09-11-2019, 04:59 PM | #16 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Code:
set ProgDir=%~dp0 calibre-debug "%ProgDir%scrambleebook.py" %1 |
|
09-11-2019, 10:21 PM | #17 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie_w: Yes I think @escwartz has a good idea. Have the GUi part of your plugin simply copy the ebook file to a temp dir. Then launch the standalone part in a separate process using calibre-debug which will allow you to use QWebEngine with no issues on that copied file.
|
Advert | |
|
09-12-2019, 07:46 AM | #18 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
I had to abandon the above plan as I forgot to mention that the plugin needs a few small dummy images to scramble the book's original images. In the standalone these are in an images subdir with the .py and .bat files. In the plugin they're stored like any other plugin's images. I had no idea whether it would be possible to pass the images. What I'd hoped to try instead was to pass the running of the whole Preview 3-column child QDialog to run_calibre_debug activated by the Preview button in the main plugin QDialog. The child dialog will (eventually) need the QWebEngineViews but doesn't need any of the plugin's images until they've already been written to disk in the scrambled container. Rather than get complicated too soon I've tried to strip everything back to bare bones to see whether you can tell me where I'm going wrong. For now, all I want to do is use run_calibre_debug to pass a single string to viewer.py which opens a single QLabel to display that text. If I ever achieve proof of concept hopefully I can start to make some progress. This is the code in scrambleebook.py when the Preview button is clicked. I've left the original 2-line contents as comments in case you needed to know what used to be there: Code:
def previewbutton_clicked(self): #dlg = EbookScramblePreviewDlg(self.ebook, self.eborig, self.is_scrambled, self.rename_file_map, parent=self.gui) #dlg.exec_() from calibre.debug import run_calibre_debug msg = 'preview run via calibre-debug' print('%s - Start' % msg) run_calibre_debug(['-c', 'from calibre_plugins.scrambleebook_plugin.viewer import main; import sys; main(sys.argv[-1]);', 'running OK']) print('%s - End' % msg) Code:
from __future__ import (unicode_literals, division, absolute_import, print_function) def main(some_text): from PyQt5.Qt import QLabel from calibre.gui2 import Application app = Application([]) w = QLabel(some_text) w.setMinimumHeight(100) w.setMinimumWidth(100) w.show() w.raise_() app.exec_() - put the above in the plugin - open calibre via calibre-debug - run the plugin on a library epub - press the Preview button I see the 2 Start/End print statements in the debug log and no error messages but no sign of any QLabel widget. What stupid error have I made? |
|
09-12-2019, 09:03 AM | #19 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie_w: some_text is not defined in viewer.py And if you need to pass in dummy images I would suggest you simply create a temporary directory, copy in the dummy images into that directory and pass the path to th edirectory
Last edited by kovidgoyal; 09-12-2019 at 09:09 AM. |
09-12-2019, 09:39 AM | #20 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
I don't understand? Am I having a brain fade?
Code:
def main(some_text): ... w = QLabel(some_text) ... I don't want to even think about this until I see evidence of run_calibre_debug doing something with the trivial example I posted. |
Advert | |
|
09-12-2019, 10:53 AM | #21 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Oh sorry my mistake, I dont see anything wrong in the snippet you post. Post the full plugin and I will have a look.
|
09-12-2019, 11:22 AM | #22 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Here it is.
|
09-12-2019, 11:51 AM | #23 |
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)
|
@jackie_w, @kovidgoyal,
Am I missing something? Surely the run_calibre_debug process, which is executing code imported from the calibre plugin itself, likewise has access to all plugin resources, and especially the ability to access plugin utilities that extract an image file from the plugin. The only thing the subprocess *won't* have is the ability to share internal state and memory, and thus, the ability to have a writable handle on the metadata.db. It should be literally the same as running the plugin normally, but launched from a custom QApplication rather than calibre's. In general, I don't think there is a reason that calibre-debug --run-plugin should be unable to import all Calibre code, consult the constant variable which says "here is where the user config dir is", or execute the same functions that are available to the GUI. |
09-12-2019, 12:18 PM | #24 |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
@eschwartz,
Much as I'd love to have a sensible discussion with you about this, I'm afraid it's above my head. If you're able to tell me exactly what to change and where I'll be happy to test but I'm not going to be able to figure it out for myself based on hints. |
09-12-2019, 01:17 PM | #25 |
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)
|
I'm mobile right now, cannot check the source code and offer specific examples, but what I'm basically thinking is that you should be able to get the images by instantiating your plugin in the calibre-debug subprocess and using https://manual.calibre-ebook.com/plu...load_resources
Also see cli_main() there. This seems like a much simpler approach: You'd want to allow the cli_main entry point to spin up your QApplication with a path to an ebook file in order to run the plugin, just as if you had used the batch file instead. In fact, this could replace the batch file. Users would simply install the plugin, and then the batch file would run 'calibre-debug --run-plugin ScrambleEbook path-to-epub'. Then the final step would be that on newer versions of Calibre with webengine instead of webkit, the plugin will simply call run_calibre_debug and start up the command line interface for the plugin. If this isn't enough of a hint for you, I will try to explain in greater detail and hopefully with code samples, tonight or tomorrow or something. Or Kovid can fill in the blanks. Last edited by eschwartz; 09-12-2019 at 01:23 PM. |
09-12-2019, 02:01 PM | #26 | |
Grand Sorcerer
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
I don't use cli_main() and have never planned to become an expert. It's not something I'll ever use anywhere else. I'm not against a one-line solution which uses it, though, if handed to me on a plate. I'm afraid your hints (while well-intentioned and gratefully received ) aren't enough. Re: the standalone version. I don't really want a different solution to that as I don't think it's broken as-is. |
|
09-12-2019, 10:53 PM | #27 |
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)
|
So I've imported ScrambleEbook into a git repository here: https://github.com/eli-schwartz/ScrambleEbook
And this patch implements the CLI interface: https://github.com/eli-schwartz/Scra...775c440f515b85 Notice it's pretty simple to do. The heart of it is in __init__.py, where ScrambleEbookActionBase needs to be extended with a new method: cli_main(), which is responsible for initializing a new application and doing all that good stuff. The thing that cli_main does is the same thing that running scrambleebook.py on its own needs to do: call a QApplication, set up the EbookScramble(QDialog), and exec the QApplication. Luckily, all that is already in a Code:
if __name__ == '__main__' And then cli_main() runs calibre_plugins.scrambleebook_plugin.scrambleebook .main -- that's all. |
09-12-2019, 11:03 PM | #28 |
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)
|
Now that you can run:
Code:
calibre-debug --run-plugin ScrambleEbook ./path/to/mytroublesomebookthatneedshelp.epub
Now that this works, once you can figure out how to run it using WebEngine as a standalone script, you can change the plugin to call itself... as a standalone script. Last edited by eschwartz; 09-12-2019 at 11:10 PM. |
09-13-2019, 11:40 AM | #29 |
creator of calibre
Posts: 43,856
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@jackie here is a demo plugin that shows you how to run webengine in a separate process. Note that it only works with calibre version >= 3.99.4 which will be released in an hour or so. No need to mess around with calibre-debug anymore.
When its button is clicked it asks for a URL and then opens that in a QwebEngineView |
09-13-2019, 08:51 PM | #30 |
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've tried your suggestions and have been able to run the plugin as standalone and from the calibre GUI - with a working QWebEngineView widget.
After thinking about it some more I can see that there is an advantage to the standalone not needing to have a local copy of scrambleebook.py and the images directory. A simple .bat should be OK Code:
echo off calibre-debug --run-plugin ScrambleEbook %1 In the plugin's uiaction.py to start the dialog it used to have Code:
dlg = EbookScramble(path_to_ebook, book_id=book_id, from_calibre=True, parent=self.gui) dlg.exec_() Code:
from calibre.debug import run_calibre_debug run_calibre_debug('--run-plugin', 'ScrambleEbook', path_to_ebook) I thought this might work but it doesn't. Code:
run_calibre_debug('--run-plugin', 'ScrambleEbook', path_to_ebook, 'True') |
|
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 |