1 | |
---|
2 | |
---|
3 | ################################################################################ |
---|
4 | #This software was developed by the University of Tennessee as part of the |
---|
5 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
6 | #project funded by the US National Science Foundation. |
---|
7 | # |
---|
8 | #See the license text in license.txt |
---|
9 | # |
---|
10 | #copyright 2008, University of Tennessee |
---|
11 | ################################################################################ |
---|
12 | |
---|
13 | |
---|
14 | from sans.guiframe.events import PanelOnFocusEvent |
---|
15 | from sans.guiframe.events import EVT_NEW_BATCH |
---|
16 | import wx |
---|
17 | |
---|
18 | class PanelBase: |
---|
19 | """ |
---|
20 | Defines the API for a panels to work with |
---|
21 | the ViewerFrame toolbar and menu bar |
---|
22 | """ |
---|
23 | ## Internal nickname for the window, used by the AUI manager |
---|
24 | #window_name = "default" |
---|
25 | ## Name to appear on the window title bar |
---|
26 | #window_caption = "Welcome panel" |
---|
27 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
28 | group_id = None |
---|
29 | uid = None |
---|
30 | |
---|
31 | def __init__(self, parent=None): |
---|
32 | """ |
---|
33 | Initialize some flag that Viewerframe used |
---|
34 | """ |
---|
35 | #panel manager |
---|
36 | self._manager = None |
---|
37 | self.parent = parent |
---|
38 | if self.parent is not None and hasattr(self.parent, '_manager'): |
---|
39 | self._manager = self.parent._manager |
---|
40 | self._print_flag = False |
---|
41 | self._undo_flag = False |
---|
42 | self._redo_flag = False |
---|
43 | self._copy_flag = False |
---|
44 | self._paste_flag = False |
---|
45 | self._preview_flag = False |
---|
46 | self._bookmark_flag = False |
---|
47 | self._zoom_in_flag = False |
---|
48 | self._zoom_out_flag = False |
---|
49 | self._zoom_flag = False |
---|
50 | self._save_flag = False |
---|
51 | self._drag_flag = False |
---|
52 | self._reset_flag = False |
---|
53 | self._has_changed = False |
---|
54 | self.batch_on = False |
---|
55 | self.group_id = None |
---|
56 | self.Bind(EVT_NEW_BATCH, self.on_batch_selection) |
---|
57 | self.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) |
---|
58 | self.Bind(wx.EVT_TEXT_ENTER, self.on_set_focus) |
---|
59 | self.Bind(wx.EVT_MIDDLE_DOWN, self.on_set_focus) |
---|
60 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_set_focus) |
---|
61 | |
---|
62 | def on_batch_selection(self, event): |
---|
63 | """ |
---|
64 | :param event: contains parameter enable . when enable is set to True |
---|
65 | the application is in Batch mode |
---|
66 | else the application is default mode(single mode) |
---|
67 | """ |
---|
68 | self.batch_on = event.enable |
---|
69 | def save_project(self, doc=None): |
---|
70 | """ |
---|
71 | return an xml node containing state of the panel |
---|
72 | that guiframe can write to file |
---|
73 | """ |
---|
74 | return None |
---|
75 | |
---|
76 | def has_changed(self): |
---|
77 | """ |
---|
78 | """ |
---|
79 | return self._has_changed |
---|
80 | |
---|
81 | def _set_print_flag(self, flag=True): |
---|
82 | """ |
---|
83 | The derivative class sets the print flag value to indicate that it can |
---|
84 | be printed |
---|
85 | """ |
---|
86 | if flag == self._print_flag: |
---|
87 | self._has_changed = False |
---|
88 | return |
---|
89 | self._has_changed = True |
---|
90 | self._print_flag = flag |
---|
91 | if self._manager is not None and self._manager.parent is not None: |
---|
92 | self._manager.parent.cpanel_on_focus = self |
---|
93 | self._manager.parent.enable_print() |
---|
94 | |
---|
95 | def get_print_flag(self): |
---|
96 | """ |
---|
97 | Get the print flag to update appropriately the tool bar |
---|
98 | """ |
---|
99 | return self._print_flag |
---|
100 | |
---|
101 | def _set_undo_flag(self, flag=True): |
---|
102 | """ |
---|
103 | The derivative class sets the undo flag value to indicate that the |
---|
104 | current action done can be canceled |
---|
105 | """ |
---|
106 | if flag == self._undo_flag: |
---|
107 | self._has_changed = False |
---|
108 | return |
---|
109 | self._has_changed = True |
---|
110 | self._undo_flag = flag |
---|
111 | if self._manager is not None and self._manager.parent is not None: |
---|
112 | self._manager.parent.cpanel_on_focus = self |
---|
113 | self._manager.parent.enable_undo() |
---|
114 | |
---|
115 | def get_undo_flag(self): |
---|
116 | """ |
---|
117 | Get the undo flag to update appropriately the tool bar |
---|
118 | """ |
---|
119 | return self._undo_flag |
---|
120 | |
---|
121 | def _set_redo_flag(self, flag=True): |
---|
122 | """ |
---|
123 | The derivative class sets the redo flag value to indicate that the |
---|
124 | action done can be recovered |
---|
125 | """ |
---|
126 | if flag == self._redo_flag: |
---|
127 | self._has_changed = False |
---|
128 | return |
---|
129 | self._has_changed = True |
---|
130 | self._redo_flag = flag |
---|
131 | if self._manager is not None and self._manager.parent is not None: |
---|
132 | self._manager.parent.cpanel_on_focus = self |
---|
133 | self._manager.parent.enable_redo() |
---|
134 | |
---|
135 | def get_redo_flag(self): |
---|
136 | """ |
---|
137 | Get the redo flag to update appropriately the tool bar |
---|
138 | """ |
---|
139 | return self._redo_flag |
---|
140 | |
---|
141 | def _set_copy_flag(self, flag=True): |
---|
142 | """ |
---|
143 | The derivative class sets the copy flag value to indicate that the |
---|
144 | action done can be recovered |
---|
145 | """ |
---|
146 | if flag == self._copy_flag: |
---|
147 | self._has_changed = False |
---|
148 | return |
---|
149 | self._has_changed = True |
---|
150 | self._copy_flag = flag |
---|
151 | if self._manager is not None and self._manager.parent is not None: |
---|
152 | self._manager.parent.cpanel_on_focus = self |
---|
153 | self._manager.parent.enable_copy() |
---|
154 | |
---|
155 | def get_copy_flag(self): |
---|
156 | """ |
---|
157 | Get the copy flag to update appropriately the tool bar |
---|
158 | """ |
---|
159 | return self._copy_flag |
---|
160 | |
---|
161 | def _set_paste_flag(self, flag=True): |
---|
162 | """ |
---|
163 | The derivative class sets the paste flag value to indicate that the |
---|
164 | action done can be recovered |
---|
165 | """ |
---|
166 | if flag == self._paste_flag: |
---|
167 | self._has_changed = False |
---|
168 | return |
---|
169 | self._has_changed = True |
---|
170 | self._paste_flag = flag |
---|
171 | if self._manager is not None and self._manager.parent is not None: |
---|
172 | self._manager.parent.cpanel_on_focus = self |
---|
173 | self._manager.parent.enable_paste() |
---|
174 | |
---|
175 | def get_paste_flag(self): |
---|
176 | """ |
---|
177 | Get the copy flag to update appropriately the tool bar |
---|
178 | """ |
---|
179 | return self._copy_flag |
---|
180 | |
---|
181 | def _set_zoomed_in_flag(self, flag=True): |
---|
182 | """ |
---|
183 | The derivative class sets the zoom in flag value to indicate that it |
---|
184 | can be zoomed in |
---|
185 | """ |
---|
186 | if self._zoom_in_flag == flag: |
---|
187 | self._has_changed = False |
---|
188 | return |
---|
189 | self._has_changed = True |
---|
190 | self._zoom_in_flag = flag |
---|
191 | if self._manager is not None and self._manager.parent is not None: |
---|
192 | self._manager.parent.cpanel_on_focus = self |
---|
193 | self._manager.parent.enable_zoom_in() |
---|
194 | |
---|
195 | def get_zoom_in_flag(self): |
---|
196 | """ |
---|
197 | Get the zoom in flag to update appropriately the tool bar |
---|
198 | """ |
---|
199 | return self._zoom_in_flag |
---|
200 | |
---|
201 | def _set_zoomed_out_flag(self, flag=True): |
---|
202 | """ |
---|
203 | The derivative class sets the zoom out flag value to indicate that it |
---|
204 | can be zoomed out |
---|
205 | """ |
---|
206 | if self._zoom_out_flag == flag: |
---|
207 | self._has_changed = False |
---|
208 | return |
---|
209 | self._has_changed = True |
---|
210 | self._zoom_out_flag = flag |
---|
211 | if self._manager is not None and self._manager.parent is not None: |
---|
212 | self._manager.parent.panel_on_focus = self |
---|
213 | self._manager.parent.enable_zoom_out() |
---|
214 | |
---|
215 | def get_zoom_out_flag(self): |
---|
216 | """ |
---|
217 | Get the zoom out flag to update appropriately the tool bar |
---|
218 | """ |
---|
219 | return self._zoom_out_flag |
---|
220 | |
---|
221 | def _set_zoom_flag(self, flag=True): |
---|
222 | """ |
---|
223 | The derivative class sets the zoom flag value to indicate that it |
---|
224 | can be zoomed |
---|
225 | """ |
---|
226 | if flag == self._zoom_flag: |
---|
227 | self._has_changed = False |
---|
228 | return |
---|
229 | self._has_changed = True |
---|
230 | self._zoom_flag = flag |
---|
231 | if self._manager is not None and self._manager.parent is not None: |
---|
232 | self._manager.parent.cpanel_on_focus = self |
---|
233 | self._manager.parent.enable_zoom() |
---|
234 | |
---|
235 | def get_zoom_flag(self): |
---|
236 | """ |
---|
237 | Get the zoom flag to update appropriately the tool bar |
---|
238 | """ |
---|
239 | return self._zoom_flag |
---|
240 | |
---|
241 | def _set_bookmark_flag(self, flag=True): |
---|
242 | """ |
---|
243 | The derivative class sets the bookmark flag value to indicate that it |
---|
244 | can be bookmarked |
---|
245 | """ |
---|
246 | if flag == self._bookmark_flag: |
---|
247 | self._has_changed = False |
---|
248 | return |
---|
249 | self._has_changed = True |
---|
250 | self._bookmark_flag = flag |
---|
251 | if self._manager is not None and self._manager.parent is not None: |
---|
252 | self._manager.parent.cpanel_on_focus = self |
---|
253 | self._manager.parent.enable_bookmark() |
---|
254 | |
---|
255 | def get_bookmark_flag(self): |
---|
256 | """ |
---|
257 | Get the bookmark flag to update appropriately the tool bar |
---|
258 | """ |
---|
259 | return self._bookmark_flag |
---|
260 | |
---|
261 | def _set_preview_flag(self, flag=True): |
---|
262 | """ |
---|
263 | The derivative class sets the preview flag value to indicate that it |
---|
264 | can be previewed |
---|
265 | """ |
---|
266 | if flag == self._preview_flag: |
---|
267 | self._has_changed = False |
---|
268 | return |
---|
269 | self._has_changed = True |
---|
270 | self._preview_flag = flag |
---|
271 | if self._manager is not None and self._manager.parent is not None: |
---|
272 | self._manager.parent.cpanel_on_focus = self |
---|
273 | self._manager.parent.enable_preview() |
---|
274 | |
---|
275 | def get_preview_flag(self): |
---|
276 | """ |
---|
277 | Get the preview flag to update appropriately the tool bar |
---|
278 | """ |
---|
279 | return self._preview_flag |
---|
280 | |
---|
281 | def _set_save_flag(self, flag=True): |
---|
282 | """ |
---|
283 | The derivative class sets the drag flag value to indicate that it |
---|
284 | can be saved |
---|
285 | """ |
---|
286 | if flag == self._save_flag: |
---|
287 | self._has_changed = False |
---|
288 | return |
---|
289 | self._has_changed = True |
---|
290 | self._save_flag = flag |
---|
291 | if self._manager is not None and self._manager.parent is not None: |
---|
292 | self._manager.parent.cpanel_on_focus = self |
---|
293 | self._manager.parent.enable_save() |
---|
294 | |
---|
295 | def get_save_flag(self): |
---|
296 | """ |
---|
297 | Get the save flag to update appropriately the tool bar |
---|
298 | """ |
---|
299 | return self._save_flag |
---|
300 | |
---|
301 | def _set_drag_flag(self, flag=True): |
---|
302 | """ |
---|
303 | The derivative class sets the drag flag value to indicate that |
---|
304 | dragging motion is possible |
---|
305 | """ |
---|
306 | if self._drag_flag == flag: |
---|
307 | self._has_changed = False |
---|
308 | return |
---|
309 | self._has_changed = True |
---|
310 | self._drag_flag = flag |
---|
311 | if self._manager is not None and self._manager.parent is not None: |
---|
312 | self._manager.parent.cpanel_on_focus = self |
---|
313 | self._manager.parent.enable_drag() |
---|
314 | |
---|
315 | def get_drag_flag(self): |
---|
316 | """ |
---|
317 | Get the drag flag to update appropriately the tool bar |
---|
318 | """ |
---|
319 | return self._drag_flag |
---|
320 | |
---|
321 | def _set_reset_flag(self, flag=True): |
---|
322 | """ |
---|
323 | The derivative class sets the reset flag value to indicate that it |
---|
324 | can be reset |
---|
325 | """ |
---|
326 | if self._reset_flag == flag: |
---|
327 | self._has_changed = False |
---|
328 | return |
---|
329 | self._has_changed = True |
---|
330 | self._reset_flag = flag |
---|
331 | if self._manager is not None and self._manager.parent is not None: |
---|
332 | self._manager.parent.cpanel_on_focus = self |
---|
333 | self._manager.parent.enable_reset() |
---|
334 | |
---|
335 | def get_reset_flag(self): |
---|
336 | """ |
---|
337 | Get the reset flag to update appropriately the tool bar |
---|
338 | """ |
---|
339 | return self._reset_flag |
---|
340 | |
---|
341 | def on_reset(self, event): |
---|
342 | """ |
---|
343 | The derivative class state is restored |
---|
344 | """ |
---|
345 | def on_drag(self, event): |
---|
346 | """ |
---|
347 | The derivative class allows dragging motion if implemented |
---|
348 | """ |
---|
349 | def on_preview(self, event): |
---|
350 | """ |
---|
351 | Display a printable version of the class derivative |
---|
352 | """ |
---|
353 | def on_save(self, event): |
---|
354 | """ |
---|
355 | The state of the derivative class is restored |
---|
356 | """ |
---|
357 | def on_redo(self, event): |
---|
358 | """ |
---|
359 | The previous action is restored if possible |
---|
360 | """ |
---|
361 | def on_undo(self, event): |
---|
362 | """ |
---|
363 | The current action is canceled |
---|
364 | """ |
---|
365 | def on_copy(self, event): |
---|
366 | """ |
---|
367 | The copy action if possible |
---|
368 | """ |
---|
369 | def on_paste(self, event): |
---|
370 | """ |
---|
371 | The paste action if possible |
---|
372 | """ |
---|
373 | def on_bookmark(self, event): |
---|
374 | """ |
---|
375 | The derivative class is on bookmark mode if implemented |
---|
376 | """ |
---|
377 | def on_zoom_in(self, event): |
---|
378 | """ |
---|
379 | The derivative class is on zoom in mode if implemented |
---|
380 | """ |
---|
381 | def on_zoom_out(self, event): |
---|
382 | """ |
---|
383 | The derivative class is on zoom out mode if implemented |
---|
384 | """ |
---|
385 | def on_zoom(self, event): |
---|
386 | """ |
---|
387 | The derivative class is on zoom mode (using pane) |
---|
388 | if zoom mode is implemented |
---|
389 | """ |
---|
390 | def on_set_focus(self, event=None): |
---|
391 | """ |
---|
392 | The derivative class is on focus if implemented |
---|
393 | """ |
---|
394 | if self.parent is not None: |
---|
395 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
396 | |
---|
397 | def on_kill_focus(self, event=None): |
---|
398 | """ |
---|
399 | The derivative class is on unfocus if implemented |
---|
400 | """ |
---|
401 | pass |
---|
402 | |
---|
403 | def get_data(self): |
---|
404 | """ |
---|
405 | return list of current data |
---|
406 | """ |
---|
407 | return |
---|
408 | |
---|
409 | def get_state(self): |
---|
410 | """ |
---|
411 | return the current state |
---|
412 | """ |
---|
413 | return |
---|
414 | |
---|
415 | def set_manager(self, manager): |
---|
416 | """ |
---|
417 | """ |
---|
418 | self._manager = manager |
---|
419 | |
---|
420 | def get_manager(self): |
---|
421 | """ |
---|
422 | """ |
---|
423 | return self._manager |
---|