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 01-24-2016, 08:35 AM   #196
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,735
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
@rubeus: you could also rename files with an input/output plugin.
Doitsu is offline   Reply With Quote
Old 01-24-2016, 08:54 AM   #197
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
Renaming means having to do a universal update to find everything that points to it. That code exists in Sigil so renaming is best done inside Sigil itself and not in a plugin to prevent huge duplication of url/href/src and etc link updating code. The purpose of the plugin is to extend Sigil, not duplicate Sigil's functionality.
The idea behind was to have some kind of heuristic, which Sigil does not have built in.

For example:

chapter05
chapter05_x
chapter05_001
SVGIMG
chapter05_end

should be

chapter05
chapter05_0001
chapter05_0002
chapter05_0003
chapter05_0004

In Sigil you have to do this block for block entering the startfilename newly each time. But if there is no API to call the rename funtionality in Sigil i will stop here as i dont want to care of links myself.
rubeus is offline   Reply With Quote
Advert
Old 01-24-2016, 09:39 AM   #198
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: 8,819
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi rubeus,

FYI: The plugin interface has absolutely no capability to call anything inside Sigil. The plugin interface simply saves all tabs to files to get the current state of the epub, launches python, running its launcher code, that parses the current content.opf and tries to make those files available to the plugin in a safe way. Anytime a plugin changes a file, a copy is made and the modified version is stored in a temp directory. When the plugin run() routine returns, the builtin python code tells Sigil what files were added, deleted, or modified (via the result.xml you saw briefly flash on the screen) as it exits. Sigil then processes ths list to make the changes the plugin requested using the modified copies stored in temp if needed.
So the plugin code never actually calls back into Sigil, it instead let's Sigil be in charge.

Hope this helps,

KevinH
KevinH is online now   Reply With Quote
Old 01-30-2016, 12:48 PM   #199
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: 8,819
Karma: 6000000
Join Date: Nov 2009
Device: many
FYI:,

I have updated the first post in this thread with a sampleOutput plugin that will properly obfuscate fonts on output and that will remove the Sigil version metadata by example. It will require the forthcoming Sigil-0.9.3 to work due to recently fixed bugs in the plugin launcher code.

I have also added an updated testme3_v030.zip edit plugin that provides many examples of how to use the plugin interfaces.

Also added links to Sigil_Plugin_Framework_rev7.epub and the launcher_version date for the upcoming Sigil-0.9.3 release.

Last edited by KevinH; 01-30-2016 at 12:53 PM.
KevinH is online now   Reply With Quote
Old 01-30-2016, 02:32 PM   #200
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
If i set the return code to something different as zero, are the changes i did via writefile, addfile etc rolled backed?
rubeus is offline   Reply With Quote
Advert
Old 01-30-2016, 02:39 PM   #201
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: 8,819
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi rubeus,
Yes. If you set the return value to -1 (or any non-zero value), none of the changes you made will be used. They will all be discarded. The way the plugin interface is designed, any modificatins done by the plugin are simply recorded (as in the case of deletes) or stored in a temp directory. When the plugin completes and control returns to Sigil, if the plugin returns success (0), the actual changes are made by Sigil itself, otherwise it ignores them.

KevinH

Quote:
Originally Posted by rubeus View Post
If i set the return code to something different as zero, are the changes i did via writefile, addfile etc rolled backed?
KevinH is online now   Reply With Quote
Old 02-06-2016, 03:45 PM   #202
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've currently played around with bk.selected_iter() wich gives the tupel (Id_type, id) back, In my case, id_type has always the value manifest. Whats the intention returning always (?) this value?

//rubeus
rubeus is offline   Reply With Quote
Old 02-06-2016, 04:24 PM   #203
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: 28,631
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by rubeus View Post
Hi,

I've currently played around with bk.selected_iter() wich gives the tupel (Id_type, id) back, In my case, id_type has always the value manifest. Whats the intention returning always (?) this value?

