Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 09-28-2024, 01:10 PM   #541
PubFut
Junior Member
PubFut began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Aug 2024
Device: Sigil
Plugin code needs review/corrections

The python code in the attached plugin is based on input from Chat GPT (unfortunately I am not a developer myself). It needs review/corrections, as it does not process properly. Is there anyone willing to help me with this?

The plugin is supposed to create a table of contents in the <nav> section of every html file. This TOC shall include references/hyperlinks to all H1, H2 and H3 headings of the current page itself and all other pages that have the first 11 characters of the file name in common (this identifies these files as part of the same main chapter).

Any advise is very much appreciated.
Attached Files
File Type: zip TOC-nav.zip (1.9 KB, 115 views)
PubFut is offline   Reply With Quote
Old 09-28-2024, 02:10 PM   #542
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,805
Karma: 6000000
Join Date: Nov 2009
Device: many
Just merge the html files so that one chapter is equivalent to one file. Let Sigil generate the nav using its tools.

What is the whole point for the tool you requested? What are you trying to achieve and why? If this is for generating epubs, it seems strange to merge a nav into every html file?

Last edited by KevinH; 09-28-2024 at 02:13 PM.
KevinH is offline   Reply With Quote
Advert
Old 09-28-2024, 02:55 PM   #543
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,377
Karma: 169098492
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by KevinH View Post
What is the whole point for the tool you requested? What are you trying to achieve and why? If this is for generating epubs, it seems strange to merge a nav into every html file?
Looking at the poster's previous messages, they appear to want a mini-ToC at the start of each chapter file with the sections/subsections within the file listed. I've seen a similar layout in a textbook but there I found popping up the ToC was easier to use since I didn't need to go back to the start of chapter to find the mini-ToC. Looking at the internals of the ebook, it appeared that they generated the full ToC and then copy/pasted the ToC code for each chapter into the start of the chapter.

Chapter 42
Section 01
Subsection 01-01
Subsection 01-02
...
Section 02
Subsection 02-01
Subsection 02-02
...
DNSB is offline   Reply With Quote
Old 09-28-2024, 03:12 PM   #544
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,355
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
A pop-up ToC would definitely be more effective. Do all readers/devices support one now??

I wonder if the OP is simply trying to replicate old style web books with the last/first/next links??
Turtle91 is offline   Reply With Quote
Old 09-28-2024, 03:26 PM   #545
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,377
Karma: 169098492
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by Turtle91 View Post
A pop-up ToC would definitely be more effective. Do all readers/devices support one now??
All the newer devices and applications that I've seen support a popup ToC.

Quote:
Originally Posted by Turtle91 View Post
I wonder if the OP is simply trying to replicate old style web books with the last/first/next links??
That was what their original request sounded like. The mini-ToC was a later request. For me, neither request makes much sense. On my Kobo ereaders, I tap in the middle of the screen and can use the arrows on the position slider to jump forward/back chapters or hit the ToC to bring up the full ToC. The original message was a bit confusing since the OP seemed to want the backward/forward arrows on each page not just at the start of a chapter.
DNSB is offline   Reply With Quote
Advert
Old 09-29-2024, 03:32 AM   #546
PubFut
Junior Member
PubFut began at the beginning.
 
Posts: 9
Karma: 10
Join Date: Aug 2024
Device: Sigil
Purpose of the plugin

Thank you for all replies! I understand that this seems a bit strange. But the html produced by this plugin is not supposesd to be used with an ebook reader, but will be exported as pure html to be used with a webbrowser. Therefore, the navigation tools of ebook readers are not available. In the html version there will be a button that makes the TOC slide in or out as the user requests. So it will work similar to the TOC popup in an ebook reader.
PubFut is offline   Reply With Quote
Old 09-29-2024, 05:57 PM   #547
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 46,377
Karma: 169098492
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Sigil is not a (X)HTML editor. It is intended for editing ePub files which use a limited subset of HTML/CSS. While quite a bit of HTML/CSS works in ePub, there is a fair bit that does not.

You might be able to take a look at the code used and modify it to meet your needs. Looking at Boundary from Baen's Free Library, it looks to be a fairly simple task to add back/next/Toc to an HTML file.

I've attached the free library version of Boundary.
Attached Files
File Type: zip H1416509321.zip (1.17 MB, 123 views)
DNSB is offline   Reply With Quote
Old 12-21-2024, 03:11 PM   #548
jwes
Connoisseur
jwes began at the beginning.
 
Posts: 77
Karma: 10
Join Date: Jul 2023
Device: none
Python plugin launcher?

