09-09-2019, 04:39 PM | #1 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
ScrambleBook and Calibre 4
I'm trying to get my ScrambleEbook user interface plugin working in the beta but I'm having a problem importing QWebEngineView.
This is the import code at the top of the main .py file: Code:
try: from PyQt5.QtWebKitWidgets import QWebView as Webview print('PyQt5.QtWebKitWidgets.QWebView OK') except: print('PyQt5.QtWebKitWidgets.QWebView failed') try: from PyQt5.QtWebEngineWidgets import QWebEngineView as Webview print('PyQt5.QtWebEngineWidgets.QWebEngineView OK') except: print('PyQt5.QtWebEngineWidgets.QWebEngineView failed') In beta 3.99.1 I'd expect the first try to fail and the second to succeed. However, both of them fail. You can see the error message prints (in red) during calibre startup in debug mode. Despite the error messages, the plugin does get installed. Spoiler:
The more obvious error message happens when running the plugin and pressing the 'Preview content' button - which is the only place the QWebView/QWebEngineView widget is used. Spoiler:
I'm confused because in one of my personal Editor Tool plugins I've used the same import approach and both 3.47.1 and 3.99.1 seem to be working fine. I've also attached a copy of the plugin in it's current state if you have time to look at it. If not I'll ask again when the initial beta bug reporting dies down a bit. |
09-09-2019, 10:17 PM | #2 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie_w: That is because webengine is not useable in the main calibre program only the editor/viewer. This is because it is very resource intensive and Qt requires that it be imported before starting the appication. Since the main GUI does not use it, I do not import it, which also means it cant be imported in any plugins. What does scrambleebook use it for? There are two possible workarounds, it is is not something that requires sophisticated HTML support then QTextBrowser can be used, otherwise you have to run it in a separate process.
@eschwartz: Given that all plugins will need to be ported to python3, it will be a long time before calibre is ready for py3. But yes, my next painful job after v4 is done is to work on getting betas ready with py3 so the plugin developers can start work on porting their plugins. |
Advert | |
|
09-09-2019, 11:28 PM | #3 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
It's a utility to preview a page from an original container object alongside the same page from the scrambled container object, so that a user can confirm nothing is readily identifiable before posting to MR. See the 2nd screenshot at the bottom of this post. Cols 1 & 3 (beige), were originally QWebView widgets displaying pre- & post-scramble versions of the container name user-highlighted in col 2 (white). The webview widgets are styled using the container CSS file(s) referenced in the page <head> <link>s. I think these would be the relevant bits of code: Code:
from calibre.ebooks.oeb.display.webview import load_html def webview_refresh(self, name): name_orig = self.revfmap.get(name, name) abspath_orig = self.orig.name_to_abspath(name_orig) abspath = self.ebook.name_to_abspath(name) load_html(abspath, self.webview_scram) load_html(abspath_orig, self.webview_orig) |
|
09-10-2019, 02:08 AM | #4 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie_w f all you are doing is previewing some text so users can check it, probably QTextBrower will be good enough for you, that is the simplest option.
|
09-10-2019, 08:57 AM | #5 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
If I can make QTextBrower work it will be the solution I ought to have used in the first place. In the past I've only ever used those for displaying simple text, like large log results, which are far too big for a calibre info_dialog.
|
Advert | |
|
09-11-2019, 10:20 AM | #6 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
TL;DNR: Unless I'm missing something, for previewing the contents of an ebook, QTextBrowser is a poor substitute for QWebView/QWebEngineView due to its limited style support. I realise this minor plugin is not going to be the tail that wags the calibre dog so I'm open to ideas if there's anything I can do to get the beta plugin QTextBrowser closer to how it looks in the QWebView of 3.47.1. Bear in mind I have limited Python skills (and none at all for Java, C++). If what I've already done in the beta plugin is as good as it's going to get then I need to decide whether I'm going to discontinue the calibre plugin leaving only its standalone equivalent. It's fair to say there should be no detriment to the actual scrambled ebook output by the plugin, current vs. beta. However, whilst the look&feel of text in a widget may be cosmetic to some extent, I don't feel right releasing an update which is visually a fairly clunky downgrade. ---------------------------------------------------------------- More detail ... I've attached some screenshots from ScrambleEbook current version vs. beta version. It has a calibre plugin and a standalone (kind of) version which uses a .bat file to run the .py file via calibre-debug. Image 1: from current calibre plugin. Current standalone looks the same because both use QWebView. Image 2: beta standalone using QWebEngineView Image 3: beta calibre plugin using QTextBrowser
|
|
09-11-2019, 10:35 AM | #7 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie_w: You should be able to use qwebengine in your plugin by running it in a separate process using calibre-debug so your previewer becomes a simple standalone program inside your plugin. Something like
Code:
from calibre.debug import run_calibre-debug run_calibre_debug(['-c', 'from calibre_plugins.your_plugin.viewer import main; import sys; main(sys.argv[-2], sys.argv[-1]);', 'path to first html file', 'path to second html file']) Last edited by kovidgoyal; 09-11-2019 at 11:42 AM. |
09-11-2019, 11:06 AM | #8 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Last edited by kovidgoyal; 09-11-2019 at 11:46 AM. |
|
09-11-2019, 11:46 AM | #9 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No cant say I have an example, but here is a barebones viewer.py to add to your plugin. It only shows a single passed in html file, for breviry
Code:
def main(path_to_html_file, path_to_ther_html_file): from calibre.gui2 import Application app = Application([]) w = QWebEngineView() w.setUrl(QUril.fromlocalFile(path_to_html_file)) w.show() w.raise_() app.exec_() |
09-11-2019, 12:01 PM | #10 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Thanks for this. I'm still having problems 'joining the dots' in how this viewer links to what's happening in the central listwidget column where when the user moves the cursor up and down the list of html names the contents of the webviews on either side change accordingly. Rather than exasperate you further let me think about it some more and try to sort it out - or maybe come up with some better questions.
|
09-11-2019, 12:09 PM | #11 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
basically rather than having the column view you have now, you instead have a preview button. the user selects the file he wants to preview the changes to and clicks the button. A new window opos up with the preview. Behind the scenes the new window is implemented using the pattern i showed you. Think of it like Sigils PageEdit.
|
09-11-2019, 12:27 PM | #12 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Well, I haven't used Sigil's PageEdit, I'm strictly calibre when it comes to editing, but have I got this right? What you're saying is that instead of a single dialog with 3 widgets layed out in 3 columns there will be an initial dialog with just the filename listwidget which will then launch a child dialog with the 2 before/after webviews for the selected file in it?
Last edited by jackie_w; 09-11-2019 at 12:31 PM. |
09-11-2019, 02:26 PM | #13 | |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
I don't recall offhand if it needs to connect back to the DB API. But that would be the only thing, honestly, which actually needs to be done in-process for locking reasons, right? So the plugin could just be there to provide, essentially, a GUI button to launch the standalone utility. |
|
09-11-2019, 03:10 PM | #14 | ||
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Quote:
|
||
09-11-2019, 03:25 PM | #15 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Perfect! So I'd advise that, then. e.g. let the plugin be able to run with calibre-debug --run-plugin entry points, accepting the path of the ebook to scramble. Make the GUI element simply figure out the path to the book to be scrambled, and use run_calibre_debug to spawn a new instance of the plugin which is set up to do webengine stuff.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
calibre-sync: Automatically download books from your Calibre Content Server onto Kobo | mishagale | Related Tools | 14 | 05-13-2019 05:18 PM |
Calibre plus Moon + Reader Pro - How to Make Calibre Library Sync to My Shelf? | bookiebabe | Related Tools | 5 | 02-09-2017 02:47 AM |
Calibre Sync on Android stopped working properly with recent version of Calibre? | khahoon | Calibre | 5 | 07-06-2013 08:14 AM |
How do I import Calibre settings from regular Win Calibre to Calibre Portable? | ABW | Calibre | 9 | 05-20-2013 02:34 PM |
Can not start recoll from calibre /opt/calibre/lib/libz.so.1: no version information | Satas | Development | 5 | 04-19-2013 11:22 PM |