//rubeus
Not all files return an id_type value of "manifest". The OPF file for instance doesn't. But you're right, most will. There's not many unmanifested files in an epub, but they need to be accounted for.
DiapDealer is offline   Reply With Quote
Old 03-17-2016, 08:15 AM   #204
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
I'm trying now to get a preference dialog in my AddImgasSVG plugin.

So i had a look at DiapDealers TagMechanic but failed, what i could achieve is a dialog window but without a simple button

So i'm trying to find a tutorial but none was so simple that even i was able to understand it.

I would like to have a separate class so i started creating one derived from TopLevel. What i currently dont understand is why do i need to call the Grame Method to put a button in it? DiapDealer created a box, and inside the box a second frame for the buttons and here i give up.

So: are there tutorials dealing with this? I was unable to find one, most of them are just opening a window and this is what i have already. I would like to have a fourth Button - no problem.

Took some code from DiapDealer (which i didnt understand), i got a window but the simple button i added doesnt show up. As i'm not getting any error message i dont know what i'm doing wrong.

What i have "stolen" so far;

Code:
class PrefDialog(tkinter.Toplevel):

    def __init__(self, parent):
        
        tkinter.Toplevel.__init__(self, parent)
        self.resizable(False, False)
        self.title('Preferences')
        self.parent = parent

        self.initUI()

    def initUI(self):
        body = tkinter.Frame(self)
        body.pack(fill=tkinter_constants.BOTH)
        
        buttons = tkinter.Frame(body)
        cancelButton = tkinter.Button(buttons, text='Done', command=self.cmdDo)
        cancelButton.pack(side=tkinter_constants.LEFT, fill=tkinter_constants.BOTH, expand=True)        

        self.withdraw()
        self.transient(self.parent)
        self.grab_set()
        self.center()
        self.deiconify()
        self.maingui.wait_window(self)
The result can be seen in the attachment
Attached Thumbnails
Click image for larger version

Name:	pref.png
Views:	778
Size:	49.9 KB
ID:	147151  

Last edited by rubeus; 03-17-2016 at 08:23 AM.
rubeus is offline   Reply With Quote
Old 03-17-2016, 08:35 AM   #205
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: 28,631
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
@rubeus: Tkinter gui stuff can be incredibly tedious and unintuitive for anything other than the simplest of dialogs/tasks. What I've picked up about it has mostly been through Google searches, hours of tedious trial and error, and much, much "code borrowing."

When it comes to placing widgets (geometry management), there are two methods used "grid" and "pack." Both have their pluses/minuses, but both can be used pretty easily (for simple interfaces). The only time you really need to worry about using Frames is when your interface layouts get increasingly complex.

Some sites I've used repeatedly are:
http://effbot.org/tkinterbook/
http://zetcode.com/gui/tkinter/
And of course, Stackoverflow.com.

If you want to create git repositories for your plugins' code, I'd be happy to provide some input/direction/pointers when you get stuck on something.

Last edited by DiapDealer; 03-17-2016 at 08:37 AM.
DiapDealer is offline   Reply With Quote
Old 06-01-2016, 07:32 AM   #206
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,735
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Question Use of HTML code in the Plugin Runner/Validation windows

Is it possible to use HTML/Pango markup to change font properties in the Plugin Runner/Valdiation windows? (E.g. change the font color and/or add yellow highlight to specific words.)
Doitsu is offline   Reply With Quote
Old 06-01-2016, 09:38 AM   #207
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: 8,819
Karma: 6000000
Join Date: Nov 2009
Device: many
Hi Doitsu,

Quote:
Originally Posted by Doitsu View Post
Is it possible to use HTML/Pango markup to change font properties in the Plugin Runner/Valdiation windows? (E.g. change the font color and/or add yellow highlight to specific words.)

The only thing you can control is the info/warning/error level. The message will be xml escaped and uploaded as part of the result xml from the plugin.

Html may survive but I am not sure if any of the display widgets used will treat it as anything other than text.
KevinH is online now   Reply With Quote
Old 07-03-2017, 10:01 PM   #208
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
Problem with bk.setmetadataxml()

Hi everyone...I'm currently writing an edit plugin for my own use called Split2TOC. This plugin only works on imported html files and does the following:

