1 | """ |
---|
2 | Defines the interface for a Plugin class that can be used by the gui_manager. |
---|
3 | """ |
---|
4 | |
---|
5 | ################################################################################ |
---|
6 | #This software was developed by the University of Tennessee as part of the |
---|
7 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
8 | #project funded by the US National Science Foundation. |
---|
9 | # |
---|
10 | #See the license text in license.txt |
---|
11 | # |
---|
12 | #copyright 2008, University of Tennessee |
---|
13 | ################################################################################ |
---|
14 | |
---|
15 | class PluginBase(object): |
---|
16 | """ |
---|
17 | This class defines the interface for a Plugin class |
---|
18 | that can be used by the gui_manager. |
---|
19 | |
---|
20 | Plug-ins should be placed in a sub-directory called "perspectives". |
---|
21 | For example, a plug-in called Foo should be place in "perspectives/Foo". |
---|
22 | That directory contains at least two files: |
---|
23 | |
---|
24 | 1. perspectives/Foo/__init__.py contains two lines: :: |
---|
25 | |
---|
26 | PLUGIN_ID = "Foo plug-in 1.0" |
---|
27 | from Foo import * |
---|
28 | |
---|
29 | 2. perspectives/Foo/Foo.py contains the definition of the Plugin |
---|
30 | class for the Foo plug-in. The interface of that Plugin class |
---|
31 | should follow the interface of the class you are looking at. |
---|
32 | |
---|
33 | See dummyapp.py for a plugin example. |
---|
34 | """ |
---|
35 | |
---|
36 | def __init__(self, name="Test_plugin"): |
---|
37 | """ |
---|
38 | Abstract class for gui_manager Plugins. |
---|
39 | """ |
---|
40 | # Define if the plugin is local to Viewerframe and always active |
---|
41 | self._always_active = False |
---|
42 | ## Plug-in name. It will appear on the application menu. |
---|
43 | self.sub_menu = name |
---|
44 | ## Reference to the parent window. Filled by get_panels() below. |
---|
45 | self.parent = None |
---|
46 | self.frame = None |
---|
47 | #plugin state reader |
---|
48 | self.state_reader = None |
---|
49 | self._extensions = '' |
---|
50 | ## List of panels that you would like to open in AUI windows |
---|
51 | # for your plug-in. This defines your plug-in "perspective" |
---|
52 | self.perspective = [] |
---|
53 | #flag to tell the current plugin that aaplication is in batch mode |
---|
54 | self.batch_on = False |
---|
55 | #properties for color and ID of a specific plugin.. |
---|
56 | self.color = None |
---|
57 | self.id = -1 |
---|
58 | self.batch_capable = self.get_batch_capable() |
---|
59 | |
---|
60 | def get_batch_capable(self): |
---|
61 | """ |
---|
62 | Check if the plugin has a batch capability |
---|
63 | """ |
---|
64 | return False |
---|
65 | |
---|
66 | def add_color(self, color, id): |
---|
67 | """ |
---|
68 | Adds color to a plugin |
---|
69 | """ |
---|
70 | |
---|
71 | def clear_panel(self): |
---|
72 | """ |
---|
73 | clear all related panels |
---|
74 | """ |
---|
75 | |
---|
76 | def get_extensions(self): |
---|
77 | """ |
---|
78 | return state reader and its extensions |
---|
79 | """ |
---|
80 | return self.state_reader, self._extensions |
---|
81 | |
---|
82 | def can_load_data(self): |
---|
83 | """ |
---|
84 | if return True, then call handler to load data |
---|
85 | """ |
---|
86 | return False |
---|
87 | |
---|
88 | def use_data(self): |
---|
89 | """ |
---|
90 | return True if these plugin use data |
---|
91 | """ |
---|
92 | return True |
---|
93 | |
---|
94 | def is_in_use(self, data_id): |
---|
95 | """ |
---|
96 | get a data id a list of data name if data data is |
---|
97 | currently used by the plugin and the name of the plugin |
---|
98 | |
---|
99 | data_name = 'None' |
---|
100 | in_use = False |
---|
101 | example [(data_name, self.sub_menu)] |
---|
102 | """ |
---|
103 | return [] |
---|
104 | |
---|
105 | def delete_data(self, data_id): |
---|
106 | """ |
---|
107 | Delete all references of data which id are in data_list. |
---|
108 | """ |
---|
109 | |
---|
110 | def load_data(self, event): |
---|
111 | """ |
---|
112 | Load data |
---|
113 | """ |
---|
114 | raise NotImplementedError |
---|
115 | |
---|
116 | def load_folder(self, event): |
---|
117 | """ |
---|
118 | Load entire folder |
---|
119 | """ |
---|
120 | raise NotImplementedError |
---|
121 | |
---|
122 | def set_is_active(self, active=False): |
---|
123 | """ |
---|
124 | Set if the perspective is always active |
---|
125 | """ |
---|
126 | self._always_active = active |
---|
127 | |
---|
128 | def is_always_active(self): |
---|
129 | """ |
---|
130 | return True is this plugin is always active and it is local to guiframe |
---|
131 | even if the user is switching between perspectives |
---|
132 | """ |
---|
133 | return self._always_active |
---|
134 | |
---|
135 | def populate_file_menu(self): |
---|
136 | """ |
---|
137 | Append menu item under file menu item of the frame |
---|
138 | """ |
---|
139 | return [] |
---|
140 | |
---|
141 | def populate_menu(self, parent): |
---|
142 | """ |
---|
143 | Create and return the list of application menu |
---|
144 | items for the plug-in. |
---|
145 | |
---|
146 | :param parent: parent window |
---|
147 | |
---|
148 | :return: plug-in menu |
---|
149 | |
---|
150 | """ |
---|
151 | return [] |
---|
152 | |
---|
153 | def get_frame(self): |
---|
154 | """ |
---|
155 | Returns MDIChildFrame |
---|
156 | """ |
---|
157 | return self.frame |
---|
158 | |
---|
159 | def _frame_set_helper(self): |
---|
160 | """ |
---|
161 | Sets default frame config |
---|
162 | """ |
---|
163 | if self.frame is not None: |
---|
164 | self.frame.EnableCloseButton(False) |
---|
165 | self.frame.Show(False) |
---|
166 | |
---|
167 | def get_panels(self, parent): |
---|
168 | """ |
---|
169 | Create and return the list of wx.Panels for your plug-in. |
---|
170 | Define the plug-in perspective. |
---|
171 | |
---|
172 | Panels should inherit from DefaultPanel defined below, |
---|
173 | or should present the same interface. They must define |
---|
174 | "window_caption" and "window_name". |
---|
175 | |
---|
176 | :param parent: parent window |
---|
177 | |
---|
178 | :return: list of panels |
---|
179 | |
---|
180 | """ |
---|
181 | ## Save a reference to the parent |
---|
182 | self.parent = parent |
---|
183 | |
---|
184 | # Return the list of panels |
---|
185 | return [] |
---|
186 | |
---|
187 | def get_tools(self): |
---|
188 | """ |
---|
189 | Returns a set of menu entries for tools |
---|
190 | """ |
---|
191 | return [] |
---|
192 | |
---|
193 | def get_context_menu(self, plotpanel=None): |
---|
194 | """ |
---|
195 | This method is optional. |
---|
196 | |
---|
197 | When the context menu of a plot is rendered, the |
---|
198 | get_context_menu method will be called to give you a |
---|
199 | chance to add a menu item to the context menu. |
---|
200 | |
---|
201 | A ref to a plotpanel object is passed so that you can |
---|
202 | investigate the plot content and decide whether you |
---|
203 | need to add items to the context menu. |
---|
204 | |
---|
205 | This method returns a list of menu items. |
---|
206 | Each item is itself a list defining the text to |
---|
207 | appear in the menu, a tool-tip help text, and a |
---|
208 | call-back method. |
---|
209 | |
---|
210 | :param graph: the Graph object to which we attach the context menu |
---|
211 | |
---|
212 | :return: a list of menu items with call-back function |
---|
213 | """ |
---|
214 | return [] |
---|
215 | |
---|
216 | def get_perspective(self): |
---|
217 | """ |
---|
218 | Get the list of panel names for this perspective |
---|
219 | """ |
---|
220 | return self.perspective |
---|
221 | |
---|
222 | def on_perspective(self, event=None): |
---|
223 | """ |
---|
224 | Call back function for the perspective menu item. |
---|
225 | We notify the parent window that the perspective |
---|
226 | has changed. |
---|
227 | |
---|
228 | :param event: menu event |
---|
229 | """ |
---|
230 | old_frame = None |
---|
231 | old_persp = self.parent.get_current_perspective() |
---|
232 | if old_persp is not None: |
---|
233 | old_frame = old_persp.get_frame() |
---|
234 | self.parent.check_multimode(self) |
---|
235 | self.parent.set_current_perspective(self) |
---|
236 | self.parent.set_perspective(self.perspective) |
---|
237 | |
---|
238 | if self.frame is not None: |
---|
239 | if old_frame is not None: |
---|
240 | pos_x, pos_y = old_frame.GetPositionTuple() |
---|
241 | self.frame.SetPosition((pos_x, pos_y)) |
---|
242 | if not self.frame.IsShown(): |
---|
243 | self.frame.Show(True) |
---|
244 | |
---|
245 | def set_batch_selection(self, flag): |
---|
246 | """ |
---|
247 | the plugin to its batch state if flag is True |
---|
248 | """ |
---|
249 | self.batch_on = flag |
---|
250 | self.on_batch_selection(self.batch_on) |
---|
251 | |
---|
252 | def on_batch_selection(self, flag): |
---|
253 | """ |
---|
254 | need to be overwritten by the derivated class |
---|
255 | """ |
---|
256 | |
---|
257 | def post_init(self): |
---|
258 | """ |
---|
259 | Post initialization call back to close the loose ends |
---|
260 | """ |
---|
261 | pass |
---|
262 | |
---|
263 | def set_state(self, state=None, datainfo=None): |
---|
264 | """ |
---|
265 | update state |
---|
266 | """ |
---|
267 | |
---|
268 | def set_data(self, data_list=None): |
---|
269 | """ |
---|
270 | receive a list of data and use it in the current perspective |
---|
271 | """ |
---|
272 | |
---|
273 | def set_theory(self, theory_list=None): |
---|
274 | """ |
---|
275 | :param theory_list: list of information |
---|
276 | related to available theory state |
---|
277 | """ |
---|
278 | msg = "%s plugin: does not support import theory" % str(self.sub_menu) |
---|
279 | raise ValueError, msg |
---|
280 | |
---|
281 | def on_set_state_helper(self, event): |
---|
282 | """ |
---|
283 | update state |
---|
284 | """ |
---|
285 | |
---|