Debian Codegraph @

manual/plugin_examples/interface_demo/__init__.py

raw
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 # The class that all Interface Action plugin wrappers must inherit from
10 from calibre.customize import InterfaceActionBase
11
12
13 class InterfacePluginDemo(InterfaceActionBase):
14 """
15 This class is a simple wrapper that provides information about the actual
16 plugin class. The actual interface plugin class is called InterfacePlugin
17 and is defined in the ui.py file, as specified in the actual_plugin field
18 below.
19
20 The reason for having two classes is that it allows the command line
21 calibre utilities to run without needing to load the GUI libraries.
22 """
23
24 name = 'Interface Plugin Demo'
25 description = 'An advanced plugin demo'
26 supported_platforms = ['windows', 'osx', 'linux']
27 author = 'Kovid Goyal'
28 version = (1, 0, 0)
29 minimum_calibre_version = (0, 7, 53)
30
31 #: This field defines the GUI plugin class that contains all the code
32 #: that actually does something. Its format is module_path:class_name
33 #: The specified class must be defined in the specified module.
34 actual_plugin = 'calibre_plugins.interface_demo.ui:InterfacePlugin'
35
36 def is_customizable(self):
37 """
38 This method must return True to enable customization via
39 Preferences->Plugins
40 """
41 return True
42
43 def config_widget(self):
44 """
45 Implement this method and :meth:`save_settings` in your plugin to
46 use a custom configuration dialog.
47
48 This method, if implemented, must return a QWidget. The widget can have
49 an optional method validate() that takes no arguments and is called
50 immediately after the user clicks OK. Changes are applied if and only
51 if the method returns True.
52
53 If for some reason you cannot perform the configuration at this time,
54 return a tuple of two strings (message, details), these will be
55 displayed as a warning dialog to the user and the process will be
56 aborted.
57
58 The base class implementation of this method raises NotImplementedError
59 so by default no user configuration is possible.
60 """
61 # It is important to put this import statement here rather than at the
62 # top of the module as importing the config class will also cause the
63 # GUI libraries to be loaded, which we do not want when using calibre
64 # from the command line
65 from calibre_plugins.interface_demo.config import ConfigWidget
66
67 return ConfigWidget()
68
69 def save_settings(self, config_widget):
70 """
71 Save the settings specified by the user with config_widget.
72
73 :param config_widget: The widget returned by :meth:`config_widget`.
74 """
75 config_widget.save_settings()
76
77 # Apply the changes
78 ac = self.actual_plugin_
79 if ac is not None:
80 ac.apply_settings()