Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 02-03-2014, 05:40 PM   #1
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
Editor widget

I currently have an application which consists of a large-ish dialog containing (amongst other things) a QWebView widget showing the contents of a single html file (or unicode string). This is working fine.

I would be interested in adding an extra widget showing the Code view equivalent and am wondering whether I can use one of the Editor's widgets for this. TextEdit in calibre/gui2/tweak_book/editor/text.py looks hopeful. Is it possible to use this class to edit a selected single html file? If so, could you show me a bit of sample code showing how I might add an 'edit html file including a theme' widget into an existing dialog?

My current sort-of-editing method is to use a subprocess.call to my standard PC text editor, which does have some benefits, but is not ideal. I'm only exploring ideas for now so any pointers would be appreciated

Last edited by jackie_w; 02-03-2014 at 05:43 PM.
jackie_w is offline   Reply With Quote
Old 02-03-2014, 09:58 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,339
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just create the widget and add it to your dialog, just like you would any other Qt widget. But note that the widget will be only the textedit, it will not include the buttons in the toolbar and so on. For those you have to use editor/widget.py (see the launch_editor()) function, however, editor/widget.py is not suitable for inclusion in other code as it depends on the infrastructure from edit book to handle keyboard shortcuts and various actions.
kovidgoyal is online now   Reply With Quote
Advert
Old 02-04-2014, 08:49 AM   #3
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
OK, thanks. I'm not trying to include a full-blown editor, just the ability to do some minor manual corrections if I spot them in passing. So hopefully the lack of toolbars shouldn't matter. I'm off to experiment.
jackie_w is offline   Reply With Quote
Old 05-20-2014, 07:14 PM   #4
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
Since my last post I've been happily using the TextEdit widget from gui2/tweak_book/editor/text.py as part of a personal plugin which, amongst many other things, allows basic manual editing of either a single html file or a single css file. However, since upgrading from calibre 1.36 to 1.37 I'm seeing a problem and I'm hoping you can give me some clues.

The problem occurs when calling the TextEdit load_text method when syntax='html'. When syntax='css' everything still seems to work OK. This is the error traceback I see:
Spoiler:
Code:
Traceback (most recent call last):
  File "site-packages\calibre\gui2\tweak_book\editor\syntax\base.py", line 145, in reformat_blocks
  File "site-packages\calibre\gui2\tweak_book\editor\syntax\base.py", line 29, in run_loop
  File "site-packages\calibre\gui2\tweak_book\editor\syntax\html.py", line 322, in normal
  File "site-packages\calibre\gui2\tweak_book\editor\syntax\html.py", line 260, in process_text
  File "site-packages\calibre\spell\dictionary.py", line 340, in recognized 
AttributeError: 'Dictionaries' object has no attribute 'active_user_dictionaries'

I've attached some stripped-down sample python code which reproduces the error (at least for me on Win7 x64 but using calibre 32 bit) when running via calibre-debug -e

Additional info:
- the editing my plugin is trying to do doesn't need any kind of spell-checking,
- something also looks wrong with the html syntax highlighting,
- I don't see any of these problems when using the full calibre Editor in the normal way.
Attached Files
File Type: zip testeditor.py.zip (954 Bytes, 283 views)
jackie_w is offline   Reply With Quote
Old 05-20-2014, 09:12 PM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,339
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You need to use

from calibre.gui2.tweak_book import dictionaries
dictionaries.initialize()

to load the dictionaries.
kovidgoyal is online now   Reply With Quote
Advert
Old 05-21-2014, 07:12 AM   #6
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
Peace and harmony restored - thank you
jackie_w is offline   Reply With Quote
Old 05-21-2014, 11:32 PM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,339
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I have also made a change that will make the dictionary initialization unneccessary in the next releaser. If using the editor widget standalone, it will simply not do inline spell checking when the dictionaries have not been initialized.
kovidgoyal is online now   Reply With Quote
Old 05-22-2014, 12:56 PM   #8
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
OK, I'll remove those 2 lines again after the next update. Thanks, forewarned is forearmed.
jackie_w is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google search widget paulsalter Kobo Tablets 0 07-11-2012 06:35 AM
Anyone know how to write a widget? NDRisk Kobo Tablets 9 11-27-2011 10:20 AM
Meaning of widget icon? Jabby Android Devices 3 05-09-2011 10:02 PM
Power Widget icons Gunnerp245 enTourage Archive 0 05-01-2010 03:17 PM
iLiad Widget style tomchek iRex Developer's Corner 5 08-02-2007 11:16 AM


All times are GMT -4. The time now is 10:10 AM.


MobileRead.com is a privately owned, operated and funded community.