source: sasview/src/sas/sasgui/guiframe/panel_base.py @ 65e61c1

Last change on this file since 65e61c1 was 18b7ecb9, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Save Analysis improvements. Fixed #629

  • Property mode set to 100644
File size: 14.4 KB
Line 
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
14from sas.sasgui.guiframe.events import PanelOnFocusEvent
15from sas.sasgui.guiframe.events import EVT_NEW_BATCH
16import wx
17
18class 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        if self.parent is not None and hasattr(self.parent, "batch_on"):
56            self.batch_on = self.parent.batch_on
57       
58        self.group_id = None
59        self.help_string = ''
60
61    def on_batch_selection(self, event):
62        """
63        :param event: contains parameter enable. When enable is set to True
64            the application is in Batch mode otherwise the application is
65            in Single mode.
66        """
67        self.batch_on = event.enable
68    def save_project(self, doc=None):
69        """
70        return an xml node containing state of the panel
71        that guiframe can write to file
72        """
73        return None
74   
75    def has_changed(self):
76        """
77        """
78        return self._has_changed
79           
80    def _set_print_flag(self, flag=True):
81        """
82        The derivative class sets the print flag value to indicate that it can
83        be printed
84        """
85        if flag == self._print_flag:
86            self._has_changed = False
87            return
88        self._has_changed = True
89        self._print_flag = flag
90        if self._manager is not None and self._manager.parent is not None:
91            self._manager.parent.cpanel_on_focus = self
92            self._manager.parent.enable_print()
93     
94    def get_print_flag(self):
95        """
96        Get the print flag to update appropriately the tool bar
97        """
98        return self._print_flag
99   
100    def _set_undo_flag(self, flag=True):
101        """
102        The derivative class sets the undo flag value to indicate that the
103        current action done can be canceled
104        """
105        if flag == self._undo_flag:
106            self._has_changed = False
107            return
108        self._has_changed = True
109        self._undo_flag = flag
110        if self._manager is not None and self._manager.parent is not None:
111            self._manager.parent.cpanel_on_focus = self
112            self._manager.parent.enable_undo()
113     
114    def get_undo_flag(self):
115        """
116        Get the undo flag to update appropriately the tool bar
117        """
118        return self._undo_flag
119   
120    def _set_redo_flag(self, flag=True):
121        """
122        The derivative class sets the redo flag value to indicate that the
123        action done can be recovered
124        """
125        if flag == self._redo_flag:
126            self._has_changed = False
127            return
128        self._has_changed = True
129        self._redo_flag = flag
130        if self._manager is not None and self._manager.parent is not None:
131            self._manager.parent.cpanel_on_focus = self
132            self._manager.parent.enable_redo()
133     
134    def get_redo_flag(self):
135        """
136        Get the redo flag to update appropriately the tool bar
137        """
138        return self._redo_flag
139
140    def _set_copy_flag(self, flag=True):
141        """
142        The derivative class sets the copy flag value to indicate that the
143        action done can be recovered
144        """
145        if flag == self._copy_flag:
146            self._has_changed = False
147            return
148        self._has_changed = True
149        self._copy_flag = flag
150        if self._manager is not None and self._manager.parent is not None:
151            self._manager.parent.cpanel_on_focus = self
152            self._manager.parent.enable_copy()
153     
154    def get_copy_flag(self):
155        """
156        Get the copy flag to update appropriately the tool bar
157        """
158        return self._copy_flag
159   
160    def _set_paste_flag(self, flag=True):
161        """
162        The derivative class sets the paste flag value to indicate that the
163        action done can be recovered
164        """
165        if flag == self._paste_flag:
166            self._has_changed = False
167            return
168        self._has_changed = True
169        self._paste_flag = flag
170        if self._manager is not None and self._manager.parent is not None:
171            self._manager.parent.cpanel_on_focus = self
172            self._manager.parent.enable_paste()
173     
174    def get_paste_flag(self):
175        """
176        Get the copy flag to update appropriately the tool bar
177        """
178        return self._copy_flag
179       
180    def _set_zoomed_in_flag(self, flag=True):
181        """
182        The derivative class sets the zoom in flag value to indicate that it
183        can be zoomed in
184        """
185        if self._zoom_in_flag == flag:
186            self._has_changed = False
187            return
188        self._has_changed = True
189        self._zoom_in_flag = flag
190        if self._manager is not None and self._manager.parent is not None:
191            self._manager.parent.cpanel_on_focus = self
192            self._manager.parent.enable_zoom_in()
193       
194    def get_zoom_in_flag(self):
195        """
196        Get the zoom in flag to update appropriately the tool bar
197        """
198        return self._zoom_in_flag
199   
200    def _set_zoomed_out_flag(self, flag=True):
201        """
202        The derivative class sets the zoom out flag value to indicate that it
203        can be zoomed out
204        """
205        if self._zoom_out_flag == flag:
206            self._has_changed = False
207            return
208        self._has_changed = True
209        self._zoom_out_flag = flag
210        if self._manager is not None and self._manager.parent is not None:
211            self._manager.parent.panel_on_focus = self
212            self._manager.parent.enable_zoom_out()
213       
214    def get_zoom_out_flag(self):
215        """
216        Get the zoom out flag to update appropriately the tool bar
217        """
218        return self._zoom_out_flag
219   
220    def _set_zoom_flag(self, flag=True):
221        """
222        The derivative class sets the zoom flag value to indicate that it
223        can be zoomed
224        """
225        if flag == self._zoom_flag:
226            self._has_changed = False
227            return
228        self._has_changed = True
229        self._zoom_flag = flag
230        if self._manager is not None and self._manager.parent is not None:
231            self._manager.parent.cpanel_on_focus = self
232            self._manager.parent.enable_zoom()
233     
234    def get_zoom_flag(self):
235        """
236        Get the zoom flag to update appropriately the tool bar
237        """
238        return self._zoom_flag
239   
240    def _set_bookmark_flag(self, flag=True):
241        """
242        The derivative class sets the bookmark flag value to indicate that it
243        can be bookmarked
244        """
245        if flag == self._bookmark_flag:
246            self._has_changed = False
247            return
248        self._has_changed = True
249        self._bookmark_flag = flag
250        if self._manager is not None and self._manager.parent is not None:
251            self._manager.parent.cpanel_on_focus = self
252            self._manager.parent.enable_bookmark()
253       
254    def get_bookmark_flag(self):
255        """
256        Get the bookmark flag to update appropriately the tool bar
257        """
258        return self._bookmark_flag
259   
260    def _set_preview_flag(self, flag=True):
261        """
262        The derivative class sets the preview flag value to indicate that it
263        can be previewed
264        """
265        if flag == self._preview_flag:
266            self._has_changed = False
267            return
268        self._has_changed = True
269        self._preview_flag = flag
270        if self._manager is not None and self._manager.parent is not None:
271            self._manager.parent.cpanel_on_focus = self
272            self._manager.parent.enable_preview()
273       
274    def get_preview_flag(self):
275        """
276        Get the preview flag to update appropriately the tool bar
277        """
278        return self._preview_flag
279   
280    def _set_save_flag(self, flag=True):
281        """
282        The derivative class sets the drag flag value to indicate that it
283        can be saved
284        """
285        if flag == self._save_flag:
286            self._has_changed = False
287            return
288        self._has_changed = True
289        self._save_flag = flag
290        if self._manager is not None and self._manager.parent is not None:
291            self._manager.parent.cpanel_on_focus = self
292            self._manager.parent.enable_save()
293
294    def get_save_flag(self):
295        """
296        Get the save flag to update appropriately the tool bar
297        """
298        return self._save_flag
299   
300    def _set_drag_flag(self, flag=True):
301        """
302        The derivative class sets the drag flag value to indicate that
303        dragging motion is possible
304        """
305        if self._drag_flag == flag:
306            self._has_changed = False
307            return
308        self._has_changed = True
309        self._drag_flag = flag
310        if self._manager is not None and self._manager.parent is not None:
311            self._manager.parent.cpanel_on_focus = self
312            self._manager.parent.enable_drag()
313       
314    def get_drag_flag(self):
315        """
316        Get the drag flag to update appropriately the tool bar
317        """
318        return self._drag_flag
319
320    def _set_analysis(self, flag):
321        """
322        Set the Analysis Save state flag and informs the manager
323        so it refreshes the menu/whole panel
324        """
325        self._set_save_flag(flag)
326        if self._manager is not None:
327            wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self))
328
329    def _set_reset_flag(self, flag=True):
330        """
331        The derivative class sets the reset flag value to indicate that it
332        can be reset
333        """
334        if self._reset_flag == flag:
335            self._has_changed = False
336            return
337        self._has_changed = True
338        self._reset_flag = flag
339        if self._manager is not None and self._manager.parent is not None:
340            self._manager.parent.cpanel_on_focus = self
341            self._manager.parent.enable_reset()
342           
343    def on_tap_focus(self):
344        """
345        Update menu on clicking the panel tap
346        """
347        #Implemented only on fitting note book
348        pass
349     
350    def get_reset_flag(self):
351        """
352        Get the reset flag to update appropriately the tool bar
353        """
354        return self._reset_flag
355
356    def on_reset(self, event):
357        """
358        The derivative class state is restored
359        """
360    def on_drag(self, event):
361        """
362        The derivative class allows dragging motion if implemented
363        """
364    def on_preview(self, event):
365        """
366        Display a printable version of the class derivative
367        """
368    def on_save(self, event):
369        """
370        The state of the derivative class is restored
371        """
372    def on_redo(self, event):
373        """
374        The previous action is restored if possible
375        """
376    def on_undo(self, event):
377        """
378        The current action is canceled
379        """
380    def on_copy(self, event):
381        """
382        The copy action if possible
383        """
384    def on_paste(self, event):
385        """
386        The paste action if possible
387        """
388    def on_bookmark(self, event):
389        """
390        The derivative class is on bookmark mode if implemented
391        """
392    def on_zoom_in(self, event):
393        """
394        The derivative class is on zoom in mode if implemented
395        """
396    def on_zoom_out(self, event):
397        """
398        The derivative class is on zoom out mode if implemented
399        """
400    def on_zoom(self, event):
401        """
402        The derivative class is on zoom mode (using pane)
403        if zoom mode is implemented
404        """
405    def on_set_focus(self, event=None):
406        """
407        The  derivative class is on focus if implemented
408        """
409        if self.parent is not None:
410            wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self))
411           
412    def on_kill_focus(self, event=None):
413        """
414        The  derivative class is on unfocus if implemented
415        """
416        pass
417               
418    def get_data(self):
419        """
420        return list of current data
421        """
422        return
423   
424    def get_state(self):
425        """
426         return the current state
427        """
428        return
429
430    def set_manager(self, manager):
431        """
432        """
433        self._manager = manager
434       
435    def get_manager(self):
436        """
437        """
438        return self._manager 
439     
440    def get_frame(self):
441        """
442        """
443        if self._manager == None:
444            return None
445        return self._manager.frame
446   
447    def on_close(self, event):
448        """
449            Close event. Hide the whole window.
450        """
451        parent = self.GetParent()
452        if parent is not None:
453            parent.Hide()
454           
Note: See TracBrowser for help on using the repository browser.