1 | ################################################################################ |
---|
2 | #This software was developed by the University of Tennessee as part of the |
---|
3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | #project funded by the US National Science Foundation. |
---|
5 | # |
---|
6 | #See the license text in license.txt |
---|
7 | # |
---|
8 | #copyright 2008, University of Tennessee |
---|
9 | ################################################################################ |
---|
10 | |
---|
11 | class PluginBase: |
---|
12 | """ |
---|
13 | This class defines the interface for a Plugin class |
---|
14 | that can be used by the gui_manager. |
---|
15 | |
---|
16 | Plug-ins should be placed in a sub-directory called "perspectives". |
---|
17 | For example, a plug-in called Foo should be place in "perspectives/Foo". |
---|
18 | That directory contains at least two files: |
---|
19 | perspectives/Foo/__init__.py contains two lines: |
---|
20 | |
---|
21 | PLUGIN_ID = "Foo plug-in 1.0" |
---|
22 | from Foo import * |
---|
23 | |
---|
24 | perspectives/Foo/Foo.py contains the definition of the Plugin |
---|
25 | class for the Foo plug-in. The interface of that Plugin class |
---|
26 | should follow the interface of the class you are looking at. |
---|
27 | |
---|
28 | See dummyapp.py for a plugin example. |
---|
29 | """ |
---|
30 | |
---|
31 | def __init__(self, name="Test_plugin", standalone=True): |
---|
32 | """ |
---|
33 | Abstract class for gui_manager Plugins. |
---|
34 | """ |
---|
35 | ## Plug-in name. It will appear on the application menu. |
---|
36 | self.sub_menu = name |
---|
37 | #standalone flag |
---|
38 | self.standalone = standalone |
---|
39 | ## Reference to the parent window. Filled by get_panels() below. |
---|
40 | self.parent = None |
---|
41 | |
---|
42 | ## List of panels that you would like to open in AUI windows |
---|
43 | # for your plug-in. This defines your plug-in "perspective" |
---|
44 | self.perspective = [] |
---|
45 | |
---|
46 | |
---|
47 | def populate_menu(self, id, parent): |
---|
48 | """ |
---|
49 | Create and return the list of application menu |
---|
50 | items for the plug-in. |
---|
51 | |
---|
52 | :param id: deprecated. Un-used. |
---|
53 | :param parent: parent window |
---|
54 | |
---|
55 | :return: plug-in menu |
---|
56 | |
---|
57 | """ |
---|
58 | return [] |
---|
59 | |
---|
60 | def get_panels(self, parent): |
---|
61 | """ |
---|
62 | Create and return the list of wx.Panels for your plug-in. |
---|
63 | Define the plug-in perspective. |
---|
64 | |
---|
65 | Panels should inherit from DefaultPanel defined below, |
---|
66 | or should present the same interface. They must define |
---|
67 | "window_caption" and "window_name". |
---|
68 | |
---|
69 | :param parent: parent window |
---|
70 | |
---|
71 | :return: list of panels |
---|
72 | |
---|
73 | """ |
---|
74 | ## Save a reference to the parent |
---|
75 | self.parent = parent |
---|
76 | |
---|
77 | # Return the list of panels |
---|
78 | return [] |
---|
79 | |
---|
80 | def get_tools(self): |
---|
81 | """ |
---|
82 | Returns a set of menu entries for tools |
---|
83 | """ |
---|
84 | return [] |
---|
85 | |
---|
86 | |
---|
87 | def get_context_menu(self, graph=None): |
---|
88 | """ |
---|
89 | This method is optional. |
---|
90 | |
---|
91 | When the context menu of a plot is rendered, the |
---|
92 | get_context_menu method will be called to give you a |
---|
93 | chance to add a menu item to the context menu. |
---|
94 | |
---|
95 | A ref to a Graph object is passed so that you can |
---|
96 | investigate the plot content and decide whether you |
---|
97 | need to add items to the context menu. |
---|
98 | |
---|
99 | This method returns a list of menu items. |
---|
100 | Each item is itself a list defining the text to |
---|
101 | appear in the menu, a tool-tip help text, and a |
---|
102 | call-back method. |
---|
103 | |
---|
104 | :param graph: the Graph object to which we attach the context menu |
---|
105 | |
---|
106 | :return: a list of menu items with call-back function |
---|
107 | |
---|
108 | """ |
---|
109 | return [] |
---|
110 | |
---|
111 | def get_perspective(self): |
---|
112 | """ |
---|
113 | Get the list of panel names for this perspective |
---|
114 | """ |
---|
115 | return self.perspective |
---|
116 | |
---|
117 | def on_perspective(self, event): |
---|
118 | """ |
---|
119 | Call back function for the perspective menu item. |
---|
120 | We notify the parent window that the perspective |
---|
121 | has changed. |
---|
122 | |
---|
123 | :param event: menu event |
---|
124 | |
---|
125 | """ |
---|
126 | self.parent.set_perspective(self.perspective) |
---|
127 | |
---|
128 | def post_init(self): |
---|
129 | """ |
---|
130 | Post initialization call back to close the loose ends |
---|
131 | """ |
---|
132 | pass |
---|
133 | |
---|
134 | def set_default_perspective(self): |
---|
135 | """ |
---|
136 | Call back method that True to notify the parent that the current plug-in |
---|
137 | can be set as default perspective. |
---|
138 | when returning False, the plug-in is not candidate for an automatic |
---|
139 | default perspective setting |
---|
140 | """ |
---|
141 | return False |
---|