source: sasview/src/sas/guiframe/data_panel.py @ f22d219

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f22d219 was f22d219, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

avoid updating current plot indicator during program shutdown. Fixes #384

  • Property mode set to 100644
File size: 54.5 KB
Line 
1################################################################################
2#This software was developed by the University of Tennessee as part of the
3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4#project funded by the US National Science Foundation.
5#
6#See the license text in license.txt
7#
8#copyright 2010, University of Tennessee
9################################################################################
10"""
11This module provides Graphic interface for the data_manager module.
12"""
13import wx
14from wx.build import build_options
15# Check version
16toks = str(wx.__version__).split('.')
17if int(toks[1]) < 9:
18    if int(toks[2]) < 12:
19        wx_version = 811
20    else:
21        wx_version = 812
22else:
23    wx_version = 900
24import sys
25from wx.lib.scrolledpanel import ScrolledPanel
26import  wx.lib.agw.customtreectrl as CT
27from sas.guiframe.dataFitting import Data1D
28from sas.guiframe.dataFitting import Data2D
29from sas.guiframe.panel_base import PanelBase
30from sas.guiframe.events import StatusEvent
31from sas.guiframe.events import EVT_DELETE_PLOTPANEL
32from sas.guiframe.events import NewLoadDataEvent
33from sas.guiframe.events import NewPlotEvent
34from sas.guiframe.gui_style import GUIFRAME
35from sas.guiframe.events import NewBatchEvent
36from sas.dataloader.loader import Loader
37#from sas.guiframe.local_perspectives.plotting.masking \
38#    import FloatPanel as QucikPlotDialog
39from sas.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame \
40        as QucikPlotDialog
41import sas.guiframe.config as config
42 
43extension_list = []
44if config.APPLICATION_STATE_EXTENSION is not None:
45    extension_list.append(config.APPLICATION_STATE_EXTENSION)
46EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list   
47PLUGINS_WLIST = config.PLUGINS_WLIST
48APPLICATION_WLIST = config.APPLICATION_WLIST
49
50#Control panel width
51if sys.platform.count("win32") > 0:
52    PANEL_WIDTH = 235
53    PANEL_HEIGHT = 700
54    CBOX_WIDTH = 140
55    BUTTON_WIDTH = 80
56    FONT_VARIANT = 0
57    IS_MAC = False
58else:
59    PANEL_WIDTH = 255
60    PANEL_HEIGHT = 750
61    CBOX_WIDTH = 155
62    BUTTON_WIDTH = 100
63    FONT_VARIANT = 1
64    IS_MAC = True
65
66STYLE_FLAG = wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\
67                    wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT
68                   
69                   
70class DataTreeCtrl(CT.CustomTreeCtrl):
71    """
72    Check list control to be used for Data Panel
73    """
74    def __init__(self, parent, *args, **kwds):
75        #agwstyle is introduced in wx.2.8.11 but is not working for mac
76        if IS_MAC and wx_version < 812:
77            try:
78                kwds['style'] = STYLE_FLAG
79                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
80            except:
81                del kwds['style']
82                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
83        else:
84            # agwstyle is introduced in wx.2.8.11
85            # argument working only for windows
86            try:
87                kwds['agwStyle'] = STYLE_FLAG
88                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
89            except:
90                try:
91                    del kwds['agwStyle']
92                    kwds['style'] = STYLE_FLAG
93                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
94                except:
95                    del kwds['style']
96                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
97        self.root = self.AddRoot("Available Data")
98                   
99    def OnCompareItems(self, item1, item2):
100        """
101        Overrides OnCompareItems in wx.TreeCtrl.
102        Used by the SortChildren method.
103        """
104        # Get the item data
105        data_1 = self.GetItemText(item1)
106        data_2 = self.GetItemText(item2)
107        # Compare the item data
108        if data_1 < data_2:
109            return -1
110        elif data_1 > data_2:
111            return 1
112        else:
113            return 0
114       
115class DataPanel(ScrolledPanel, PanelBase):
116    """
117    This panel displays data available in the application and widgets to
118    interact with data.
119    """
120    ## Internal name for the AUI manager
121    window_name = "Data Panel"
122    ## Title to appear on top of the window
123    window_caption = "Data Explorer"
124    #type of window
125    window_type = "Data Panel"
126    ## Flag to tell the GUI manager that this panel is not
127    #  tied to any perspective
128    #ALWAYS_ON = True
129    def __init__(self, parent, 
130                 list=None,
131                 size=(PANEL_WIDTH, PANEL_HEIGHT),
132                 id=-1,
133                 list_of_perspective=None, manager=None, *args, **kwds):
134        #kwds['size'] = size
135        #kwds['style'] = STYLE_FLAG
136        ScrolledPanel.__init__(self, parent=parent, id=id, *args, **kwds)
137        PanelBase.__init__(self, parent)
138        self.SetupScrolling()
139        #Set window's font size
140        self.SetWindowVariant(variant=FONT_VARIANT)
141        self.loader = Loader() 
142        #Default location
143        self._default_save_location = None 
144        self.all_data1d = True
145        self.parent = parent.parent
146        self._manager = manager
147        self.frame = parent
148        if list is None:
149            list = []
150        self.list_of_data = list
151        if list_of_perspective is None:
152            list_of_perspective = []
153        self.list_of_perspective = list_of_perspective
154        self.list_rb_perspectives = []
155        self.list_cb_data = {}
156        self.list_cb_theory = {}
157        self.tree_ctrl = None
158        self.tree_ctrl_theory = None
159        self.perspective_cbox = None
160        ## Create context menu for page
161        self.data_menu = None
162        self.popUpMenu = None
163        self.plot3d_id = None
164        self.editmask_id = None
165        # Default attr
166        self.vbox  = None
167        self.sizer1 = None
168        self.sizer2 = None
169        self.sizer3 = None
170        self.sizer4 = None
171        self.sizer5 = None
172        self.selection_cbox = None
173        self.bt_add = None
174        self.bt_remove = None
175        self.bt_import = None
176        self.bt_append_plot = None
177        self.bt_plot = None
178        self.bt_freeze = None
179        self.cb_plotpanel = None
180        self.rb_single_mode = None
181        self.rb_batch_mode = None
182
183        self.owner = None
184        self.do_layout()
185        self.fill_cbox_analysis(self.list_of_perspective)
186        self.Bind(wx.EVT_SHOW, self.on_close_page)
187        if self.parent is not None:
188            self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel)
189     
190    def do_layout(self):
191        """
192            Create the panel layout
193        """
194        self.define_panel_structure()
195        self.layout_selection()
196        self.layout_data_list()
197        self.layout_batch()
198        self.layout_button()
199       
200    def disable_app_combo(self, enable):
201        """
202        Disable app combo box
203        """
204        self.perspective_cbox.Enable(enable)
205       
206    def define_panel_structure(self):
207        """
208        Define the skeleton of the panel
209        """
210        w, h = self.parent.GetSize()
211        self.vbox  = wx.BoxSizer(wx.VERTICAL)
212        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
213        self.sizer1.SetMinSize(wx.Size(w/13, h*2/5))
214     
215        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
216        self.sizer3 = wx.FlexGridSizer(9, 2, 4, 1)
217        self.sizer4 = wx.BoxSizer(wx.VERTICAL)
218        self.sizer5 = wx.BoxSizer(wx.VERTICAL)
219       
220        self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL, 1)
221        self.vbox.Add(self.sizer1, 1, wx.EXPAND|wx.ALL, 0)
222        self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL, 1)
223        self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL, 10)
224        #self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5)
225       
226        self.SetSizer(self.vbox)
227       
228    def layout_selection(self):
229        """
230            Create selection option combo box
231        """
232        select_txt = wx.StaticText(self, -1, 'Selection Options')
233        select_txt.SetForegroundColour('blue')
234        self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
235        list_of_options = ['Select all Data',
236                            'Unselect all Data',
237                           'Select all Data 1D',
238                           'Unselect all Data 1D',
239                           'Select all Data 2D',
240                           'Unselect all Data 2D' ]
241        for option in list_of_options:
242            self.selection_cbox.Append(str(option))
243        self.selection_cbox.SetValue('Select all Data')
244        wx.EVT_COMBOBOX(self.selection_cbox, -1, self._on_selection_type)
245        self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 
246                            (self.selection_cbox, 0, wx.ALL,5)])
247        self.enable_selection()
248       
249   
250    def _on_selection_type(self, event):
251        """
252            Select data according to patterns
253            :param event: UI event
254        """
255        option = self.selection_cbox.GetValue()
256       
257        pos = self.selection_cbox.GetSelection()
258        if pos == wx.NOT_FOUND:
259            return 
260        option = self.selection_cbox.GetString(pos)
261        for item in self.list_cb_data.values():
262            data_ctrl, _, _, _, _, _, _, _ = item
263            _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 
264            if option == 'Select all Data':
265                self.tree_ctrl.CheckItem(data_ctrl, True) 
266            elif option == 'Unselect all Data':
267                self.tree_ctrl.CheckItem(data_ctrl, False)
268            elif option == 'Select all Data 1D':
269                if data_class == 'Data1D':
270                    self.tree_ctrl.CheckItem(data_ctrl, True) 
271            elif option == 'Unselect all Data 1D':
272                if data_class == 'Data1D':
273                    self.tree_ctrl.CheckItem(data_ctrl, False) 
274            elif option == 'Select all Data 1D':
275                if data_class == 'Data1D':
276                    self.tree_ctrl.CheckItem(data_ctrl, True) 
277            elif option == 'Select all Data 2D':
278                if data_class == 'Data2D':
279                    self.tree_ctrl.CheckItem(data_ctrl, True) 
280            elif option == 'Unselect all Data 2D':
281                if data_class == 'Data2D':
282                    self.tree_ctrl.CheckItem(data_ctrl, False) 
283        self.enable_append()
284        self.enable_freeze()
285        self.enable_plot()
286        self.enable_import()
287        self.enable_remove()
288               
289    def layout_button(self):
290        """
291        Layout widgets related to buttons
292        """
293        self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 
294                                size=(BUTTON_WIDTH, -1))
295        self.bt_add.SetToolTipString("Load data files")
296        wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data)
297        self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data",
298         size=(BUTTON_WIDTH, -1))
299        self.bt_remove.SetToolTipString("Delete data from the application")
300        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove)
301        self.bt_import = wx.Button(self, wx.NewId(), "Send To",
302                                    size=(BUTTON_WIDTH, -1))
303        self.bt_import.SetToolTipString("Send Data set to active perspective")
304        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import)
305        self.perspective_cbox = wx.ComboBox(self, -1,
306                                style=wx.CB_READONLY)
307        if not IS_MAC:
308            self.perspective_cbox.SetMinSize((BUTTON_WIDTH*1.6, -1))
309        wx.EVT_COMBOBOX(self.perspective_cbox, -1, 
310                        self._on_perspective_selection)
311   
312        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To",
313                                        size=(BUTTON_WIDTH, -1))
314        self.bt_append_plot.SetToolTipString( \
315                                "Plot the selected data in the active panel")
316        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot)
317       
318        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 
319                                 size=(BUTTON_WIDTH, -1))
320        self.bt_plot.SetToolTipString("To trigger plotting")
321        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot)
322       
323        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 
324                                   size=(BUTTON_WIDTH, -1))
325        freeze_tip = "To trigger freeze a theory: making a copy\n"
326        freeze_tip += "of the theory checked to Data box,\n"
327        freeze_tip += "     so that it can act like a real data set."
328        self.bt_freeze.SetToolTipString(freeze_tip)
329        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze)
330       
331        if sys.platform == 'darwin':
332            self.cb_plotpanel = wx.ComboBox(self, -1, 
333                                            style=wx.CB_READONLY)
334        else:
335            self.cb_plotpanel = wx.ComboBox(self, -1, 
336                                            style=wx.CB_READONLY|wx.CB_SORT)
337        wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection)
338        self.cb_plotpanel.Disable()
339
340        self.sizer3.AddMany([(self.bt_add),
341                             ((10, 10)),
342                             (self.bt_remove),
343                             ((10, 10)),
344                             (self.bt_freeze),
345                             ((10, 10)),
346                             (self.bt_plot),
347                             ((10, 10)),
348                             (self.bt_append_plot),
349                             (self.cb_plotpanel, 
350                              wx.EXPAND|wx.ADJUST_MINSIZE, 5),
351                             ((5, 5)),
352                             ((5, 5)),
353                             (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5),
354                             (self.perspective_cbox, 
355                              wx.EXPAND|wx.ADJUST_MINSIZE, 5),
356                             ((10, 10)),
357                             (self.sizer4),
358                             ((10, 40)),
359                             ((10, 40))])
360
361        self.sizer3.AddGrowableCol(1, 1)
362        self.show_data_button()
363        self.enable_remove()
364        self.enable_import()
365        self.enable_plot()
366        self.enable_append()
367        self.enable_freeze()
368        self.enable_remove_plot()
369       
370    def layout_batch(self):
371        """
372            Set up batch mode options
373        """
374        self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode',
375                                             style=wx.RB_GROUP)
376        self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode')
377        self.Bind(wx.EVT_RADIOBUTTON, self.on_single_mode,
378                     id=self.rb_single_mode.GetId())
379        self.Bind(wx.EVT_RADIOBUTTON, self.on_batch_mode,
380                   id=self.rb_batch_mode.GetId())
381       
382        self.rb_single_mode.SetValue(not self.parent.batch_on)
383        self.rb_batch_mode.SetValue(self.parent.batch_on)
384        self.sizer4.AddMany([(self.rb_single_mode, 0, wx.ALL, 4),
385                             (self.rb_batch_mode, 0, wx.ALL, 4)])
386       
387    def on_single_mode(self, event):
388        """
389            Change to single mode
390            :param event: UI event
391        """
392        if self.parent is not None:
393            wx.PostEvent(self.parent, NewBatchEvent(enable=False))
394       
395    def on_batch_mode(self, event):
396        """
397            Change to batch mode
398            :param event: UI event
399        """
400        if self.parent is not None:
401            wx.PostEvent(self.parent, 
402                         NewBatchEvent(enable=True))
403   
404    def _get_data_selection(self, event): 
405        """
406            Get data selection from the right click
407            :param event: UI event
408        """
409        data = None
410        #selection = event.GetSelection()
411        id, _, _ = self.FindFocus().GetSelection().GetData()
412        data_list, theory_list = \
413                        self.parent.get_data_manager().get_by_id(id_list=[id])
414        if data_list:
415            data = data_list.values()[0]
416        if data == None:
417            data = theory_list.values()[0][0]
418        return data
419   
420    def on_edit_data(self, event):
421        """
422        Pop Up Data Editor
423        """
424        data = self._get_data_selection(event)
425        from sas.guiframe.local_perspectives.plotting.masking \
426            import MaskPanel as MaskDialog
427       
428        panel = MaskDialog(parent=self.parent, base=self, 
429                           data=data, id=wx.NewId())
430        panel.ShowModal()
431   
432    def on_plot_3d(self, event):
433        """
434        Frozen image of 3D
435        """
436        data = self._get_data_selection(event)
437        from sas.guiframe.local_perspectives.plotting.masking \
438        import FloatPanel as Float3dDialog
439       
440        panel = Float3dDialog(base=self, data=data, 
441                              dimension=3, id=wx.NewId())
442        panel.ShowModal()   
443   
444    def on_quick_plot(self, event):
445        """
446        Frozen plot
447        """
448        data = self._get_data_selection(event)
449        if data.__class__.__name__ == "Data2D":
450            dimension = 2
451        else:
452            dimension = 1 
453        #panel = QucikPlotDialog(base=self, data=data,
454        #                        dimension=dimension, id=wx.NewId())
455        frame = QucikPlotDialog(self, -1, "Plot " + data.name, 'log_{10}')
456        self.parent.put_icon(frame)
457        frame.add_plot(data)
458        #frame.SetTitle(title)
459        frame.Show(True)
460        frame.SetFocus()
461        #panel.ShowModal()   
462   
463    def on_data_info(self, event):
464        """
465        Data Info panel
466        """
467        data = self._get_data_selection(event)
468        if data.__class__.__name__ == "Data2D":
469            self.parent.show_data2d(data, data.name)
470        else:
471            self.parent.show_data1d(data, data.name)
472       
473    def on_save_as(self, event):
474        """
475        Save data as a file
476        """
477        data = self._get_data_selection(event)
478        #path = None
479        default_name = data.name
480        if default_name.count('.') > 0:
481            default_name = default_name.split('.')[0]
482        default_name += "_out"
483        if self.parent != None:
484            if issubclass(data.__class__, Data1D):
485                self.parent.save_data1d(data, default_name)
486            elif issubclass(data.__class__, Data2D):
487                self.parent.save_data2d(data, default_name)
488            else:
489                print "unable to save this type of data"
490       
491    def layout_data_list(self):
492        """
493        Add a listcrtl in the panel
494        """
495        tree_ctrl_label = wx.StaticText(self, -1, "Data")
496        tree_ctrl_label.SetForegroundColour('blue')
497        self.tree_ctrl = DataTreeCtrl(parent=self, style=wx.SUNKEN_BORDER)
498        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
499        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click_data)
500        ## Create context menu for page
501        self.data_menu = wx.Menu()
502        id = wx.NewId()
503        name = "Data Info"
504        msg = "Show Data Info"
505        self.data_menu.Append(id, name, msg)
506        wx.EVT_MENU(self, id, self.on_data_info)
507       
508        id = wx.NewId()
509        name = "Save As"
510        msg = "Save Theory/Data as a file"
511        self.data_menu.Append(id, name, msg)
512        wx.EVT_MENU(self, id, self.on_save_as)
513   
514        quickplot_id = wx.NewId()
515        name = "Quick Plot"
516        msg = "Plot the current Data"
517        self.data_menu.Append(quickplot_id, name, msg)
518        wx.EVT_MENU(self, quickplot_id, self.on_quick_plot)
519       
520        self.plot3d_id = wx.NewId()
521        name = "Quick 3DPlot (Slow)"
522        msg = "Plot3D the current 2D Data"
523        self.data_menu.Append(self.plot3d_id, name, msg)
524        wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d)
525           
526        self.editmask_id = wx.NewId()
527        name = "Edit Mask"
528        msg = "Edit Mask for the current 2D Data"
529        self.data_menu.Append(self.editmask_id, name, msg)
530        wx.EVT_MENU(self, self.editmask_id, self.on_edit_data)
531       
532        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory")
533        tree_ctrl_theory_label.SetForegroundColour('blue')
534        self.tree_ctrl_theory = DataTreeCtrl(parent=self, 
535                                                    style=wx.SUNKEN_BORDER)
536        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 
537                                                    self.on_check_item)
538        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 
539                                   self.on_right_click_theory)
540        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10)
541        self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10)
542        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10)
543        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10)
544           
545    def on_right_click_theory(self, event):
546        """
547        On click theory data
548        """
549        try:
550            id, data_class_name, _ = \
551                            self.tree_ctrl_theory.GetSelection().GetData()
552            _, _ = self.parent.get_data_manager().get_by_id(id_list=[id])
553        except:
554            return
555        if self.data_menu is not None:
556            menu_enable = (data_class_name == "Data2D")
557            self.data_menu.Enable(self.editmask_id, False)
558            self.data_menu.Enable(self.plot3d_id, menu_enable)
559            self.PopupMenu(self.data_menu) 
560                   
561    def on_right_click_data(self, event):
562        """
563        Allow Editing Data
564        """
565        #selection = event.GetSelection()
566        is_data = True
567        try:
568            id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData()
569            data_list, _ = \
570                        self.parent.get_data_manager().get_by_id(id_list=[id])
571            if not data_list:
572                is_data = False
573        except:
574            return
575        if self.data_menu is not None:
576            menu_enable = (data_class_name == "Data2D")
577            maskmenu_enable = (menu_enable and is_data)
578            self.data_menu.Enable(self.editmask_id, maskmenu_enable)
579            self.data_menu.Enable(self.plot3d_id, menu_enable)
580            self.PopupMenu(self.data_menu) 
581       
582    def onContextMenu(self, event): 
583        """
584        Retrieve the state selected state
585        """
586        # Skipping the save state functionality for release 0.9.0
587        #return
588        pos = event.GetPosition()
589        pos = self.ScreenToClient(pos)
590        self.PopupMenu(self.popUpMenu, pos) 
591     
592 
593    def on_check_item(self, event):
594        """
595        On check item
596        """
597        item = event.GetItem()
598        item.Check(not item.IsChecked()) 
599        self.enable_append()
600        self.enable_freeze()
601        self.enable_plot()
602        self.enable_import()
603        self.enable_remove()
604        event.Skip()
605       
606    def fill_cbox_analysis(self, plugin):
607        """
608        fill the combobox with analysis name
609        """
610        self.list_of_perspective = plugin
611        if self.parent is None or \
612            not hasattr(self.parent, "get_current_perspective") or \
613            len(self.list_of_perspective) == 0:
614            return
615        if self.parent is not None and self.perspective_cbox  is not None:
616            for plug in self.list_of_perspective:
617                if plug.get_perspective():
618                    self.perspective_cbox.Append(plug.sub_menu, plug)
619           
620            curr_pers = self.parent.get_current_perspective()
621            if curr_pers:
622                self.perspective_cbox.SetStringSelection(curr_pers.sub_menu)
623                self.enable_import()
624                       
625    def load_data_list(self, list):
626        """
627        add need data with its theory under the tree
628        """
629        if list:
630            for state_id, dstate in list.iteritems():
631                data = dstate.get_data()
632                theory_list = dstate.get_theory()
633                if data is not None:
634                    data_name = str(data.name)
635                    data_title = str(data.title)
636                    data_run = str(data.run)
637                    data_class = data.__class__.__name__
638                    path = dstate.get_path() 
639                    process_list = data.process
640                    data_id = data.id
641                    s_path = str(path)
642                    if state_id not in self.list_cb_data:
643                        #new state
644                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,
645                                        0, data_name, ct_type=1, 
646                                        data=(data_id, data_class, state_id))
647                        data_c.Check(True)
648                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
649                        d_t_c = self.tree_ctrl.AppendItem(d_i_c, 
650                                                      'Title: %s' % data_title)
651                        r_n_c = self.tree_ctrl.AppendItem(d_i_c, 
652                                                      'Run: %s' % data_run)
653                        i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
654                                                      'Type: %s' % data_class)
655                        p_c_c = self.tree_ctrl.AppendItem(d_i_c,
656                                                      "Path: '%s'" % s_path)
657                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
658                       
659                        for process in process_list:
660                            process_str = str(process).replace('\n',' ')
661                            if len(process_str)>20:
662                                process_str = process_str[:20]+' [...]'
663                            self.tree_ctrl.AppendItem(d_p_c, process_str)
664                        theory_child = self.tree_ctrl.AppendItem(data_c, 
665                                                                 "THEORIES")
666                        self.list_cb_data[state_id] = [data_c, 
667                                                       d_i_c,
668                                                       d_t_c,
669                                                       r_n_c,
670                                                       i_c_c,
671                                                       p_c_c,
672                                                       d_p_c,
673                                                       theory_child]
674                    else:
675                        data_ctrl_list =  self.list_cb_data[state_id]
676                        #This state is already display replace it contains
677                        data_c, d_i_c, d_t_c, r_n_c,  i_c_c, p_c_c, d_p_c, _ \
678                                = data_ctrl_list
679                        self.tree_ctrl.SetItemText(data_c, data_name) 
680                        temp = (data_id, data_class, state_id)
681                        self.tree_ctrl.SetItemPyData(data_c, temp) 
682                        self.tree_ctrl.SetItemText(i_c_c, 
683                                                   'Type: %s' % data_class)
684                        self.tree_ctrl.SetItemText(p_c_c, 
685                                                   'Path: %s' % s_path) 
686                        self.tree_ctrl.DeleteChildren(d_p_c) 
687                        for process in process_list:
688                            _ = self.tree_ctrl.AppendItem(d_p_c,
689                                                              process.__str__())
690                wx.CallAfter(self.append_theory, state_id, theory_list)
691            # Sort by data name
692            if self.tree_ctrl.root:
693                self.tree_ctrl.SortChildren(self.tree_ctrl.root)   
694        self.enable_remove()
695        self.enable_import()
696        self.enable_plot()
697        self.enable_freeze()
698        self.enable_selection()
699       
700    def _uncheck_all(self):
701        """
702        Uncheck all check boxes
703        """
704        for item in self.list_cb_data.values():
705            data_ctrl, _, _, _, _, _, _, _ = item
706            self.tree_ctrl.CheckItem(data_ctrl, False) 
707        self.enable_append()
708        self.enable_freeze()
709        self.enable_plot()
710        self.enable_import()
711        self.enable_remove()
712   
713    def append_theory(self, state_id, theory_list):
714        """
715        append theory object under data from a state of id = state_id
716        replace that theory if  already displayed
717        """
718        if not theory_list:
719            return 
720        if state_id not in self.list_cb_data.keys():
721            root = self.tree_ctrl_theory.root
722            tree = self.tree_ctrl_theory
723        else:
724            item = self.list_cb_data[state_id]
725            data_c, _, _, _, _, _, _, _ = item
726            root = data_c
727            tree = self.tree_ctrl
728        if root is not None:
729            wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 
730                                       state_id=state_id, 
731                                       theory_list=theory_list)
732     
733     
734    def append_theory_helper(self, tree, root, state_id, theory_list):
735        """
736        Append theory helper
737        """
738        if state_id in self.list_cb_theory.keys():
739            #update current list of theory for this data
740            theory_list_ctrl = self.list_cb_theory[state_id]
741
742            for theory_id, item in theory_list.iteritems():
743                theory_data, _ = item
744                if theory_data is None:
745                    name = "Unknown"
746                    theory_class = "Unknown"
747                    theory_id = "Unknown"
748                    temp = (None, None, None)
749                else:
750                    name = theory_data.name
751                    theory_class = theory_data.__class__.__name__
752                    theory_id = theory_data.id
753                    #if theory_state is not None:
754                    #    name = theory_state.model.name
755                    temp = (theory_id, theory_class, state_id)
756                if theory_id not in theory_list_ctrl:
757                    #add new theory
758                    t_child = tree.AppendItem(root,
759                                                    name, ct_type=1, data=temp)
760                    t_i_c = tree.AppendItem(t_child, 'Info')
761                    i_c_c = tree.AppendItem(t_i_c, 
762                                                  'Type: %s' % theory_class)
763                    t_p_c = tree.AppendItem(t_i_c, 'Process')
764                   
765                    for process in theory_data.process:
766                        tree.AppendItem(t_p_c, process.__str__())
767                    theory_list_ctrl[theory_id] = [t_child, 
768                                                   i_c_c, 
769                                                   t_p_c]
770                else:
771                    #replace theory
772                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
773                    tree.SetItemText(t_child, name) 
774                    tree.SetItemPyData(t_child, temp) 
775                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
776                    tree.DeleteChildren(t_p_c) 
777                    for process in theory_data.process:
778                        tree.AppendItem(t_p_c, process.__str__())
779             
780        else:
781            #data didn't have a theory associated it before
782            theory_list_ctrl = {}
783            for theory_id, item in theory_list.iteritems():
784                theory_data, _ = item
785                if theory_data is not None:
786                    name = theory_data.name
787                    theory_class = theory_data.__class__.__name__
788                    theory_id = theory_data.id
789                    #if theory_state is not None:
790                    #    name = theory_state.model.name
791                    temp = (theory_id, theory_class, state_id)
792                    t_child = tree.AppendItem(root,
793                            name, ct_type=1, 
794                            data=(theory_data.id, theory_class, state_id))
795                    t_i_c = tree.AppendItem(t_child, 'Info')
796                    i_c_c = tree.AppendItem(t_i_c, 
797                                                  'Type: %s' % theory_class)
798                    t_p_c = tree.AppendItem(t_i_c, 'Process')
799                   
800                    for process in theory_data.process:
801                        tree.AppendItem(t_p_c, process.__str__())
802           
803                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
804                #self.list_cb_theory[data_id] = theory_list_ctrl
805                self.list_cb_theory[state_id] = theory_list_ctrl
806       
807           
808   
809    def set_data_helper(self):
810        """
811        Set data helper
812        """
813        data_to_plot = []
814        state_to_plot = []
815        theory_to_plot = []
816        for value in self.list_cb_data.values():
817            item, _, _, _, _, _, _,  _ = value
818            if item.IsChecked():
819                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
820                data_to_plot.append(data_id)
821                if state_id not in state_to_plot:
822                    state_to_plot.append(state_id)
823           
824        for theory_dict in self.list_cb_theory.values():
825            for _, value in theory_dict.iteritems():
826                item, _, _ = value
827                if item.IsChecked():
828                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
829                    theory_to_plot.append(theory_id)
830                    if state_id not in state_to_plot:
831                        state_to_plot.append(state_id)
832        return data_to_plot, theory_to_plot, state_to_plot
833   
834    def remove_by_id(self, id):
835        """
836        Remove_dat by id
837        """
838        for item in self.list_cb_data.values():
839            data_c, _, _, _, _, _,  _, _ = item
840            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
841            if id == data_id:
842                self.tree_ctrl.Delete(data_c)
843                del self.list_cb_data[state_id]
844                del self.list_cb_theory[data_id]
845             
846    def load_error(self, error=None):
847        """
848        Pop up an error message.
849       
850        :param error: details error message to be displayed
851        """
852        if error is not None or str(error).strip() != "":
853            dial = wx.MessageDialog(self.parent, str(error), 
854                                    'Error Loading File',
855                                    wx.OK | wx.ICON_EXCLAMATION)
856            dial.ShowModal() 
857       
858    def _load_data(self, event):
859        """
860        send an event to the parent to trigger load from plugin module
861        """
862        if self.parent is not None:
863            wx.PostEvent(self.parent, NewLoadDataEvent())
864           
865
866    def on_remove(self, event):
867        """
868        Get a list of item checked and remove them from the treectrl
869        Ask the parent to remove reference to this item
870        """
871        msg = "This operation will delete the data sets checked "
872        msg += "and all the dependents."
873        msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)
874        if msg_box.ShowModal() != wx.ID_OK:
875            return
876       
877        data_to_remove, theory_to_remove, _ = self.set_data_helper()
878        data_key = []
879        theory_key = []
880        #remove  data from treectrl
881        for d_key, item in self.list_cb_data.iteritems():
882            data_c, _, _, _,  _, _, _, _ = item
883            if data_c.IsChecked():
884                self.tree_ctrl.Delete(data_c)
885                data_key.append(d_key)
886                if d_key in self.list_cb_theory.keys():
887                    theory_list_ctrl = self.list_cb_theory[d_key]
888                    theory_to_remove += theory_list_ctrl.keys()
889        # Remove theory from treectrl       
890        for _, theory_dict in self.list_cb_theory.iteritems():
891            for  key, value in theory_dict.iteritems():
892                item, _, _ = value
893                if item.IsChecked():
894                    try:
895                        self.tree_ctrl.Delete(item)
896                    except:
897                        pass
898                    theory_key.append(key)
899                   
900        #Remove data and related theory references
901        for key in data_key:
902            del self.list_cb_data[key]
903            if key in theory_key:
904                del self.list_cb_theory[key]
905        #remove theory  references independently of data
906        for key in theory_key:
907            for _, theory_dict in self.list_cb_theory.iteritems():
908                if key in theory_dict:
909                    for  key, value in theory_dict.iteritems():
910                        item, _, _ = value
911                        if item.IsChecked():
912                            try:
913                                self.tree_ctrl_theory.Delete(item)
914                            except:
915                                pass
916                    del theory_dict[key]
917                   
918           
919        self.parent.remove_data(data_id=data_to_remove,
920                                  theory_id=theory_to_remove)
921        self.enable_remove()
922        self.enable_freeze()
923        self.enable_remove_plot()
924       
925    def on_import(self, event=None):
926        """
927        Get all select data and set them to the current active perspetive
928        """
929        if event != None:
930            event.Skip()
931        data_id, theory_id, state_id = self.set_data_helper()
932        temp = data_id + state_id
933        self.parent.set_data(data_id=temp, theory_id=theory_id)
934       
935    def on_append_plot(self, event=None):
936        """
937        append plot to plot panel on focus
938        """
939        self._on_plot_selection()
940        data_id, theory_id, state_id = self.set_data_helper()
941        self.parent.plot_data(data_id=data_id, 
942                              state_id=state_id,
943                              theory_id=theory_id,
944                              append=True)
945   
946    def on_plot(self, event=None):
947        """
948        Send a list of data names to plot
949        """
950        data_id, theory_id, state_id = self.set_data_helper()
951        self.parent.plot_data(data_id=data_id, 
952                              state_id=state_id,
953                              theory_id=theory_id,
954                              append=False)
955        self.enable_remove_plot()
956         
957    def on_close_page(self, event=None):
958        """
959        On close
960        """
961        if event != None:
962            event.Skip()
963        # send parent to update menu with no show nor hide action
964        self.parent.show_data_panel(action=False)
965   
966    def on_freeze(self, event):
967        """
968        On freeze to make a theory to a data set
969        """
970        _, theory_id, state_id = self.set_data_helper()
971        if len(theory_id) > 0:
972            self.parent.freeze(data_id=state_id, theory_id=theory_id)
973            msg = "Freeze Theory:"
974            msg += " The theory(s) copied to the Data box as a data set."
975        else:
976            msg = "Freeze Theory: Requires at least one theory checked."
977        wx.PostEvent(self.parent, StatusEvent(status=msg))
978           
979    def set_active_perspective(self, name):
980        """
981        set the active perspective
982        """
983        self.perspective_cbox.SetStringSelection(name)
984        self.enable_import()
985       
986    def _on_delete_plot_panel(self, event):
987        """
988        get an event with attribute name and caption to delete existing name
989        from the combobox of the current panel
990        """
991        #name = event.name
992        caption = event.caption
993        if self.cb_plotpanel is not None:
994            pos = self.cb_plotpanel.FindString(str(caption)) 
995            if pos != wx.NOT_FOUND:
996                self.cb_plotpanel.Delete(pos)
997        self.enable_append()
998       
999    def set_panel_on_focus(self, name=None):
1000        """
1001        set the plot panel on focus
1002        """
1003        if self.cb_plotpanel and self.cb_plotpanel.IsBeingDeleted():
1004            return
1005        for _, value in self.parent.plot_panels.iteritems():
1006            name_plot_panel = str(value.window_caption)
1007            if name_plot_panel not in self.cb_plotpanel.GetItems():
1008                self.cb_plotpanel.Append(name_plot_panel, value)
1009            if name != None and name == name_plot_panel:
1010                self.cb_plotpanel.SetStringSelection(name_plot_panel)
1011                break
1012        self.enable_append()
1013        self.enable_remove_plot()
1014   
1015    def set_plot_unfocus(self):
1016        """
1017        Unfocus plot
1018        """
1019        return
1020   
1021    def _on_perspective_selection(self, event=None):
1022        """
1023        select the current perspective for guiframe
1024        """
1025        selection = self.perspective_cbox.GetSelection()
1026        if self.perspective_cbox.GetValue() != 'None':
1027            perspective = self.perspective_cbox.GetClientData(selection)
1028            perspective.on_perspective(event=None)
1029            self.parent.check_multimode(perspective=perspective)
1030               
1031    def _on_plot_selection(self, event=None):
1032        """
1033        On source combobox selection
1034        """
1035        if event != None:
1036            combo = event.GetEventObject()
1037            event.Skip()
1038        else:
1039            combo = self.cb_plotpanel
1040        selection = combo.GetSelection()
1041
1042        if combo.GetValue() != 'None':
1043            panel = combo.GetClientData(selection)
1044            self.parent.on_set_plot_focus(panel)   
1045           
1046    def on_close_plot(self, event):
1047        """
1048        clseo the panel on focus
1049        """ 
1050        self.enable_append()
1051        selection = self.cb_plotpanel.GetSelection()
1052        if self.cb_plotpanel.GetValue() != 'None':
1053            panel = self.cb_plotpanel.GetClientData(selection)
1054            if self.parent is not None and panel is not None:
1055                wx.PostEvent(self.parent, 
1056                             NewPlotEvent(group_id=panel.group_id,
1057                                          action="delete"))
1058        self.enable_remove_plot()
1059   
1060    def set_frame(self, frame):
1061        """
1062        """
1063        self.frame = frame
1064   
1065    def get_frame(self):
1066        """
1067        """
1068        return self.frame
1069   
1070    def on_close(self, event):
1071        """
1072        On close event
1073        """
1074        self.parent.show_data_panel(event)
1075                       
1076    def set_schedule_full_draw(self, panel=None, func='del'):
1077        """
1078        Send full draw to guimanager
1079        """
1080        self.parent.set_schedule_full_draw(panel, func)
1081       
1082    def enable_remove_plot(self):
1083        """
1084        enable remove plot button if there is a plot panel on focus
1085        """
1086        pass
1087        #if self.cb_plotpanel.GetCount() == 0:
1088        #    self.bt_close_plot.Disable()
1089        #else:
1090        #    self.bt_close_plot.Enable()
1091           
1092    def enable_remove(self):
1093        """
1094        enable or disable remove button
1095        """
1096        n_t = self.tree_ctrl.GetCount()
1097        n_t_t = self.tree_ctrl_theory.GetCount()
1098        if n_t + n_t_t <= 0:
1099            self.bt_remove.Disable()
1100        else:
1101            self.bt_remove.Enable()
1102           
1103    def enable_import(self):
1104        """
1105        enable or disable send button
1106        """
1107        n_t = 0
1108        if self.tree_ctrl != None:
1109            n_t = self.tree_ctrl.GetCount()
1110        if n_t > 0 and len(self.list_of_perspective) > 0:
1111            self.bt_import.Enable()
1112        else:
1113            self.bt_import.Disable()
1114        if len(self.list_of_perspective) <= 0 or \
1115            self.perspective_cbox.GetValue()  in ["None",
1116                                                "No Active Application"]:
1117            self.perspective_cbox.Disable()
1118        else:
1119            self.perspective_cbox.Enable()
1120           
1121    def enable_plot(self):
1122        """
1123        enable or disable plot button
1124        """
1125        n_t = 0 
1126        n_t_t = 0
1127        if self.tree_ctrl != None:
1128            n_t = self.tree_ctrl.GetCount()
1129        if self.tree_ctrl_theory != None:
1130            n_t_t = self.tree_ctrl_theory.GetCount()
1131        if n_t + n_t_t <= 0:
1132            self.bt_plot.Disable()
1133        else:
1134            self.bt_plot.Enable()
1135        self.enable_append()
1136       
1137    def enable_append(self):
1138        """
1139        enable or disable append button
1140        """
1141        n_t = 0 
1142        n_t_t = 0
1143        if self.tree_ctrl != None:
1144            n_t = self.tree_ctrl.GetCount()
1145        if self.tree_ctrl_theory != None:
1146            n_t_t = self.tree_ctrl_theory.GetCount()
1147        if n_t + n_t_t <= 0: 
1148            self.bt_append_plot.Disable()
1149            self.cb_plotpanel.Disable()
1150        elif self.cb_plotpanel.GetCount() <= 0:
1151            self.cb_plotpanel.Disable()
1152            self.bt_append_plot.Disable()
1153        else:
1154            self.bt_append_plot.Enable()
1155            self.cb_plotpanel.Enable()
1156           
1157    def check_theory_to_freeze(self):
1158        """
1159        Check_theory_to_freeze
1160        """
1161    def enable_freeze(self):
1162        """
1163        enable or disable the freeze button
1164        """
1165        n_t_t = 0
1166        n_l = 0
1167        if self.tree_ctrl_theory != None:
1168            n_t_t = self.tree_ctrl_theory.GetCount()
1169        n_l = len(self.list_cb_theory)
1170        if (n_t_t + n_l > 0):
1171            self.bt_freeze.Enable()
1172        else:
1173            self.bt_freeze.Disable()
1174       
1175    def enable_selection(self):
1176        """
1177        enable or disable combobo box selection
1178        """
1179        n_t = 0
1180        n_t_t = 0
1181        if self.tree_ctrl != None:
1182            n_t = self.tree_ctrl.GetCount()
1183        if self.tree_ctrl_theory != None:
1184            n_t_t = self.tree_ctrl_theory.GetCount()
1185        if n_t + n_t_t > 0 and self.selection_cbox != None:
1186            self.selection_cbox.Enable()
1187        else:
1188            self.selection_cbox.Disable()
1189           
1190    def show_data_button(self):
1191        """
1192        show load data and remove data button if
1193        dataloader on else hide them
1194        """
1195        try:
1196            gui_style = self.parent.get_style()
1197            style = gui_style & GUIFRAME.DATALOADER_ON
1198            if style == GUIFRAME.DATALOADER_ON: 
1199                #self.bt_remove.Show(True)
1200                self.bt_add.Show(True) 
1201            else:
1202                #self.bt_remove.Hide()
1203                self.bt_add.Hide()
1204        except: 
1205            #self.bt_remove.Hide()
1206            self.bt_add.Hide() 
1207   
1208
1209
1210WIDTH = 400
1211HEIGHT = 300
1212
1213
1214class DataDialog(wx.Dialog):
1215    """
1216    Allow file selection at loading time
1217    """
1218    def __init__(self, data_list, parent=None, text='', *args, **kwds):
1219        wx.Dialog.__init__(self, parent, *args, **kwds)
1220        self.SetTitle("Data Selection")
1221        self.SetSize((WIDTH, HEIGHT))
1222        self.list_of_ctrl = []
1223        if not data_list:
1224            return 
1225        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
1226        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
1227        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
1228        self.sizer = wx.GridBagSizer(5, 5)
1229        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
1230                               size=(WIDTH-20, HEIGHT-50))
1231        self._panel.SetupScrolling()
1232        self.__do_layout(data_list, text=text)
1233       
1234    def __do_layout(self, data_list, text=''):
1235        """
1236        layout the dialog
1237        """
1238        if not data_list or len(data_list) <= 1:
1239            return 
1240        #add text
1241       
1242        text = "Deleting these file reset some panels.\n"
1243        text += "Do you want to proceed?\n"
1244        text_ctrl = wx.StaticText(self, -1, str(text))
1245        self._sizer_txt.Add(text_ctrl)
1246        iy = 0
1247        ix = 0
1248        #data_count = 0
1249        for (data_name, in_use, sub_menu) in range(len(data_list)):
1250            if in_use == True:
1251                ctrl_name = wx.StaticBox(self, -1, str(data_name))
1252                ctrl_in_use = wx.StaticBox(self, -1, " is used by ")
1253                plug_name = str(sub_menu) + "\n"
1254                #ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)
1255                self.sizer.Add(ctrl_name, (iy, ix),
1256                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
1257                ix += 1
1258                self._sizer_button.Add(ctrl_in_use, 1,
1259                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1260                ix += 1
1261                self._sizer_button.Add(plug_name, 1,
1262                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1263            iy += 1
1264        self._panel.SetSizer(self.sizer)
1265        #add sizer
1266        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1267        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
1268        self._sizer_button.Add(button_cancel, 0,
1269                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1270        button_OK = wx.Button(self, wx.ID_OK, "Ok")
1271        button_OK.SetFocus()
1272        self._sizer_button.Add(button_OK, 0,
1273                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1274        static_line = wx.StaticLine(self, -1)
1275       
1276        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
1277        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
1278        #self._sizer_main.Add(self._data_text_ctrl, 0,
1279        #                     wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
1280        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
1281        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
1282        self.SetSizer(self._sizer_main)
1283        self.Layout()
1284       
1285    def get_data(self):
1286        """
1287        return the selected data
1288        """
1289        temp = []
1290        for item in self.list_of_ctrl:
1291            cb, data = item
1292            if cb.GetValue():
1293                temp.append(data)
1294        return temp
1295               
1296class DataFrame(wx.Frame):
1297    """
1298    Data Frame
1299    """
1300    ## Internal name for the AUI manager
1301    window_name = "Data Panel"
1302    ## Title to appear on top of the window
1303    window_caption = "Data Panel"
1304    ## Flag to tell the GUI manager that this panel is not
1305    #  tied to any perspective
1306    ALWAYS_ON = True
1307   
1308    def __init__(self, parent=None, owner=None, manager=None, size=(300, 800),
1309                         list_of_perspective=[], list=[], *args, **kwds):
1310        kwds['size'] = size
1311        kwds['id'] = -1
1312        kwds['title'] = "Loaded Data"
1313        wx.Frame.__init__(self, parent=parent, *args, **kwds)
1314        self.parent = parent
1315        self.owner = owner
1316        self._manager = manager
1317        self.panel = DataPanel(parent=self, 
1318                               manager=manager,
1319                               list_of_perspective=list_of_perspective)
1320     
1321    def load_data_list(self, list=[]):
1322        """
1323        Fill the list inside its panel
1324        """
1325        self.panel.load_data_list(list=list)
1326       
1327   
1328   
1329from sas.guiframe.dataFitting import Theory1D
1330from sas.guiframe.data_state import DataState
1331
1332class State():
1333    """
1334    DataPanel State
1335    """
1336    def __init__(self):
1337        self.msg = ""
1338    def __str__(self):
1339        self.msg = "model mane : model1\n"
1340        self.msg += "params : \n"
1341        self.msg += "name  value\n"
1342        return self.msg
1343   
1344def set_data_state(data=None, path=None, theory=None, state=None):
1345    """
1346    Set data state
1347    """
1348    dstate = DataState(data=data)
1349    dstate.set_path(path=path)
1350    dstate.set_theory(theory, state)
1351 
1352    return dstate
1353   
1354if __name__ == "__main__":
1355   
1356    app = wx.App()
1357    try:
1358        #list_of_perspective = [('perspective2', False), ('perspective1', True)]
1359        data_list1 = {}
1360        # state 1
1361        data1 = Data2D()
1362        data1.name = "data2"
1363        data1.id = 1
1364        data1.append_empty_process()
1365        process1 = data1.process[len(data1.process)-1]
1366        process1.data = "07/01/2010"
1367        theory1 = Data2D()
1368        theory1.id = 34
1369        theory1.name = "theory1"
1370        path1 = "path1"
1371        state1 = State()
1372        data_list1['1'] = set_data_state(data1, path1, theory1, state1)
1373        #state 2
1374        data1 = Data2D()
1375        data1.name = "data2"
1376        data1.id = 76
1377        theory1 = Data2D()
1378        theory1.id = 78
1379        theory1.name = "CoreShell 07/24/25"
1380        path1 = "path2"
1381        #state3
1382        state1 = State()
1383        data_list1['2'] = set_data_state(data1, path1, theory1, state1)
1384        data1 = Data1D()
1385        data1.id = 3
1386        data1.name = "data2"
1387        theory1 = Theory1D()
1388        theory1.name = "CoreShell"
1389        theory1.id = 4
1390        theory1.append_empty_process()
1391        process1 = theory1.process[len(theory1.process)-1]
1392        process1.description = "this is my description"
1393        path1 = "path3"
1394        data1.append_empty_process()
1395        process1 = data1.process[len(data1.process)-1]
1396        process1.data = "07/22/2010"
1397        data_list1['4'] = set_data_state(data1, path1, theory1, state1)
1398        #state 4
1399        temp_data_list = {}
1400        data1.name = "data5 erasing data2"
1401        temp_data_list['4'] = set_data_state(data1, path1, theory1, state1)
1402        #state 5
1403        data1 = Data2D()
1404        data1.name = "data3"
1405        data1.id = 5
1406        data1.append_empty_process()
1407        process1 = data1.process[len(data1.process)-1]
1408        process1.data = "07/01/2010"
1409        theory1 = Theory1D()
1410        theory1.name = "Cylinder"
1411        path1 = "path2"
1412        state1 = State()
1413        dstate1 = set_data_state(data1, path1, theory1, state1)
1414        theory1 = Theory1D()
1415        theory1.id = 6
1416        theory1.name = "CoreShell"
1417        dstate1.set_theory(theory1)
1418        theory1 = Theory1D()
1419        theory1.id = 6
1420        theory1.name = "CoreShell replacing coreshell in data3"
1421        dstate1.set_theory(theory1)
1422        data_list1['3'] = dstate1
1423        #state 6
1424        data_list1['6'] = set_data_state(None, path1, theory1, state1)
1425        data_list1['6'] = set_data_state(theory=theory1, state=None)
1426        theory1 = Theory1D()
1427        theory1.id = 7
1428        data_list1['6'] = set_data_state(theory=theory1, state=None)
1429        data_list1['7'] = set_data_state(theory=theory1, state=None)
1430        window = DataFrame(list=data_list1)
1431        window.load_data_list(list=data_list1)
1432        window.Show(True)
1433        window.load_data_list(list=temp_data_list)
1434    except:
1435        #raise
1436        print "error", sys.exc_value
1437       
1438    app.MainLoop() 
1439   
1440   
Note: See TracBrowser for help on using the repository browser.