10-28-2015, 09:59 AM | #106 |
Grand Sorcerer
Posts: 27,688
Karma: 196159104
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
On Windows, you should be able to run sigil-python3.exe with the -EO command-line switches. I won't guarantee it can be used externally from Sigil with no issues whatsoever, but it should be able to launch and load the bundled modules OK. The python plugin launcher files themselves, for instance, won't be included in sys.path, nor will the plugin's directory when running it in this manner.
The -E switch isn't entirely necessary (especially if you have no other version of Python installed on your system). It just tells python to ignore any Python environment variables. It helps ensure the isolation of Sigil's bundled pyrhon from any other python installations. Full disclosure: on Windows, the Python interpreter is launched (when running plugins) with -EOBu as command-line parameters. Not much to gain by using it in this manner, though. It's just a standard python.org 3.4.3 install with a few extra modules and a tweaked site.py. Last edited by DiapDealer; 10-28-2015 at 10:51 AM. |
11-28-2015, 11:15 AM | #107 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Hi,
i'm rying to get familiar with the new python built in interpreter. I now have this code as plugin: Code:
#!/usr/bin/env python # -*- coding: utf-8 -*- from PIL import Image from io import BytesIO def run(bk): xml = '<?xml version="1.0" encoding="utf-8"?>\n' xml += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n' xml += ' "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n' xml += '\n' xml += '<html xmlns="http://www.w3.org/1999/xhtml">\n' xml += '<head>\n' xml += '<title>Allpics</title>\n' xml += '</head>\n' xml += '<body>\n' for (id, href, mime) in bk.image_iter(): im = Image.open(BytesIO(bk.readfile(id))) (width, height) = im.size print ('id={} href={} mime={} width={} height={}'.format(id, href, mime, width,height)) xml += ' <div class="cimg">\n' xml += ' <img alt="" src="../{}" style="max-width: {}px" />\n'.format(href, width) xml += ' </div>\n' xml += '\n' xml += '</body>\n' xml += '</html>\n' print (xml) basename = "allpic.html" mt = "application/xhtml+xml" uid1 = 'allpic' bk.addfile(uid1, basename, xml, mt) print ('\nClick OK to close the Plugin Runner window.') return 0 def main(): print ('I reached main when I should not have\n') return -1 if __name__ == "__main__": sys.exit(main()) Code:
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Allpics</title> </head> <body><div class="cimg"><img alt="" src="../Images/fm.png" style="max-width: 365px"></img> </div> <div class="cimg"><img alt="" src="../Images/img01.jpg" style="max-width: 378px"></img> </div> <div class="cimg"><img alt="" src="../Images/img01.png" style="max-width: 378px"></img> </div> <div class="cimg"><img alt="" src="../Images/img02.jpg" style="max-width: 520px"></img> </div> <div class="cimg"><img alt="" src="../Images/img02.png" style="max-width: 520px"></img> </div> <div class="cimg"><img alt="" src="../Images/img03.jpg" style="max-width: 330px"></img> </div> </body> </html> //rb PS Sigil Version is 0.9.0, to test i started sigil from scratch and added some pictures. Running the plugin should add a xhtml file, but this looks different to the printout Last edited by rubeus; 11-28-2015 at 11:30 AM. |
Advert | |
|
11-28-2015, 11:57 AM | #108 |
Sigil Developer
Posts: 7,872
Karma: 5449552
Join Date: Nov 2009
Device: many
|
Hi rubeus,
You are not doing anything wrong. That was a bug for any file added that passed it incorrectly through an xml repair routine (instead of an xhtml aware repair routine like gumbo) that was introduced in Sigil-0.8.900 series someplace that is fixed in Sigil-0.9.1. The xml parser had no xhtml dtd to work with and so did not understand that img was a void tag (self-closing) and thus it introduced the error. I have a release build of Sigil-0.9.1 on my machine (ready for a release after US Thanksgiving) and your plugin code runs quite well on my machine. Here is the output of your plugin code running on the Sigil_Plugin_Framework_rev6.epub: Code:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Allpics</title> </head> <body> <div class="cimg"> <img alt="" src="../Images/Manage_Plugins.jpg" style="max-width: 880px" /> </div> <div class="cimg"> <img alt="" src="../Images/Sigil_Plugins_Menu.jpg" style="max-width: 904px" /> </div> <div class="cimg"> <img alt="" src="../Images/PluginRunner.jpg" style="max-width: 791px" /> </div> </body> </html> Sorry about that. I inadvertently introduced that bug when fixing another plugin related bug. KevinH |
11-28-2015, 12:06 PM | #109 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Hi
thx for the quick answer. As i'm on windows i need to wait then. //rb |
11-29-2015, 04:42 PM | #110 |
Sigil Developer
Posts: 7,872
Karma: 5449552
Join Date: Nov 2009
Device: many
|
|
Advert | |
|
11-30-2015, 03:20 AM | #111 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
And solved. I noticed that the image element in an svg behaved as well, solved to.
|
12-05-2015, 09:39 AM | #112 | |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Quote:
I only found the prettify method of the original Beautiful Soup library, Can someone help me? |
|
12-05-2015, 10:08 AM | #113 |
Sigil Developer
Posts: 7,872
Karma: 5449552
Join Date: Nov 2009
Device: many
|
These are new abilities addd by Sigil to BS4 to allow it to work better with Sigil. They are not a standard part of bs4.
Here is the only real doc I have on it: https://www.mobileread.com/forums/sho...d.php?t=265170 There is a simple example near the end illustrating their use. I will try and update the Sigil Plugin Framework docs to include more on them. KevinH |
12-05-2015, 11:17 AM | #114 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Thx, do i need to enclose the result in the str() function when writing back to sigil? Doitso did that with the prettify_html. but you didn't in your example.
|
12-05-2015, 11:25 AM | #115 |
Sigil Developer
Posts: 7,872
Karma: 5449552
Join Date: Nov 2009
Device: many
|
I don't think it should be needed but if it doesn't work, sometimes using str() effectively forces it to be interpreted as a string versus an object.
I will run some tests. I want to make prettyprint_xhtml more robust anyway. KevinH |
12-19-2015, 12:46 PM | #116 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Hi,
i can put a cover.xhtml template file in the sigil prefernce folder which is in windows C:\Users\rubeus\AppData\Local\sigil-ebook\sigil\cover.xhtml This template is used when i select the Add Cover menu item. How can i read this file independet from the os to use it i my own plugin? //rubeus |
12-19-2015, 01:35 PM | #117 | |
Grand Sorcerer
Posts: 27,688
Karma: 196159104
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
Some other cross-platform Wrapper properties that may come in handy are: bk._w.appdir (the path to the directory the Sigil executable is in) bk._w.selected (a python list of the files selected in Sigil's Book Browser) Those should be available from Sigil 0.8.90x onward (I think). Last edited by DiapDealer; 12-19-2015 at 01:41 PM. |
|
12-19-2015, 01:40 PM | #118 | |
Grand Sorcerer
Posts: 5,623
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
C:\Users\rubeus\AppData\Local\sigil-ebook\sigil\cover.xhtml Code:
import os def run(bk): cover_path = os.path.abspath(os.path.join(bk._w.usrsupdir, 'cover.xhtml')) print(cover_path) # Windows: C:\Users\doitsu\AppData\Local\sigil-ebook\sigil\cover.xhtml # Linux: /home/doitsu/.local/share/sigil-ebook/sigil/cover.xhtml print(os.path.isfile(cover_path)) Code:
import os def run(bk): cover_path = os.path.abspath(os.path.join(bk._w.plugin_dir, 'PluginName', 'cover.xhtml')) print(cover_path) # returns: C:\Users\doitsu\AppData\Local\sigil-ebook\sigil\plugins\PluginName\cover.xhtml # returns: /home/doitsu/.local/share/sigil-ebook/sigil/plugins/PluginName/cover.xhtml print(os.path.isfile(cover_path)) |
|
12-19-2015, 01:48 PM | #119 |
Banned
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Hi,
thx. I dont want to use my own template, if the user has defined one i would like to use this, otherwise a built in. And yes i'm thinking to "improve" Doitsu's svgwrapper. With the internal python interpreter and PIL theres no need for the files. Despite of that, the creation of the uid fails if there are images like img01.jpg and img01.png in the book. @ Doitsu i will contact you if i'm done... |
12-19-2015, 02:14 PM | #120 | |
Grand Sorcerer
Posts: 5,623
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
When you're done you can post your version in the same thread and I'll add it as an additional download to the original post. Just pick a slightly different name. :-) |
|
|
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 |