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