![]() |
#556 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,558
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
What build cycle do you need to go through with a Python plugin?
|
![]() |
![]() |
![]() |
#557 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
That would work but the Sigil.cfg would have to match the current Sigil, dll locations, etc and unzipped epub (to select html files), but other than that the interface was designed to be run in a subprocess and results passed back in xml and stored updated files.
Not sure about any "build cycle" as this is python which can be run as is. I personally find that logic errors are better found by studying the source (a follower of Linus's many eyes club) and normally stay far away from debuggers since python generates its own traceback stacks), but to each his or her own. Glad you have something that works for you. |
![]() |
![]() |
![]() |
#558 |
Connoisseur
![]() Posts: 74
Karma: 10
Join Date: Jul 2023
Device: none
|
How does Sigil check the validity of the html when editing and can I use it in a plugin? I am trying to figure out what to do if an user edit results in invalid html.
|
![]() |
![]() |
![]() |
#559 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,725
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
It's automatically handled by the plugin handler code. If your plugin tries to write invalid html code to a file, Sigil will display a warning dialog box.
|
![]() |
![]() |
![]() |
#560 |
Connoisseur
![]() Posts: 74
Karma: 10
Join Date: Jul 2023
Device: none
|
|
![]() |
![]() |
![]() |
#561 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
If you load your Preview clone correctly and provide the proper xhtml media type, your Preview clone should be showing all xhtml parsing errors.
Otherwise you have to pass the source through an error detecting xml parser. |
![]() |
![]() |
![]() |
#562 | |
Connoisseur
![]() Posts: 74
Karma: 10
Join Date: Jul 2023
Device: none
|
Quote:
on_load_finished receives OK. What, if anything, do I need to put in baseUrl? |
|
![]() |
![]() |
![]() |
#563 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
Do *not* use setHtml as you are loading xhtml which is a different specification with very different parsing rules that are much less forgiving than the html spaghetti.
Use: void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl()) The baseURL is the path to the file as a QUrl, and data holds the contents of the file in bytes (ie. a bytes buffer that you read the entire file into), and of course the proper mimetype: = "application/xhtml+xml" See the QtWebEngineView online docs: https://doc.qt.io/qt-6/qwebengineview.html And for a python example see the calibre source code here: https://github.com/kovidgoyal/calibr...lay/webview.py Code:
if force_as_html or load_as_html(html): view.setHtml(html, loading_url) else: view.setContent(QByteArray(html.encode(codec)), mime_type, loading_url) mf = view.page().mainFrame() elem = mf.findFirstElement('parsererror') Last edited by KevinH; 01-02-2025 at 10:54 AM. |
![]() |
![]() |
![]() |
#564 | |
Connoisseur
![]() Posts: 74
Karma: 10
Join Date: Jul 2023
Device: none
|
Quote:
I also am having a problem with using the stylesheet and am guessing it is a problem with the QUrl basepath. Which bookpath functions do I use to get the basepath? id_to_bookpath(current_fileid) doesn't seem to work. |
|
![]() |
![]() |
![]() |
#565 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
A bookpath is a path from the root folder of the epub to that particular file. To link in css from any one xhtml file you need to calculate the relative path from the folder holding the xhtml file to your css file so you can create the proper link. There are a number of utility routines available to python plugins on Sigil to help you do that.
From the Sigil plugin interface code see bookcontainer.py: Code:
# returns the href relative path from source bookpath to target bookpath def get_relativepath(self, from_bookpath, to_bookpath): return self._w.get_relativepath(from_bookpath, to_bookpath) |
![]() |
![]() |
![]() |
#566 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
And by the way, you can use Qt callbacks to extract the code of the page being viewed in case you want to load exactly what is in your Preview clone into a validator.
That said, once you setContent and specify xhtml if there is a parsing error, the error message should show up in your Preview clone as it does in Sigil. If that is not happening then something is not set propertly. Look up how QtWebEngineProfiles are used to set settings used by QtWebEngineViews. Defaults are rarely what you want. |
![]() |
![]() |
![]() |
#567 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
As for base url, I prepend the path of the stored epub to the bookpath (properly handling url encode and decode if needed) to create an absolute file path to the xhtml file in question then use Qt's routine to create a url from the absolute file path.
Last edited by KevinH; 01-03-2025 at 11:07 AM. |
![]() |
![]() |
![]() |
#568 |
Connoisseur
![]() Posts: 74
Karma: 10
Join Date: Jul 2023
Device: none
|
As far as I can tell, I need basedir from wrapper.py, which is ebook_root or outdir if the file has been written. I don't see a function to get that.
|
![]() |
![]() |
![]() |
#569 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,749
Karma: 5706256
Join Date: Nov 2009
Device: many
|
If you want full control check out bookcontainer.py for the copy epub to folder routine. You specify the folder full path and can get actual file access to a full copy of all the epub's files.
If you never directly write to it, you can cheat and do something like: bk._w.ebook_root to access the actual internal-to-Sigil, ebook root path but if you write directly to there without using the proper plugin interface you will crash Sigil. Sigil plugins use a "copy and modify on write approach" built into the bookcontainer.py and wrapper.py routines to protect Sigil. So if a file is modified remember to only write its new contents using the proper plugin interface so that it is properly registered as being modified and stored away. Last edited by KevinH; 01-03-2025 at 07:34 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 06:57 PM |
Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-04-2012 11:33 PM |
DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 09:46 AM |
Device plugin development | reader42 | Plugins | 10 | 03-29-2010 12:39 PM |
Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 12:44 PM |