View Single Post
Old 09-12-2019, 07:46 AM   #18
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,252
Karma: 16544692
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
Quote:
Originally Posted by kovidgoyal View Post
@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.
More help, pretty please ...

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)
viewer.py is this:
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_()
When I
- 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?
jackie_w is offline   Reply With Quote