source: sasview/sansguiframe/src/sans/guiframe/data_panel.py @ 5e5704d

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 5e5704d was 5e5704d, checked in by Jae Cho <jhjcho@…>, 12 years ago

data panel: clean up for pylint

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