08-10-2013, 01:19 PM | #1 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Sigil Plugins!
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.) ** Last edited by DiapDealer; 08-10-2013 at 02:06 PM. |
08-10-2013, 02:06 PM | #2 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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. |
Advert | |
|
08-10-2013, 02:12 PM | #3 |
Well trained by Cats
Posts: 30,448
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
08-10-2013, 02:23 PM | #4 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
|
08-10-2013, 04:01 PM | #5 | |
frumious Bandersnatch
Posts: 7,536
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
|
|
Advert | |
|
08-10-2013, 04:16 PM | #6 | |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
|
|
08-13-2013, 02:05 AM | #7 |
Obsessively Dedicated...
Posts: 3,200
Karma: 34978132
Join Date: May 2011
Location: JAPAN (US expatriate)
Device: Sony PRS-T2, ADE on PC
|
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.
|
08-13-2013, 07:49 AM | #8 |
Color me gone
Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
|
I don't need a wood burning computer....I fume all by myself. LOL
|
08-13-2013, 06:45 PM | #9 |
actually it is /var/log
Posts: 341
Karma: 2994236
Join Date: Sep 2012
Location: usually Europa
Device: prs t1
|
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. |
08-13-2013, 07:35 PM | #10 | |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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!
Quote:
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. Last edited by DiapDealer; 08-13-2013 at 08:55 PM. |
|
08-13-2013, 08:09 PM | #11 |
actually it is /var/log
Posts: 341
Karma: 2994236
Join Date: Sep 2012
Location: usually Europa
Device: prs t1
|
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. |
08-19-2013, 05:06 PM | #12 |
Guru
Posts: 657
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
|
I've created one to add to these, it strips all the empty <span> elements
(and their corresponding (and correct) closing </span>'s) |
08-19-2013, 08:41 PM | #13 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
It's a plugin revolution!
|
08-20-2013, 03:01 AM | #14 |
Wizard
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
|
Hi
A good idea. Even after making the scripts executable, I fail to launch them. Maybe my python version is too old? |
08-20-2013, 07:50 AM | #15 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sigil 0.3.4 / Sigil 0.4.0 RC1 / Cover in Nook Color | Bertrand | Sigil | 13 | 08-06-2011 05:06 AM |
Sigil 0.3.4 / Problème CSS entre Sigil et iPad | Grivels | Software | 10 | 07-03-2011 10:06 AM |
Plugins | junkml | Plugins | 32 | 06-19-2009 07:43 AM |
Plugins? | Mitchll | Plugins | 0 | 12-27-2008 03:36 PM |