How difficult would it be to write a python program that would load an epub using ebooklib or similar, create a bk class, and run the plugin? This would be very useful for debugging.
jwes is offline   Reply With Quote
Old 12-21-2024, 05:17 PM   #549
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,805
Karma: 6000000
Join Date: Nov 2009
Device: many
Just have the plugin always return -1 to indicate an error so that you get the full debug output.

You could write an equivalent to plugin runner to unzip an epub, parse its opf and set up the plugin environment and run the wrapper/launcher.

But as I said, just return -1 so any debug output is copied to Sigil's Plugin Runner console.
KevinH is offline   Reply With Quote
Old 12-21-2024, 07:08 PM   #550
jwes
Connoisseur
jwes began at the beginning.
 
Posts: 77
Karma: 10
Join Date: Jul 2023
Device: none
Launcher: missing or incorrect paths passed in

I was testing my plugin and added it without deleting it first and when I started it got Launcher: missing or incorrect paths passed in. I then deleted it and reloaded it and it worked fine (or at least it loaded).
jwes is offline   Reply With Quote
Old 12-21-2024, 09:54 PM   #551
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,805
Karma: 6000000
Join Date: Nov 2009
Device: many
The plugin runner dialog and launcher does a sanity check for all paths passed in and will refuse to launch if anything is incorrect, doesn't exist, can not be read, etc
Editing directly in the plugin folder can result in temporary issues that trigger this.
These issues generally do not happen when plugins are zipped up and properly installed.

Last edited by KevinH; 12-21-2024 at 09:59 PM.
KevinH is offline   Reply With Quote
Old 12-22-2024, 01:32 PM   #552
jwes
Connoisseur
jwes began at the beginning.
 
Posts: 77
Karma: 10
Join Date: Jul 2023
Device: none
Quote:
Originally Posted by KevinH View Post
The plugin runner dialog and launcher does a sanity check for all paths passed in and will refuse to launch if anything is incorrect, doesn't exist, can not be read, etc
Editing directly in the plugin folder can result in temporary issues that trigger this.
These issues generally do not happen when plugins are zipped up and properly installed.
It seems to happen whenever I load the same version of a plugin that is already loaded without deleting it first.
jwes is offline   Reply With Quote
Old 12-22-2024, 01:47 PM   #553
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,805
Karma: 6000000
Join Date: Nov 2009
Device: many
No ideas here at all. On macOS, I always directly edit the plugin.py (or whatever py file I am debugging) inside my local Library/Application Support/sigil-ebook/sigil/plugins/MYPLUGINFOLDER/ and save it.

I just make sure to always close completely out of the Sigil Plugin Runner dialog first before editing anything.

I have never needed to change versions in plugin.xml file or reinstall.

I keep Sigil open and running with a test epub while doing this. I can repeatedly launch the plugin and get my output in the Sigil Plugin Runner console (as long as I change plugin.py to return a -1 indicating error always until fully debugged).

So very fast: "run - see output or errors - modify - run" cycles are possible.

Last edited by KevinH; 12-22-2024 at 02:44 PM.
KevinH is offline   Reply With Quote
Old 12-22-2024, 02:01 PM   #554
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,605
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
My experience has been much the same as Kevin's when editing/debugging plugins on Linux or Windows. I don't think I've ever had to uninstall/reinstall to get them to work.

If you're launching the plugins via toolbar shortcuts, you might try launching them via the plugin menu and see if that makes a difference.

If your plugin is set to manually start (from the Plugin Runner), then you definitely don't want to make changes to plugin.py with the Plugin Runner already open, and then press start.

You also might run into permissions errors (which can trigger the errors your getting) if you're keeping the plugin's Python files open in an editor while trying to run the plugin.

Last edited by DiapDealer; 12-22-2024 at 02:08 PM.
DiapDealer is offline   Reply With Quote
Old 12-23-2024, 08:00 PM   #555
jwes
Connoisseur
jwes began at the beginning.
 
Posts: 77
Karma: 10
Join Date: Jul 2023
Device: none
Quote:
Originally Posted by KevinH View Post
Just have the plugin always return -1 to indicate an error so that you get the full debug output.

You could write an equivalent to plugin runner to unzip an epub, parse its opf and set up the plugin environment and run the wrapper/launcher.

But as I said, just return -1 so any debug output is copied to Sigil's Plugin Runner console.
It turns out it is easy to adapt the Sigil python plugin launcher to run standalone. There is probably a better way, but what I did was put the plugin launcher files and all my plugin files into a directory, added a copy of Sigil.cfg, created a directory and unzipped an eBook into it, commented out the redirection of sys.stdout and sys.stderr, and created an argv string to point to the right places, and it works!
I much prefer not going through a build cycle to find a syntax error, or stepping through my code rather than putting in print statements to find a logic error.
jwes is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 10:36 AM.


MobileRead.com is a privately owned, operated and funded community.