MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Sigil (https://www.mobileread.com/forums/forumdisplay.php?f=203)
-   -   Sigil Plugins! (https://www.mobileread.com/forums/showthread.php?t=219835)

DiapDealer 08-10-2013 01:19 PM

Sigil Plugins!
 
1 Attachment(s)
Ok, not officially anyway, but still ... sorta ... kinda. ;)

I've been using the "Open with" feature of Sigil to launch Python scripts from *.bat files and bash scripts... with varying levels of success.

I thought I'd share in case anyone was interested in creating their own "plugins."

I'm using Python because that's what I know, but there's really nothing preventing someone from using their own preferred scripting/programming language if they so desired.

Having said that, however; if you want to try my attached samples (working on Windows and Linux), you'll need to have Python installed (and the interpreter on your PATH).

I've got three simple plugins that perform various things:
1) Smarten Punctuation (using SmartyPants)
2) Generate a new UUID in the OPF file (useful for those who use templates)
3) Add the Apple XML file to the ePub (so embedded fonts work in iBooks)

After ensuring you have a working Python installation, unzip the attached file to a folder/directory on your system. Then from within Sigil, right-click on a file and select "Open With." Then browse to the folder where you unzipped the files and select the plugin you want to use (*.bat on windows ... *.sh on linux). Optionally change the name of the "editor" to something relevant, and that's really it.

*Please* don't use these on something you've spent hours getting just right without having proper backups. They're working fairly well for me, but still... caution would definitely be in order.


Details:

Smarten Punctuation: smarten_punc.(bat|sh). Edit smarten_punc.py to tweak how things work (converting entities to characters, which entities, etc). I associate this plugin with (x)html files (and yes, it only works on one file at a time). This script is not discriminating in what kind of file it will work on, so please don't attempt to use it on anything other than your (x)html files. I don't know what the results would be!

Generate New UUID: new_uuid.(bat|sh) Edit new_uuid.py to tweak how things work. I associate this plugin with the OPF file.

Add Apple XML: apple_xml.(bat|sh) Edit apple_xml.py to tweak how things work. I associate this plugin with font files (even though it doesn't modify them). NOTE: you won't see the XML file in Sigil after running the plugin, but you will get an indication that the epub is in an unsaved state. If you save the ePub, rest assured the xml file will show up in Sigil 'Misc' folder next time you open the ePub.

Anyway, I hope someone can have fun with this. It's really meant as a "proof of concept" sort of thing. I'm more than willing to help people get things working in a general way, but just know that I'm not volunteering for a "make it do X!, or make it do Y!" sort of free-for-all.

Also, although SmartyPants does an admirable job, it's not perfect (and I didn't write it). So I'm not responsible for it behaving in a way you don't think it should. ;)

For myself, I eventually foresee me creating a Tk graphical front-end that will allow me to choose from several common utilities to be performed for that file type. But I'm in no hurry. :)

** (If you want to use these in conjunction with Calibre's 'Open with' plugin to launch Sigil, you'll probably need to edit the bat/sh files and hardcode the path to your Python interpreter. Something about the Calibre environment prevents Sigil from finding the interpreter even when it's on the system path. I hard code them anyway, simply because I have multiple versions of Python installed.) **

DiapDealer 08-10-2013 02:06 PM

Did I forget to attach the zip file, or was it removed for some reason?
Oh well, I'll just attach it again. If there's some sort of issue with doing so, I assume someone will let me know.

theducks 08-10-2013 02:12 PM

Quote:

Originally Posted by DiapDealer (Post 2591034)
Did I forget to attach the zip file, or was it removed for some reason?
Oh well, I'll just attach it again. If there's some sort of issue with doing so, I assume someone will let me know.

I don't see any MOD action. Maybe you rushed the upload process ;)

DiapDealer 08-10-2013 02:23 PM

Quote:

Originally Posted by theducks (Post 2591043)
I don't see any MOD action. Maybe you rushed the upload process ;)

Quite likely the case. :)

Jellby 08-10-2013 04:01 PM

Quote:

Originally Posted by DiapDealer (Post 2591001)
For myself, I eventually foresee me creating a Tk graphical front-end that will allow me to choose from several common utilities to be performed for that file type. But I'm in no hurry. :)

