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

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 11-27-2010, 03:57 PM   #1
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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?
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 04:45 PM   #2
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,223
Karma: 1333994
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Quote:
Originally Posted by janvanmaar View Post
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?
Someone like Kovid can give you the 100% facts about it but from my experiences it seems that the plug-in architecture unfortunately does not include zip plugins for gui interface actions. See this thread for my experiences of the first gui action I tried to add. It is so close to being possible but there is a unfortunately one existing file (builtins.py) which you have to modify each time for every action you add.

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.
kiwidude is offline   Reply With Quote
Old 11-27-2010, 04:54 PM   #3
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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).
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 05:17 PM   #4
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,223
Karma: 1333994
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Quote:
Originally Posted by janvanmaar View Post
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).
Well if you can think of a way to convince Kovid that your requirement would be useful to others and submit it as a patch then that would solve your update problem ;-)

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...
kiwidude is offline   Reply With Quote
Old 11-27-2010, 05:30 PM   #5
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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'
Where can I find the tweak you mention?
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 05:41 PM   #6
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: 25,246
Karma: 4961457
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).
kovidgoyal is online now   Reply With Quote
Old 11-27-2010, 05:46 PM   #7
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 06:01 PM   #8
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,223
Karma: 1333994
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Quote:
Originally Posted by janvanmaar View Post
Where can I find the tweak you mention?
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']
If you want to put it all together as a patch to submit then you would also want to modify resources\default_tweaks.py so that other users would know what the possible values are.

Thanks Kovid for the latest fix for zip interface actions, will change the two I have written so far to use that approach.
kiwidude is offline   Reply With Quote
Old 11-27-2010, 06:26 PM   #9
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 06:35 PM   #10
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: 25,246
Karma: 4961457
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
kovidgoyal is online now   Reply With Quote
Old 11-27-2010, 06:43 PM   #11
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,223
Karma: 1333994
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Quote:
Originally Posted by kovidgoyal View Post
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
Kovid, do you have an example py you could post, just like the HelloWorld one?

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
kiwidude is offline   Reply With Quote
Old 11-27-2010, 07:12 PM   #12
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
Karma: 404
Join Date: Nov 2010
Device: Kindle 3G, Samsung SIII
Code:
ImportError: cannot import name Dispatcher
That's exactly the same error message I am getting it looks so simple but we are still doing something wrong apparently...
janvanmaar is offline   Reply With Quote
Old 11-27-2010, 07:25 PM   #13
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: 25,246
Karma: 4961457
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Hold your horses, I'll put together a GUI helloWorld plugin later today.
kovidgoyal is online now   Reply With Quote
Old 11-27-2010, 07:40 PM   #14
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: 25,246
Karma: 4961457
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)
Add this plugin and press Ctrl+Shift+H in the gui to see a nice Hello World popup
kovidgoyal is online now   Reply With Quote
Old 11-27-2010, 08:23 PM   #15
janvanmaar
Addict
janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.janvanmaar has a complete set of Star Wars action figures.
 
Posts: 215
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)!
janvanmaar is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 03:25 AM.


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