source: sasview/src/sas/sasgui/guiframe/panel_base.py @ 0765c00

Last change on this file since 0765c00 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
RevLine 
[b5ca223]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
[03314e7]13
[d85c194]14from sas.sasgui.guiframe.events import PanelOnFocusEvent
15from sas.sasgui.guiframe.events import EVT_NEW_BATCH
[a45037aa]16import wx
[b5ca223]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
[691643c]24    #window_name = "default"
[b5ca223]25    ## Name to appear on the window title bar
[691643c]26    #window_caption = "Welcome panel"
[b5ca223]27    ## Flag to tell the AUI manager to put this panel in the center pane
[75fbd17]28    group_id = None
[df22224]29    uid = None
[b5ca223]30   
[a45037aa]31    def __init__(self, parent=None):
[b5ca223]32        """
33        Initialize some flag that Viewerframe used
34        """
[52725d6]35        #panel manager
36        self._manager = None
[03314e7]37        self.parent = parent
[7bf9a8c]38        if self.parent is not None and hasattr(self.parent, '_manager'):
39            self._manager = self.parent._manager
[b5ca223]40        self._print_flag = False
41        self._undo_flag = False
42        self._redo_flag = False
[07c8630]43        self._copy_flag = False
44        self._paste_flag = False
[b5ca223]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
[03314e7]53        self._has_changed = False
[c958e30]54        self.batch_on = False
[d03a356]55        if self.parent is not None and hasattr(self.parent, "batch_on"):
56            self.batch_on = self.parent.batch_on
57       
[c70eb7c]58        self.group_id = None
[ae84427]59        self.help_string = ''
[225ed2d]60
[c958e30]61    def on_batch_selection(self, event):
62        """
[ac7be54]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.
[c958e30]66        """
67        self.batch_on = event.enable
[6f28e70]68    def save_project(self, doc=None):
69        """
70        return an xml node containing state of the panel
[ac7be54]71        that guiframe can write to file
[6f28e70]72        """
73        return None
74   
[03314e7]75    def has_changed(self):
76        """
77        """
78        return self._has_changed
79           
[f036c692]80    def _set_print_flag(self, flag=True):
[b5ca223]81        """
82        The derivative class sets the print flag value to indicate that it can
83        be printed
84        """
[03314e7]85        if flag == self._print_flag:
86            self._has_changed = False
87            return
88        self._has_changed = True
[b5ca223]89        self._print_flag = flag
[03314e7]90        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]91            self._manager.parent.cpanel_on_focus = self
[03314e7]92            self._manager.parent.enable_print()
93     
[b5ca223]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   
[f036c692]100    def _set_undo_flag(self, flag=True):
[b5ca223]101        """
102        The derivative class sets the undo flag value to indicate that the
103        current action done can be canceled
104        """
[03314e7]105        if flag == self._undo_flag:
106            self._has_changed = False
107            return
108        self._has_changed = True
[b5ca223]109        self._undo_flag = flag
[03314e7]110        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]111            self._manager.parent.cpanel_on_focus = self
[03314e7]112            self._manager.parent.enable_undo()
113     
[b5ca223]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   
[f036c692]120    def _set_redo_flag(self, flag=True):
[b5ca223]121        """
122        The derivative class sets the redo flag value to indicate that the
123        action done can be recovered
124        """
[03314e7]125        if flag == self._redo_flag:
126            self._has_changed = False
127            return
128        self._has_changed = True
[b5ca223]129        self._redo_flag = flag
[03314e7]130        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]131            self._manager.parent.cpanel_on_focus = self
[03314e7]132            self._manager.parent.enable_redo()
133     
[b5ca223]134    def get_redo_flag(self):
135        """
136        Get the redo flag to update appropriately the tool bar
137        """
138        return self._redo_flag
[07c8630]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
[b5ca223]159   
[07c8630]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       
[f036c692]180    def _set_zoomed_in_flag(self, flag=True):
[b5ca223]181        """
182        The derivative class sets the zoom in flag value to indicate that it
183        can be zoomed in
184        """
[03314e7]185        if self._zoom_in_flag == flag:
186            self._has_changed = False
187            return
188        self._has_changed = True
[b5ca223]189        self._zoom_in_flag = flag
[03314e7]190        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]191            self._manager.parent.cpanel_on_focus = self
[03314e7]192            self._manager.parent.enable_zoom_in()
193       
[b5ca223]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   
[f036c692]200    def _set_zoomed_out_flag(self, flag=True):
[b5ca223]201        """
202        The derivative class sets the zoom out flag value to indicate that it
203        can be zoomed out
204        """
[03314e7]205        if self._zoom_out_flag == flag:
206            self._has_changed = False
207            return
208        self._has_changed = True
[b5ca223]209        self._zoom_out_flag = flag
[03314e7]210        if self._manager is not None and self._manager.parent is not None:
[ecc85443]211            self._manager.parent.panel_on_focus = self
[03314e7]212            self._manager.parent.enable_zoom_out()
[b5ca223]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   
[f036c692]220    def _set_zoom_flag(self, flag=True):
[b5ca223]221        """
222        The derivative class sets the zoom flag value to indicate that it
223        can be zoomed
224        """
[03314e7]225        if flag == self._zoom_flag:
226            self._has_changed = False
227            return
228        self._has_changed = True
[b5ca223]229        self._zoom_flag = flag
[03314e7]230        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]231            self._manager.parent.cpanel_on_focus = self
[03314e7]232            self._manager.parent.enable_zoom()
233     
[b5ca223]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   
[f036c692]240    def _set_bookmark_flag(self, flag=True):
[b5ca223]241        """
242        The derivative class sets the bookmark flag value to indicate that it
243        can be bookmarked
244        """
[03314e7]245        if flag == self._bookmark_flag:
246            self._has_changed = False
247            return
248        self._has_changed = True
[b5ca223]249        self._bookmark_flag = flag
[03314e7]250        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]251            self._manager.parent.cpanel_on_focus = self
[03314e7]252            self._manager.parent.enable_bookmark()
[a45037aa]253       
[b5ca223]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   
[f036c692]260    def _set_preview_flag(self, flag=True):
[b5ca223]261        """
262        The derivative class sets the preview flag value to indicate that it
263        can be previewed
264        """
[03314e7]265        if flag == self._preview_flag:
266            self._has_changed = False
267            return
268        self._has_changed = True
[b5ca223]269        self._preview_flag = flag
[03314e7]270        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]271            self._manager.parent.cpanel_on_focus = self
[03314e7]272            self._manager.parent.enable_preview()
273       
[b5ca223]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   
[f036c692]280    def _set_save_flag(self, flag=True):
[b5ca223]281        """
282        The derivative class sets the drag flag value to indicate that it
283        can be saved
284        """
[03314e7]285        if flag == self._save_flag:
286            self._has_changed = False
287            return
288        self._has_changed = True
[b5ca223]289        self._save_flag = flag
[03314e7]290        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]291            self._manager.parent.cpanel_on_focus = self
[03314e7]292            self._manager.parent.enable_save()
[a45037aa]293
[b5ca223]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   
[f036c692]300    def _set_drag_flag(self, flag=True):
[b5ca223]301        """
302        The derivative class sets the drag flag value to indicate that
303        dragging motion is possible
304        """
[03314e7]305        if self._drag_flag == flag:
306            self._has_changed = False
307            return
308        self._has_changed = True
[b5ca223]309        self._drag_flag = flag
[03314e7]310        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]311            self._manager.parent.cpanel_on_focus = self
[03314e7]312            self._manager.parent.enable_drag()
[a45037aa]313       
[b5ca223]314    def get_drag_flag(self):
315        """
316        Get the drag flag to update appropriately the tool bar
317        """
318        return self._drag_flag
[18b7ecb9]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
[f036c692]329    def _set_reset_flag(self, flag=True):
[b5ca223]330        """
331        The derivative class sets the reset flag value to indicate that it
332        can be reset
333        """
[03314e7]334        if self._reset_flag == flag:
335            self._has_changed = False
336            return
337        self._has_changed = True
[b5ca223]338        self._reset_flag = flag
[03314e7]339        if self._manager is not None and self._manager.parent is not None:
[0a2fdca]340            self._manager.parent.cpanel_on_focus = self
[03314e7]341            self._manager.parent.enable_reset()
[46cec6c]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
[a45037aa]349     
[b5ca223]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        """
[07c8630]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        """
[b5ca223]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        """
[a45037aa]405    def on_set_focus(self, event=None):
[b5ca223]406        """
407        The  derivative class is on focus if implemented
408        """
[a45037aa]409        if self.parent is not None:
410            wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self))
[f69b5830]411           
412    def on_kill_focus(self, event=None):
413        """
414        The  derivative class is on unfocus if implemented
415        """
416        pass
417               
[52725d6]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        """
[ae84427]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        """
[663e988]449            Close event. Hide the whole window.
[ae84427]450        """
[663e988]451        parent = self.GetParent()
452        if parent is not None:
453            parent.Hide()
[ae84427]454           
Note: See TracBrowser for help on using the repository browser.