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 10-28-2015, 09:59 AM   #106
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: 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.
DiapDealer is offline   Reply With Quote
Old 11-28-2015, 11:15 AM   #107
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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())
The print function shows the content in the launcher window and everything looks ok, but the inserted file gets corrupted;

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>
I cant see what i did wrong, and i dont understand why some \n are lost and why the img element now have a closing tag in the inserted file.



//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.
rubeus is offline   Reply With Quote
Advert
Old 11-28-2015, 11:57 AM   #108
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: 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>
If you try the Sigil-0.8.6 build or maybe some later builds, you will see that bug did not exist. If you use a Mac, I would be happy to privately post a version of the forthcoming Sigil-0.9.1 for you to continue development with. If you have Linux, and build from source (github.com master) you should also be good to go.

Sorry about that. I inadvertently introduced that bug when fixing another plugin related bug.

KevinH
KevinH is online now   Reply With Quote
Old 11-28-2015, 12:06 PM   #109
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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
rubeus is offline   Reply With Quote
Old 11-29-2015, 04:42 PM   #110
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: 7,872
Karma: 5449552
Join Date: Nov 2009
Device: many
FYI: Its out now.

Quote:
Originally Posted by rubeus View Post
Hi

thx for the quick answer. As i'm on windows i need to wait then.

//rb
KevinH is online now   Reply With Quote
Advert
Old 11-30-2015, 03:20 AM   #111
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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.
rubeus is offline   Reply With Quote
Old 12-05-2015, 09:39 AM   #112
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
Quote:
Originally Posted by KevinH View Post
ps. I see Doitsu has already beaten me to the punch with his solution. If you decide to use BS4, I would recommend the serialize_xhtml call in sigil_bs4 over the prettyprint_xhtml call since the serialize call will make fewer changes to the source code (ie. is less likely to introduce errors from incorrect pretty-printing).
I wasn't able to find any documentation about serialize_xhtml nor prettyprint_html.

I only found the prettify method of the original Beautiful Soup library,

Can someone help me?
rubeus is offline   Reply With Quote
Old 12-05-2015, 10:08 AM   #113
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: 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
KevinH is online now   Reply With Quote
Old 12-05-2015, 11:17 AM   #114
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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.
rubeus is offline   Reply With Quote
Old 12-05-2015, 11:25 AM   #115
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: 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
KevinH is online now   Reply With Quote
Old 12-19-2015, 12:46 PM   #116
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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
rubeus is offline   Reply With Quote
Old 12-19-2015, 01:35 PM   #117
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: 27,688
Karma: 196159104
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by rubeus View Post
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
I believe bk._w.usrsupdir should get you the Sigil preferences directory in a cross-platform-safe way.

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.
DiapDealer is offline   Reply With Quote
Old 12-19-2015, 01:40 PM   #118
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,623
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by rubeus View Post
How can i read this file independet from the os to use it i my own plugin?
If you want to put your own cover file in:

Code:
C:\Users\rubeus\AppData\Local\sigil-ebook\sigil\cover.xhtml
you could access it independently of the OS as follows:

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))
You could also load it from within the plugin folder:

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))
(Replace PluginName with the actual plugin name.)
Doitsu is offline   Reply With Quote
Old 12-19-2015, 01:48 PM   #119
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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...
rubeus is offline   Reply With Quote
Old 12-19-2015, 02:14 PM   #120
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,623
Karma: 23190435
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by rubeus View Post
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.
Feel free to improve on my SVG wrapper plugin, which was pretty much a throwaway plugin with hardly any error checking.
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. :-)
Doitsu 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 01:38 PM.


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