|
|
#1 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Writing an interface action plugin
Reading about the lovely "plugin architecture" I thought I would look into dabbling myself with it. I've "had a go" with trial & error but stumped I think with the wrapper class. Has anyone successfully attempted this and if so could they share their code or experiences? Is there an equivalent of the "HelloWorld" plugin example for an interface action? I have a bunch of questions but a simple example would solve most of them I am sure. This is what I have so far (simplified) - all classes in the same file: Filename: foo_plugin.py, Zipped into: foo_plugin.zip Code:
import webbrowser
from calibre.customize import InterfaceActionBase
from calibre.gui2.actions import InterfaceAction
from calibre.gui2 import error_dialog
class ActionFoo(InterfaceActionBase):
name = 'Foo'
actual_plugin = 'FooAction'
class FooAction(InterfaceAction)
name = ... etc with implementation
Many thanks for help - first time at trying to write Python (.NET developer in the day job) so please be gentle
Last edited by kiwidude; 11-10-2010 at 02:57 PM. |
|
|
|
|
|
#2 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Ok, so I got one step further... I changed the code line for actual_plugin to have this value:
Code:
actual_plugin = 'calibre.gui2.actions.foo_plugin:FooAction' If I list the plugins using calibre-customize it appears in the list, and I can see the zip file in the Roaming\calibre\plugins folder. There seems to be some trick I am missing though to (a) get the plugin to appear back in the Preferences dialog after a restart, and (b) to get my menu items to actually appear (which may or may not be related to the implementation). I have tried copying directly an implementation from show_book_details.py into my FooAction class to prove it is not part of the code and it makes no difference? That version is now attached. Apologies for being a pain for asking. Last edited by kiwidude; 11-10-2010 at 03:54 PM. Reason: Added attachment |
|
|
|
|
Enthusiast
|
|
|
|
#3 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,514
Karma: 2944574
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The InterfaceAction plugins aren't really designed to be loaded from zip files (this is because they depend on Qt, unlike most other plugin classes) that's why you have to jump through the "actual_plugin" hoops.
I'd suggest running calibre from source and implementing your plugin there. It's fairly trivial to run calibre from source, instructions in the user manual.
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
|
#4 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
That's a shame.
Is there a way of getting just the 0.7.26 version of the code for me to run, rather than the trunk? I'm running on Windows btw. |
|
|
|
|
|
#5 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,514
Karma: 2944574
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
you can check out any revision you like from the source code.
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
|
#6 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Ummm... could you please be so kind as to give me a command line I could type for that? Not familiar with Bazaar or your repo structure sorry. I followed the instructions on the web page previously with
bzr branch lp:calibre |
|
|
|
|
|
#7 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,514
Karma: 2944574
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
do
bzr revert -r revision_number in your checkout, get the revision_number you want with bzr log
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
|
#8 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Brilliant, thank you very much.
Ok, time for the really dumb question. I've setup my environment variable, got the right revision of code I want... But how do I actually run from source?
|
|
|
|
|
|
#9 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,596
Karma: 549131
Join Date: Nov 2008
Device: Sony PRS-950, iphone/ipad (stanza/iBooks/QuickReader)
|
Once you have downloaded the source and set up the Environment variable correctly to specify its location, just start up Calibre in the normal way and the source is automatically picked up. Source files automatically supersede binary files if they are newer.
|
|
|
|
|
|
#10 | |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Quote:
At a command prompt when I type echo %CALIBRE_DEVELOP_FROM% it gives me back "c:\calibre" which is my root directory that has a src subdirectory with the changes in. Something else obvious I am doing wrong? |
|
|
|
|
|
|
#11 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,514
Karma: 2944574
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You need to use c:\calibre\src
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
|
#12 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
That would be the obvious thing
Thanks kovid, running from source now.
|
|
|
|
|
|
#13 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Ok, got my action plugged into the menu. For anyone else's info who follows in my footsteps (and for Kovid to tell me if I did wrong) I did these steps:
1. Add your implementation class file into \src\calibre\gui2\actions 2. Edit src\calibre\customize\builtins.py to add the wrapper class implementation pointing to the above. Also add the name of that wrapper class to the 'plugins' variable array. 3. Edit src\calibre\gui2\__init__.py to ensure the context menu item actually physically appears in the 'action-layout-context-menu' array in appropriate place you want it to appear in the menu. The value you add here matches that of the 'name' property of the implementation class. 4. Begin many iterations of opening and closing calibre as you learn how to write code in Python ![]() I've got a working (crude) implementation though of launching the webpage for fantasticfiction for the current selected author which was the first goal so stoked with that. Thanks for the help to get up and running! |
|
|
|
|
|
#14 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,514
Karma: 2944574
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Note that 3 is not strictly necessary, you can control what appears in the context menus and toolbars via Preferences->Toolbars
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
|
#15 |
|
calibre/Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,088
Karma: 1211092
Join Date: Oct 2010
Location: London, UK
Device: Kindle 3 3G, iPad 2, iPad 3
|
Ahhh yes, did not know that, thanks Kovid.
Job done... loving it! A shame I have to run from source (would be nicer as a zip plugin) but that I was able to add this so easily is a tribute to the quality of the existing codebase - great job Kovid and whoever else wrote Calibre. I've attached a screenshot for anyone interested in what I ended up with. The sub-menu options are currently defined in an array. You specify the name, icon and a url with tokens like {author}, {title} or {isbn} to be substituted by the plugin based on the selected row. You can also do empty rows for separators. If there was any interest by others in this becoming a patch to add to the trunk whoever wants to do it is welcome to the code, let me know. It would be nice to make the array able to be specified via the tweaks file or some other configuration, so users can manipulate the menu with other websites etc. I've not written this to be "bulletproof" being a Python newbie but it does the job for me. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New Plugin Type Idea: Library Plugin | cgranade | Plugins | 3 | 09-15-2010 12:11 PM |
| Device interface plugin - nook | badmadbug | Plugins | 2 | 09-06-2010 11:03 AM |
| Manybooks new interface | mtravellerh | Upload Help | 0 | 11-30-2008 08:26 AM |
| OS X Interface | irulan | Calibre | 5 | 09-13-2008 01:18 PM |
| iLiad Interface Design | nathany | iRex Developer's Corner | 6 | 09-17-2007 02:05 PM |