Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-03-2014, 12:48 PM   #1
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,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
plugin_path for editor plugins.

Is there (or can there be) an easy method to obtain the path to the plugin's own zip file (like self.plugin_path in the run method of a File type plugin) in an editor plugin's main.py:Tool classes? For the purpose of extracting resources. The os.path.join(config_dir, 'plugins', '{}.zip'.format(plugin_name)) method seems a little fragile.
DiapDealer is offline   Reply With Quote
Old 08-03-2014, 07:34 PM   #2
kabirmaar
Member
kabirmaar began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
I found load_resources in InterfaceAction helpful:

https://github.com/kovidgoyal/calibr...init__.py#L260

Code:
If this plugin comes in a ZIP file (user added plugin), this method
        will allow you to load resources from the ZIP file.

        For example to load an image::

            pixmap = QPixmap()
            pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues().next())
            icon = QIcon(pixmap)

        :param names: List of paths to resources in the zip file using / as separator

        :return: A dictionary of the form ``{name : file_contents}``. Any names
                 that were not found in the zip file will not be present in the
                 dictionary.
Here is how I used it for Kaliweb plugin:
https://bitbucket.org/kabiir/kaliweb...t=master#cl-65

In short, in InterfaceAction.genesis:
Code:
res = self.load_resources(PORTABLE_RESOURCES)
for resource in res.keys():
    res[resource] #get data
I unpack resources from .zip file to temporary directory so that can be used during the running session. Then I use 'close' hook to delete that temporary directory
kabirmaar is offline   Reply With Quote
Advert
Old 08-03-2014, 11:05 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
http://manual.calibre-ebook.com/crea...lugin-zip-file
kovidgoyal is offline   Reply With Quote
Old 08-04-2014, 06:02 AM   #4
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,549
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Thanks guys. I don't know why I was making that more difficult than it was.
DiapDealer is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Editor: ToC Editor: Start entry macnab69 Editor 2 06-25-2014 11:15 AM
Book Editor TOC Editor Isue? weberr Editor 2 04-17-2014 11:13 AM
Plugins junkml Plugins 32 06-19-2009 06:43 AM
Plugins? Mitchll Plugins 0 12-27-2008 02:36 PM


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


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