* Splits the html file into separate xhtml files at heading boundaries
* Allows you to choose which heading style to use to split your file
* Adds the guides for cover, TOC and begin read(set to Chapter 1 or default)
* Removes any existing doc TOC
* Creates a Level 1 TOC file in the epub
* Creates a TOC CSS
* Adds the book cover
* Adds the metadata

Everything is working fine except when I try to add the epub metadata using setmetadataxml().

Here is my function that tries to set the metadata in the epub:

Spoiler:
Code:
def addOPFMetadata(bk, **meta):
   
    lang = getdefaultlocale()[0]
    if lang == None:
        lang = 'en'
    if '_' in lang:    
        lang = lang.split("_")[0]

    # add the metadata
    data =  ('  <metadata>')
    data += ('    <dc:date opf:event="creation">' + meta['date'] + '</dc:date>')
    data += ('    <dc:title>' + meta['title'].strip() + '</dc:title>\n')
    data += ('    <dc:identifier id="PrimaryID">urn:uuid:' + meta['book id'] + '</dc:identifier>\n')
    data += ('    <dc:language>' + lang + '</dc:language>\n')
    data += ('    <dc:creator opf:role="aut">' + meta['author'].strip() + '</dc:creator>\n')
    data += ('    <dc:publisher>' + meta['publisher'].strip() + '</dc:publisher>\n')
    data += ('    <dc:rights>Worldwide Copyright ©' + meta['year'] + ' ' +  meta['author'].strip() + \
                     '. All Rights Reserved.</dc:rights>\n')
    data += ('    <meta name="cover" content="cover-img" />\n')
    data += ('  </metadata>')

    bk.setmetadataxml(data)

    return(0)


And this is what I get in the epub opf metadata section after running that function:

Spoiler:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<package unique-identifier="BookId" version="2.0" xmlns="http://www.idpf.org/2007/opf">
  <metadata>
    <date event="creation">2017-07-04</date>
    <title>Test Book</title>
    <identifier id="PrimaryID">urn:uuid:c8b2a9e5-abcdef-ae9d-ef72-9d15c76a8be3</identifier>
    <language>en</language>
    <creator role="aut">John Smith</creator>
    <publisher>John Smith</publisher>
    <rights>Worldwide Copyright ©2017 John Smith. All Rights Reserved.</rights>
    <meta content="cover-img" name="cover"></meta>
  </metadata>


As you can see, the 'dc:' tag prefix/suffix is missing on all metadata items in the epub. It appears that setmetadaxml() is deliberately removing 'dc:' from my data. What am I missing or is this a known problem with setmetadataxml()? Any ideas?

Last edited by slowsmile; 07-03-2017 at 10:42 PM.
slowsmile is offline   Reply With Quote
Old 07-03-2017, 10:36 PM   #209
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: 28,631
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by slowsmile View Post
It appears that setmetadaxml() is deliberately removing 'dc:' from my data.
setmetadatxml() isn't removing the 'dc:' prefixes. Sigil is doing that after your plugin is done running. It's because the metadata tag you're creating and writing back to the opf file is insufficient. It does not contain the dc namespace declaration:

Code:
xmlns:dc="http://purl.org/dc/elements/1.1/"
Without this, Sigil's opf/xml parsing routines won't know how to handle the dc prefixes. So they get stripped (delete the dc namespace declaration from the metadata tag in any existing epub's OPF and the same thing will happen).

Look at the metadata tag properties in the OPF of Sigil's empty epub template for an example of the namepace declaration(s) you need to provide for the metadata tag that you ultimately hand back to the setmetadataxml() function if you're using dc metadata.

Instead of:
Code:
data =  ('  <metadata>')
You need something more like:
Code:
data =  ('  <metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">')

Last edited by DiapDealer; 07-03-2017 at 10:45 PM.
DiapDealer is offline   Reply With Quote
Old 07-03-2017, 11:22 PM   #210
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
@DiapDealer...Much thanks for your quick reply. I'll give that a try.
slowsmile 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 12:13 PM.


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