11-27-2010, 03:57 PM | #1 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
Custom external commands in the GUI
I have several custom scripts that perform some (ebook/ereader related) actions that Calibre does not implement on its own. I was wondering whether there exists a mechanism to integrate them in the Calibre GUI. It could simply mean adding a button with user specified name to user specified group which would simply run a user specified command and return information about success/failure (through or besides the Calibre job management).
In case there is no mechanism for custom commands from GUI: it should not be difficult for me to write Calibre GUI plugins that would do what I describe above. But is there a way to set things up so that the custom plugins survive a binary Calibre update while all the remaining 'stock' Calibre functionality comes in binary form? I have read about the development environment but I am not sure it would enable this? |
11-27-2010, 04:45 PM | #2 | |
Calibre Plugins Developer
Posts: 4,678
Karma: 2162246
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
I've made a number of modifications to the source for various gui actions (some submitted as patches, others not), and I just keep pulling down the latest source and merging it into my version of the code. Not a big deal once you know what to do - I was a complete noob to Python and Bazaar so it took a while but got there eventually. As time goes on I make more and more tweaks and "improvements" so it may all go wrong one day of course. |
|
Advert | |
|
11-27-2010, 04:54 PM | #3 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
Thanks kiwidude, this is exactly the information I needed!
I will try to get to the point so that (only) builtins.py manual rewrites are needed and then perhaps think of a workaround for that need (although it is extremely unlikely to find one if you did not). |
11-27-2010, 05:17 PM | #4 | |
Calibre Plugins Developer
Posts: 4,678
Karma: 2162246
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
For instance a "Run command" type menu action, with the definition of what that command is stored in the tweaks. So you and anyone else going forward could customise what it does without touching the source code, and if the menu action wasn't included in the default menu then no-one else will see it unless they customise their menu to include it. Whether something like that still fits your need of course is another issue... |
|
11-27-2010, 05:30 PM | #5 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
The tweak you mention sounds interesting but I have actually gone through the tweaks before asking my question and could not find anything like that - these are all the tweaks available for me (in 0.7.28 GUI):
Code:
series_index_auto_increment = 'next' author_sort_copy_method = 'invert' bool_custom_columns_are_tristate = 'yes' sort_columns_at_startup = None gui_pubdate_display_format = 'MMM yyyy' gui_timestamp_display_format = 'dd MMM yyyy' title_series_sorting = 'library_order' save_template_title_series_sorting = 'library_order' title_sort_articles=r'^(A|The|An)\s+' auto_connect_to_folder = '' sony_collection_renaming_rules={} sony_collection_sorting_rules = [] grouped_search_terms = {} add_new_book_tags_when_importing_books = False max_content_server_tags_shown=5 content_server_will_display = ['*'] content_server_wont_display = [''] maximum_resort_levels = 5 generate_cover_title_font = None generate_cover_foot_font = None doubleclick_on_library_view = 'open_viewer' |
Advert | |
|
11-27-2010, 05:41 PM | #6 |
creator of calibre
Posts: 44,428
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Actually, I just committed code to make interface action plugins also loadable from zip files. For details, see the commit (it includes documentation).
|
11-27-2010, 05:46 PM | #7 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
wow, this sounds great!!!
going to make a coffee and download the latest commit |
11-27-2010, 06:01 PM | #8 |
Calibre Plugins Developer
Posts: 4,678
Karma: 2162246
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
It was just an idea for a possible implementation - you would have to code it yourself. Trivial to do though - code like this will allow you to grab a value from the tweaks set on your machine (from a patch I did today to allow disabling bookmarks):
Code:
from calibre.utils.config import tweaks ... self.disable_bookmarks = tweaks['disable_bookmarks_in_ebook_viewer'] Thanks Kovid for the latest fix for zip interface actions, will change the two I have written so far to use that approach. |
11-27-2010, 06:26 PM | #9 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
Kovid: I cannot find the documentation, where is it located?
kiwidude: I get it now, it might be an option too |
11-27-2010, 06:35 PM | #10 |
creator of calibre
Posts: 44,428
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
look at the patch accompanying the commit. Specifically the patch to plugins.rst and __init__.py
Basically you just have to create the InterfaceActionBase and InterfaceAction subclasses and have the load_actual_plugin method of your InterfaceActionBase subclass return the InterfaceAction subclass |
11-27-2010, 06:43 PM | #11 | |
Calibre Plugins Developer
Posts: 4,678
Karma: 2162246
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
I'm going through trial and error here and going in circles a bit. It was blowing up on my imports being defined at the top (giving errors like "ImportError: cannot import name error_dialog"). So I moved those into my InterfaceAction subclass and now get this error: Code:
Failed to initialize plugin... Traceback (most recent call last): File "D:\CalibreDev\latest\calibre\src\calibre\customize\ui.py", line 518, in initialize_plugins File "D:\CalibreDev\latest\calibre\src\calibre\customize\ui.py", line 83, in load_plugin File "<string>", line 8, in <module> File "D:\CalibreDev\latest\calibre\src\calibre\gui2\actions\__init__.py", line 12, in <module> ImportError: cannot import name Dispatcher |
|
11-27-2010, 07:12 PM | #12 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
Code:
ImportError: cannot import name Dispatcher |
11-27-2010, 07:25 PM | #13 |
creator of calibre
Posts: 44,428
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Hold your horses, I'll put together a GUI helloWorld plugin later today.
|
11-27-2010, 07:40 PM | #14 |
creator of calibre
Posts: 44,428
Karma: 24044628
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Here you go:
Code:
#!/usr/bin/env python # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __docformat__ = 'restructuredtext en' from calibre.customize import InterfaceActionBase class HelloWorldBase(InterfaceActionBase): name = 'Hello World GUI' author = 'The little green man' def load_actual_plugin(self, gui): from calibre.gui2.actions import InterfaceAction class HelloWorld(InterfaceAction): name = 'Hello World GUI' action_spec = ('Hello World!', 'add_book.png', None, _('Ctrl+Shift+H')) def genesis(self): self.qaction.triggered.connect(self.hello_world) def hello_world(self, *args): from calibre.gui2 import info_dialog info_dialog(self.gui, 'Hello World!', 'Hellooo World!', show=True) return HelloWorld(gui, None) |
11-27-2010, 08:23 PM | #15 |
Addict
Posts: 219
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
|
It works perfectly now, I have my first simple plugin working and it even does what it should (refresh screen on the device)!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can I stop Sigil from inserting sgc formatting commands? | ramjet1953 | Sigil | 4 | 11-22-2010 11:59 AM |
list of commands for Calibre | JTAL604622 | Calibre | 5 | 06-23-2010 04:21 PM |
GUI suggestion | carpii | Calibre | 3 | 02-27-2010 12:32 PM |
Problems Using Calibredb Commands in a Batch File | Cartaphilus | Calibre | 3 | 01-22-2010 07:18 PM |
PRS-500 Available XML commands | johnmcelfresh | Sony Reader Dev Corner | 0 | 08-18-2007 01:55 PM |