| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai |
| 3 |
|
| 4 |
|
| 5 |
__license__ = 'GPL v3' |
| 6 |
__copyright__ = '2011, Kovid Goyal <[email protected]>' |
| 7 |
__docformat__ = 'restructuredtext en' |
| 8 |
|
| 9 |
if False: |
| 10 |
# This is here to keep my python error checker from complaining about |
| 11 |
# the builtin functions that will be defined by the plugin loading system |
| 12 |
# You do not need this code in your plugins |
| 13 |
get_icons = get_resources = None |
| 14 |
|
| 15 |
# The class that all interface action plugins must inherit from |
| 16 |
from calibre.gui2.actions import InterfaceAction |
| 17 |
from calibre_plugins.interface_demo.main import DemoDialog |
| 18 |
|
| 19 |
|
| 20 |
class InterfacePlugin(InterfaceAction): |
| 21 |
name = 'Interface Plugin Demo' |
| 22 |
|
| 23 |
# Declare the main action associated with this plugin |
| 24 |
# The keyboard shortcut can be None if you don't want to use a keyboard |
| 25 |
# shortcut. Remember that currently calibre has no central management for |
| 26 |
# keyboard shortcuts, so try to use an unusual/unused shortcut. |
| 27 |
action_spec = ('Interface Plugin Demo', None, 'Run the Interface Plugin Demo', 'Ctrl+Shift+F1') |
| 28 |
|
| 29 |
def genesis(self): |
| 30 |
# This method is called once per plugin, do initial setup here |
| 31 |
|
| 32 |
# Set the icon for this interface action |
| 33 |
# The get_icons function is a builtin function defined for all your |
| 34 |
# plugin code. It loads icons from the plugin zip file. It returns |
| 35 |
# QIcon objects, if you want the actual data, use the analogous |
| 36 |
# get_resources builtin function. |
| 37 |
# |
| 38 |
# Note that if you are loading more than one icon, for performance, you |
| 39 |
# should pass a list of names to get_icons. In this case, get_icons |
| 40 |
# will return a dictionary mapping names to QIcons. Names that |
| 41 |
# are not found in the zip file will result in null QIcons. |
| 42 |
icon = get_icons('images/icon.png', 'Interface Demo Plugin') |
| 43 |
|
| 44 |
# The qaction is automatically created from the action_spec defined |
| 45 |
# above |
| 46 |
self.qaction.setIcon(icon) |
| 47 |
self.qaction.triggered.connect(self.show_dialog) |
| 48 |
|
| 49 |
def show_dialog(self): |
| 50 |
# The base plugin object defined in __init__.py |
| 51 |
base_plugin_object = self.interface_action_base_plugin |
| 52 |
# Show the config dialog |
| 53 |
# The config dialog can also be shown from within |
| 54 |
# Preferences->Plugins, which is why the do_user_config |
| 55 |
# method is defined on the base plugin class |
| 56 |
assert base_plugin_object is not None |
| 57 |
do_user_config = base_plugin_object.do_user_config |
| 58 |
|
| 59 |
# self.gui is the main calibre GUI. It acts as the gateway to access |
| 60 |
# all the elements of the calibre user interface, it should also be the |
| 61 |
# parent of the dialog |
| 62 |
d = DemoDialog(self.gui, self.qaction.icon(), do_user_config) |
| 63 |
d.show() |
| 64 |
|
| 65 |
def apply_settings(self): |
| 66 |
from calibre_plugins.interface_demo.config import prefs |
| 67 |
|
| 68 |
# In an actual non trivial plugin, you would probably need to |
| 69 |
# do something based on the settings in prefs |
| 70 |
prefs |