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