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 | |
---|
29 | def __init__(self, parent=None): |
---|
30 | """ |
---|
31 | Initialize some flag that Viewerframe used |
---|
32 | """ |
---|
33 | #panel manager |
---|
34 | self._manager = None |
---|
35 | self.parent = parent |
---|
36 | self._print_flag = False |
---|
37 | self._undo_flag = False |
---|
38 | self._redo_flag = False |
---|
39 | self._preview_flag = False |
---|
40 | self._bookmark_flag = False |
---|
41 | self._zoom_in_flag = False |
---|
42 | self._zoom_out_flag = False |
---|
43 | self._zoom_flag = False |
---|
44 | self._save_flag = False |
---|
45 | self._drag_flag = False |
---|
46 | self._reset_flag = False |
---|
47 | self._has_changed = False |
---|
48 | self.group_id = None |
---|
49 | |
---|
50 | self.Bind(wx.EVT_LEFT_DOWN, self.on_set_focus) |
---|
51 | self.Bind(wx.EVT_TEXT_ENTER, self.on_set_focus) |
---|
52 | self.Bind(wx.EVT_MIDDLE_DOWN, self.on_set_focus) |
---|
53 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_set_focus) |
---|
54 | |
---|
55 | def has_changed(self): |
---|
56 | """ |
---|
57 | """ |
---|
58 | return self._has_changed |
---|
59 | |
---|
60 | def _set_print_flag(self, flag=True): |
---|
61 | """ |
---|
62 | The derivative class sets the print flag value to indicate that it can |
---|
63 | be printed |
---|
64 | """ |
---|
65 | if flag == self._print_flag: |
---|
66 | self._has_changed = False |
---|
67 | return |
---|
68 | self._has_changed = True |
---|
69 | self._print_flag = flag |
---|
70 | if self._manager is not None and self._manager.parent is not None: |
---|
71 | self._manager.parent.enable_print() |
---|
72 | |
---|
73 | def get_print_flag(self): |
---|
74 | """ |
---|
75 | Get the print flag to update appropriately the tool bar |
---|
76 | """ |
---|
77 | return self._print_flag |
---|
78 | |
---|
79 | def _set_undo_flag(self, flag=True): |
---|
80 | """ |
---|
81 | The derivative class sets the undo flag value to indicate that the |
---|
82 | current action done can be canceled |
---|
83 | """ |
---|
84 | if flag == self._undo_flag: |
---|
85 | self._has_changed = False |
---|
86 | return |
---|
87 | self._has_changed = True |
---|
88 | self._undo_flag = flag |
---|
89 | if self._manager is not None and self._manager.parent is not None: |
---|
90 | self._manager.parent.enable_undo() |
---|
91 | |
---|
92 | def get_undo_flag(self): |
---|
93 | """ |
---|
94 | Get the undo flag to update appropriately the tool bar |
---|
95 | """ |
---|
96 | return self._undo_flag |
---|
97 | |
---|
98 | def _set_redo_flag(self, flag=True): |
---|
99 | """ |
---|
100 | The derivative class sets the redo flag value to indicate that the |
---|
101 | action done can be recovered |
---|
102 | """ |
---|
103 | if flag == self._redo_flag: |
---|
104 | self._has_changed = False |
---|
105 | return |
---|
106 | self._has_changed = True |
---|
107 | self._redo_flag = flag |
---|
108 | if self._manager is not None and self._manager.parent is not None: |
---|
109 | self._manager.parent.enable_redo() |
---|
110 | |
---|
111 | def get_redo_flag(self): |
---|
112 | """ |
---|
113 | Get the redo flag to update appropriately the tool bar |
---|
114 | """ |
---|
115 | return self._redo_flag |
---|
116 | |
---|
117 | def _set_zoomed_in_flag(self, flag=True): |
---|
118 | """ |
---|
119 | The derivative class sets the zoom in flag value to indicate that it |
---|
120 | can be zoomed in |
---|
121 | """ |
---|
122 | if self._zoom_in_flag == flag: |
---|
123 | self._has_changed = False |
---|
124 | return |
---|
125 | self._has_changed = True |
---|
126 | self._zoom_in_flag = flag |
---|
127 | if self._manager is not None and self._manager.parent is not None: |
---|
128 | self._manager.parent.enable_zoom_in() |
---|
129 | |
---|
130 | def get_zoom_in_flag(self): |
---|
131 | """ |
---|
132 | Get the zoom in flag to update appropriately the tool bar |
---|
133 | """ |
---|
134 | return self._zoom_in_flag |
---|
135 | |
---|
136 | def _set_zoomed_out_flag(self, flag=True): |
---|
137 | """ |
---|
138 | The derivative class sets the zoom out flag value to indicate that it |
---|
139 | can be zoomed out |
---|
140 | """ |
---|
141 | if self._zoom_out_flag == flag: |
---|
142 | self._has_changed = False |
---|
143 | return |
---|
144 | self._has_changed = True |
---|
145 | self._zoom_out_flag = flag |
---|
146 | if self._manager is not None and self._manager.parent is not None: |
---|
147 | self._manager.parent.enable_zoom_out() |
---|
148 | |
---|
149 | def get_zoom_out_flag(self): |
---|
150 | """ |
---|
151 | Get the zoom out flag to update appropriately the tool bar |
---|
152 | """ |
---|
153 | return self._zoom_out_flag |
---|
154 | |
---|
155 | def _set_zoom_flag(self, flag=True): |
---|
156 | """ |
---|
157 | The derivative class sets the zoom flag value to indicate that it |
---|
158 | can be zoomed |
---|
159 | """ |
---|
160 | if flag == self._zoom_flag: |
---|
161 | self._has_changed = False |
---|
162 | return |
---|
163 | self._has_changed = True |
---|
164 | self._zoom_flag = flag |
---|
165 | if self._manager is not None and self._manager.parent is not None: |
---|
166 | self._manager.parent.enable_zoom() |
---|
167 | |
---|
168 | def get_zoom_flag(self): |
---|
169 | """ |
---|
170 | Get the zoom flag to update appropriately the tool bar |
---|
171 | """ |
---|
172 | return self._zoom_flag |
---|
173 | |
---|
174 | def _set_bookmark_flag(self, flag=True): |
---|
175 | """ |
---|
176 | The derivative class sets the bookmark flag value to indicate that it |
---|
177 | can be bookmarked |
---|
178 | """ |
---|
179 | if flag == self._bookmark_flag: |
---|
180 | self._has_changed = False |
---|
181 | return |
---|
182 | self._has_changed = True |
---|
183 | self._bookmark_flag = flag |
---|
184 | if self._manager is not None and self._manager.parent is not None: |
---|
185 | self._manager.parent.enable_bookmark() |
---|
186 | |
---|
187 | def get_bookmark_flag(self): |
---|
188 | """ |
---|
189 | Get the bookmark flag to update appropriately the tool bar |
---|
190 | """ |
---|
191 | return self._bookmark_flag |
---|
192 | |
---|
193 | def _set_preview_flag(self, flag=True): |
---|
194 | """ |
---|
195 | The derivative class sets the preview flag value to indicate that it |
---|
196 | can be previewed |
---|
197 | """ |
---|
198 | if flag == self._preview_flag: |
---|
199 | self._has_changed = False |
---|
200 | return |
---|
201 | self._has_changed = True |
---|
202 | self._preview_flag = flag |
---|
203 | if self._manager is not None and self._manager.parent is not None: |
---|
204 | self._manager.parent.enable_preview() |
---|
205 | |
---|
206 | def get_preview_flag(self): |
---|
207 | """ |
---|
208 | Get the preview flag to update appropriately the tool bar |
---|
209 | """ |
---|
210 | return self._preview_flag |
---|
211 | |
---|
212 | def _set_save_flag(self, flag=True): |
---|
213 | """ |
---|
214 | The derivative class sets the drag flag value to indicate that it |
---|
215 | can be saved |
---|
216 | """ |
---|
217 | if flag == self._save_flag: |
---|
218 | self._has_changed = False |
---|
219 | return |
---|
220 | self._has_changed = True |
---|
221 | self._save_flag = flag |
---|
222 | if self._manager is not None and self._manager.parent is not None: |
---|
223 | self._manager.parent.enable_save() |
---|
224 | |
---|
225 | def get_save_flag(self): |
---|
226 | """ |
---|
227 | Get the save flag to update appropriately the tool bar |
---|
228 | """ |
---|
229 | return self._save_flag |
---|
230 | |
---|
231 | def _set_drag_flag(self, flag=True): |
---|
232 | """ |
---|
233 | The derivative class sets the drag flag value to indicate that |
---|
234 | dragging motion is possible |
---|
235 | """ |
---|
236 | if self._drag_flag == flag: |
---|
237 | self._has_changed = False |
---|
238 | return |
---|
239 | self._has_changed = True |
---|
240 | self._drag_flag = flag |
---|
241 | if self._manager is not None and self._manager.parent is not None: |
---|
242 | self._manager.parent.enable_drag() |
---|
243 | |
---|
244 | def get_drag_flag(self): |
---|
245 | """ |
---|
246 | Get the drag flag to update appropriately the tool bar |
---|
247 | """ |
---|
248 | return self._drag_flag |
---|
249 | |
---|
250 | def _set_reset_flag(self, flag=True): |
---|
251 | """ |
---|
252 | The derivative class sets the reset flag value to indicate that it |
---|
253 | can be reset |
---|
254 | """ |
---|
255 | if self._reset_flag == flag: |
---|
256 | self._has_changed = False |
---|
257 | return |
---|
258 | self._has_changed = True |
---|
259 | self._reset_flag = flag |
---|
260 | if self._manager is not None and self._manager.parent is not None: |
---|
261 | self._manager.parent.enable_reset() |
---|
262 | |
---|
263 | def get_reset_flag(self): |
---|
264 | """ |
---|
265 | Get the reset flag to update appropriately the tool bar |
---|
266 | """ |
---|
267 | return self._reset_flag |
---|
268 | |
---|
269 | def on_reset(self, event): |
---|
270 | """ |
---|
271 | The derivative class state is restored |
---|
272 | """ |
---|
273 | def on_drag(self, event): |
---|
274 | """ |
---|
275 | The derivative class allows dragging motion if implemented |
---|
276 | """ |
---|
277 | def on_preview(self, event): |
---|
278 | """ |
---|
279 | Display a printable version of the class derivative |
---|
280 | """ |
---|
281 | def on_save(self, event): |
---|
282 | """ |
---|
283 | The state of the derivative class is restored |
---|
284 | """ |
---|
285 | def on_redo(self, event): |
---|
286 | """ |
---|
287 | The previous action is restored if possible |
---|
288 | """ |
---|
289 | def on_undo(self, event): |
---|
290 | """ |
---|
291 | The current action is canceled |
---|
292 | """ |
---|
293 | def on_bookmark(self, event): |
---|
294 | """ |
---|
295 | The derivative class is on bookmark mode if implemented |
---|
296 | """ |
---|
297 | def on_zoom_in(self, event): |
---|
298 | """ |
---|
299 | The derivative class is on zoom in mode if implemented |
---|
300 | """ |
---|
301 | def on_zoom_out(self, event): |
---|
302 | """ |
---|
303 | The derivative class is on zoom out mode if implemented |
---|
304 | """ |
---|
305 | def on_zoom(self, event): |
---|
306 | """ |
---|
307 | The derivative class is on zoom mode (using pane) |
---|
308 | if zoom mode is implemented |
---|
309 | """ |
---|
310 | def on_set_focus(self, event=None): |
---|
311 | """ |
---|
312 | The derivative class is on focus if implemented |
---|
313 | """ |
---|
314 | if self.parent is not None: |
---|
315 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
316 | |
---|
317 | def get_data(self): |
---|
318 | """ |
---|
319 | return list of current data |
---|
320 | """ |
---|
321 | return |
---|
322 | |
---|
323 | def get_state(self): |
---|
324 | """ |
---|
325 | return the current state |
---|
326 | """ |
---|
327 | return |
---|
328 | |
---|
329 | def set_manager(self, manager): |
---|
330 | """ |
---|
331 | """ |
---|
332 | self._manager = manager |
---|
333 | |
---|
334 | def get_manager(self): |
---|
335 | """ |
---|
336 | """ |
---|
337 | return self._manager |
---|