Why not QT? When I created the GUI for the epub2pdf script I was only a novice in python (I still am) and had never done any GUI programming, let alone QT.

DiapDealer 08-10-2013 04:16 PM

Quote:

Originally Posted by Jellby (Post 2591086)
Why not QT? When I created the GUI for the epub2pdf script I was only a novice in python (I still am) and had never done any GUI programming, let alone QT.

Even though I said "for myself," I'll more than likely share whatever I come up with. So even though I prefer the look of QT (and agree that it's fairly painless), I usually try to confine my scripts to modules that will work with "standard" Python installs. TKinter is standard in most Linux flavors (as well as OS X), and comes with Activestate's Python for Windows as well. PyQt is usually an addon. I enjoy sharing python scripts that other users won't need to install extra modules to get up and running. I guess you could say it was a slightly obsessive hobby of mine. :)

GrannyGrump 08-13-2013 02:05 AM

Thank you for the plugins. I am really looking forward to using "Smarten Punctuation", seems like it will be simpler to work from within Sigil rather than having to use Calibre and its plugin.

mrmikel 08-13-2013 07:49 AM

I don't need a wood burning computer....I fume all by myself. LOL

varlog 08-13-2013 06:45 PM

On my Ubuntu 12.04 32 I had to make *.sh files executable to make it work - which is obvious but perhaps not to all.
Undo function function doesn't know anything about plugins (ditto) - but you don't have to save (save before :)).
toc.ncx shows the old data (uuid) - you have to save and open again to see changes - which only shows that I don't know my Sigil yet :(.

And when speaking about not knowing: at the moment Sigil monitors the tmp files and reacts immediately to any changes - is it reliable feature?

Nice.

DiapDealer 08-13-2013 07:35 PM

Yes, the Generate UUID script doesn't currently change the matching uuid in the toc.ncx file. Mainly because I forgot about there BEING an id entry in the ncx! :o

Quote:

And when speaking about not knowing: at the moment Sigil monitors the tmp files and reacts immediately to any changes - is it reliable feature?
It can be a bit flaky, actually. If you look at the bash scripts, you'll see some commented out lines I was experimenting with. If the Sigil UI doesn't seem to react to your changes to the tmp files (visually), you may have to experiment with those commented out commands and see if one works better than the other for you.

Launching a terminal (gnome-terminal in my case) from the bash script and executing the commands seems to have pretty reliable results, though. Seems Sigil likes the "editor" to actually take the focus away from it. It's not a problem on Windows since it always opens a terminal window when launching the scripts.

Something for the TODO list is to modify the Smarten Punctuation script so that if no punctuation is altered, it doesn't save the file. The way it works currently, the file is ALWAYS modified. It works for what I want to do with it, but that may be sticking point for other users.

varlog 08-13-2013 08:09 PM

I think at the moment that ncx is build (rebuild?) on the fly when you open a book (Devs please?).
And of course I've seen yours commented out... I've partly uncommented - and added my own to verify.
And of course (Google is the saviour!) I don't speak python ;).

tk (and SmartyPants!) was not included in my standard python installation - so it is quite ok to use qt I guess.

Perkin 08-19-2013 05:06 PM

1 Attachment(s)
I've created one to add to these, it strips all the empty <span> elements
(and their corresponding (and correct) closing </span>'s)

DiapDealer 08-19-2013 08:41 PM

It's a plugin revolution! :2thumbsup

roger64 08-20-2013 03:01 AM

Hi

A good idea.

Even after making the scripts executable, I fail to launch them. Maybe my python version is too old?

DiapDealer 08-20-2013 07:50 AM

Or too new. They probably won't work if your default python is 3.0 or higher. They need to be run with python 2.x (or you may need to hardcode the location of your python interpreter in the bash script). Also, make sure it is the bash script you are making executable, and pointing to with Sigil's Open With feature -- and not the python script. It won't matter if the python script is executable as you won't be launching it directly. Also keep all the files together in one directory -- don't move the bash scripts in relation to the python scripts.

If none of that gets you going, I'd suggest taking Sigil out of the equation. Launch one of the bash scripts from a terminal and see what's happening.


All times are GMT -4. The time now is 08:37 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.