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