MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Plugin to insert and wrap an image with SVG (https://www.mobileread.com/forums/showthread.php?t=283333)

CalibUser 02-05-2017 03:56 PM

Plugin to insert and wrap an image with SVG
 
2 Attachment(s)
Description
The attached plugin will enable you to select an image that already exists in your ePub book or import an external image and then insert it in a new or existing xhtml section, wrapping it with SVG tags.

How to use the plugin
Please see the attached user guide.

UPDATE
I have updated this plugin to version 0.2.1.0 to put an image on the clipboard from one that already exists in your ePub book or from an external image. The image on the clipboard is surrounded by SVG tags. The image and these tags can then be pasted into any part of your ePub.
  • Images are inserted in the Book Browser in the position that you select using this plugin; however, you may want to move the page containing the image to a different position in the underlying ePub structure of the book for Sigil version 1.0.0.0 or above. To do this (after running this plugin) right-click on the xhtml section that contains the image and select Move from the pop up menu. You can then select the underlying folder in the ePub structure where you want to put this page.
  • Similarly, if you import an image you may wish to move it to a different position in the underlying ePub structure of the ePub.


After pasting in the image and SVG code, you may want to add a class to the <div> wrapper eg div.breakavoid {page-break-inside: avoid;} as suggested by AlanHK.

I have updated this plugin to version 0.2.1.1. This version has the following improvements:
  • Checking for updates - you can set the time interval between reminders
  • The copy button changes colour when an image has been selected for import
  • Code has been improved for the copying process.
Please note that if you are using Sigil 0.99 then the first time you run the plugin it will try to run again when an image has been imported. To get round this issue please close Sigil after installing the plugin. You can then use the plugin next time you open Sigil.

DiapDealer 02-05-2017 04:49 PM

Thanks! I'll get it added to the plugin index.

bravosx 02-05-2017 06:16 PM

1 Attachment(s)
@CalibUser...

When you attempt to use the plug getting the message.

:help:

bravosx

Doitsu 02-05-2017 06:27 PM

@bravosx: The plugin works fine on my Windows 10 machine. Did you check the Use Bundled Python box in the Manage Plugins dialog box?

If so, you'll need to post the steps that caused this message to be displayed, unless it's being displayed immediately after running the plugin.

DiapDealer 02-05-2017 06:37 PM

The epub he opened probably has no images in it. I get the same error when launching the plugin when no images exist (in the plugin). Works fine on Linux, otherwise.

Just needs a way to handle the empty list situation, is all.


EDIT: I take that back. It's not the images. The error happens when an epub only has 1 xhtml file. One of the combo boxes is set to default to the second entry in the list ... but a brand-new epub only has one xhtml file.

bravosx 02-05-2017 06:56 PM

@Doitsu...
@DiapDealer...

Field: of Use Bundled Python box in the Manage Plugins dialog box is checked.

An error message is given a moment after starting the plug.

Images are included eo Images directory.

edit: The plugin works properly when epub is a lot of files in the folder text.

Sorry for my English.
Regards
bravosx

Toxaris 02-06-2017 03:17 AM

Thanks! I will wait for an update for the reported bug though!

DiapDealer 02-06-2017 09:28 AM

1 Attachment(s)
Some suggestions in the attached patch.

In addition to the index error, I'd suggest populating the combo box with the xhtml file _names_, rather than their manifest ids. Many people won't recognize those offhand.

Also the image file filter is broken on the openfile dialog. My png files wouldn't show up unless I changed to "All files".

Yours to do with what you will, of course. Thanks for the plugin! :)

CalibUser 02-06-2017 03:38 PM

Thanks for the bug report and for the suggested patch - I have uploaded a correction in the first post of this thread

CalibUser 02-11-2017 04:53 PM

I have updated the plugin in the first post of this thread.

Quote:

Originally Posted by DiapDealer (Post 3471226)
...I'd suggest populating the combo box with the xhtml file _names_, rather than their manifest ids. Many people won't recognize those offhand.

I am not sure what you were referring to - the combo box showed the names of the xhtml files when I ran the original plugin eg Section0001.xhtml. Was you referring to the Images\... reference in the listbox? The new version no longer shows Images\...

DiapDealer 02-11-2017 05:06 PM

Quote:

Originally Posted by CalibUser (Post 3474052)
I have updated the plugin in the first post of this thread.



I am not sure what you were referring to - the combo box showed the names of the xhtml files when I ran the original plugin eg Section0001.xhtml. Was you referring to the Images\... reference in the listbox? The new version no longer shows Images\...

No. The first version I saw was populating the combo box with the manifest ids of the epub's text files. Many epubs made by Sigil will have ids that match the filename (Sigil creates new files with ids equal to the filename if it can, but this isn't always guaranteed), but others may not. When I opened some of my own epubs, the combobox was populated with entries like "nav, toc" etc. They didn't match what I was seeing in Sigil's Book Browser.

You're not doing anything wrong, it's just that the manifest ids of an epub's files won't always match what a user sees in Sigil's Book Browser.

I included a "fix" for it in my patch. Perhaps you already applied it?

EDIT: Yes, I see my patched code being used on line 139
Code:

for id, href in self.bk1.text_iter():
    self.xhtmlTuple=self.xhtmlTuple + (os.path.basename(href),)

Originally it was:
Code:

for id, href in self.bk1.text_iter():
    self.xhtmlTuple=self.xhtmlTuple + (id,)


KevinH 02-11-2017 05:10 PM

The content.opf uses manifest ids. A manifest id is any unique identifier name. To make dure the id is unique, some people and somesofrware will copy the file name and use it as the manifest identifier. This is a simple way to assure uniqeness but can be confusing as both the actual filename based on the manifest href and the manifest id can look identical but need not be. That is why using the filenam part of the href is recommended as the id for that same manifest entry could be something like "c1" instead of "chapter1.xhtml".

Hope this explains things.

KevinH

DiapDealer 02-11-2017 05:20 PM

Also, a heads-up to all that Python 3.6 absolutely detests tuples with null elements. For future compatibility, consider not using code like:

EDIT: never mind ... I remembered the issue wrong. The issue was empty/Null first elements in tuple that can cause problems in 3.6+. But only in freaky os.execvp() commands that you probably won't run into. Sorry for any confusion.

CalibUser 02-11-2017 05:21 PM

@DiapDealer - Thanks for the supplying the bug fix - I had not realised that my original code populated the combobox with entries like "nav, toc" etc as my tests did not show this - all my IDs did match the filenames in my tests so I didnot detect this problem.

@KevinH - Thanks for the clarification.

DiapDealer 02-11-2017 05:35 PM

No problem! :)


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

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