Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 05-09-2011, 11:44 AM   #1
KevinH
Wizard
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: 2,350
Karma: 756374
Join Date: Nov 2009
Device: many
new plugins and using import

Hi Kovid, Other Plugin Developers

I am in the process of updating some older File Type plugins to the new plugin interface and I looked at your examples but still had a few questions.

From our old File Type plugin "_plugin.py" we could easily import other python code from our own zip archive by simply using "import" as long as we did it inside of the "run" method. So we never ran into any zipimport issues, since we never needed to do that.

Is using simple imports from within the run methods still the right way to import other code from our plugin zip archive for File Type Plugins?

I noticed you used some other approaches for UI demos where you defined a new class that did the main work but I was not sure if you needed/wanted that approach for the simpler file type plugins?

Thanks,

KevinH
KevinH is offline   Reply With Quote
Advert
Old 05-09-2011, 05:20 PM   #2
KevinH
Wizard
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: 2,350
Karma: 756374
Join Date: Nov 2009
Device: many
Hi,

Just in case anyone else is interested in this question: based on trial and error with my own plugin and Calibre 0.8.0, it seems I misunderstood how use of import had changed in the new plugins setup. With recent calibre versions I can now use "import" anyplace (even for other files from the plugin zip) in __init.py__. So I no longer need to restrict the imports to be within the run method.

That is a very nice improvement indeed.

KevinH
KevinH is offline   Reply With Quote
Old 05-09-2011, 08:35 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: 30,281
Karma: 7723403
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You can import anything from anywhere, and no you dont need multiple classes for file type plugins. Really, ll you need to migrate an old plugin is to rename the .py file to _init__.py and add the .txt file that gives the import name. Of course for maintainability of your plugin you should ideally split it up into multiple .py files, which the new import mechanism facilitates.
kovidgoyal is offline   Reply With Quote
Old 05-09-2011, 09:37 PM   #4
KevinH
Wizard
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: 2,350
Karma: 756374
Join Date: Nov 2009
Device: many
Hi Kovid,

Please forgive my ignorance here but just to be clear ...

By adding a "plugin-import-name-MYPLUGIN.txt" empty text file to my plugin zip archive, I am effectively saying the contents of my plugin zip file uses a namespace (or something like that) called "MYPLUGIN". This is done to prevent name clashes with other python files used inside calibre and/or inside other plugins, is that right?

Then in my __init__.py (or any of my other .py files in the plugin) I change my imports of other python files local to my plugin to use that "namespace" equivalent as follows:

from calibre_plugins.MYPLUGIN import file1

This would be equivalent to adding "import file1" in the run method under the old plugin interface.

Am I understanding things correctly?

Thanks,

KevinH

Last edited by KevinH; 05-09-2011 at 09:43 PM. Reason: fix typos
KevinH is offline   Reply With Quote
Old 05-09-2011, 11:48 PM   #5
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: 30,281
Karma: 7723403
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes .
kovidgoyal is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DRM plugins jjansen Plugins 9 12-01-2012 06:22 PM
Index of plugins kiwidude Plugins 0 01-27-2011 07:19 PM
Introduction to plugins kiwidude Plugins 0 01-27-2011 09:15 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 02:49 PM.


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