root/gaphor/tags/gaphor-0.2.0/gaphor/plugin.py

Revision 146, 3.4 kB (checked in by arjanmol, 6 years ago)

Many changes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # vim:sw=4
2 """
3 Plugin support for Gaphor.
4 """
5
6 from gaphor.misc.command import Command
7
8 class PluginCommand(Command):
9     """
10     This is the base class for all plugin commands that are to be executed.
11     PluginCommand is basically an implementation of the command pattern,
12     extended by the possibility to make menu items (in)sensitive.
13     """
14
15     def __init__(self, **args):
16         pass
17
18     def get_menu_item(self):
19         """
20         Return the menu item representing this plugin in a menu.
21         """
22         pass
23
24     def set_menu_item(self, menu_item):
25         """
26         Store a menu item reference in the plugin. The plugin should take care
27         of making the menu item (in)sensitive at the right moment.
28         The menu item is of type gaphor.ui.MenuItem (or gaphor.ui.CheckMenuItem
29         for check box menu items or gaphor.ui.RadioMenuItem for radiobutton
30         menu items).
31         """
32         pass
33
34     def get_comment(self):
35         """
36         Return a piece of text to describe the menu item.
37         """
38         pass
39
40     def execute(self):
41         """
42         Run the plugin.
43         """
44         pass
45
46
47 class Plugin(object):
48     """
49     Plugin class. One instance of this class is created. It is used as
50     a factory for PluginCommand objects.
51     """
52
53     def __init__(self):
54         """
55         Initialize a new instance of the plugin.
56         """
57         pass
58
59     def get_menu_entry(self):
60         """
61         Return the menu entry that need to be added through this Plugin.
62         It should return a (list of) tuple(s) with the format:
63             (stock_id, 'menuitem name', 'icon file(s)')
64         """
65         pass
66
67     def register(self):
68         """
69         Return a class for which the item should be displayed, or a sequence
70         of classes in case it may appear for more than one item.
71         For example, if this plugin should appear in the main menu (in the
72         gaphor.ui.MainWindow class) this function should return
73         "(gaphor.ui.MainWindow, 'path/to/menu entry')". If it should also
74         appear in the diagram widget in the diagram window it should return
75         "((gaphor.ui.MainWindow, 'path/to/menu entry'),
76           (gaphor.ui.DiagramView, 'path/to/menu entry')).
77         e.g.
78             return (gaphor.ui.MainWindow, 'File/Export/SVG...')
79         or
80             return (gaphor.UML.Namespace, 'Edit/Set parent')
81         In case this item should appear only for (popup) menu's on namespace
82         elements (such as classes, packages and use cases).
83
84         If the pathname starts with 'toolbar/' it appears in the toolbar, if
85         a toolbar exists.
86         """
87         pass
88
89     def get_image(self):
90         """
91         Return an image for the menu item. This is useful in case it appears
92         in a toolbox.
93         You can also return a
94         """
95         pass
96
97     def create(self, **context):
98         """
99         Return a new instance of a PluginCommand, context contains a buch of
100         variables that can be used to set the state of the plugin.
101         The variables 'class' and 'menupath' are the same as the variables
102         returned by register().
103         """
104         pass
105
106     def remove(self, instance):
107         """
108         Do some cleanup after this instance is removed.
109         """
110         pass
111
112 class CheckPlugin(Plugin):
113     """
114     Inherit from this class if your plugin should appear as a checkbox menu
115     item in the menu.
116     """
117     pass
118
119 class RadioPlugin(Plugin):
120     """
121     Inherit from this class if your plugin should appear as a radio menu
122     item in the menu. Note that register() should return at least two entries.
123     """
124
125     def register(self):
126         """
127         In case of radio menu items, more items can be returned using the
128         same class, the same menu path, but a different menu item name.
129         """
130         pass
131
Note: See TracBrowser for help on using the browser.