![]() |
#1 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
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. |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Peace and harmony restored - thank you
![]() |
![]() |
![]() |
![]() |
#7 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#8 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |