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

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

data_panel: pylint cleanup3

  • 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        data_1 = self.GetItemText(item1)
103        data_2 = self.GetItemText(item2)
104        # Compare the item data
105        if data_1 < data_2:
106            return -1
107        elif data_1 > data_2:
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            _, _ = self.parent.get_data_manager().get_by_id(id_list=[id])
544        except:
545            return
546        if self.data_menu is not None:
547            menu_enable = (data_class_name == "Data2D")
548            self.data_menu.Enable(self.editmask_id, False)
549            self.data_menu.Enable(self.plot3d_id, menu_enable)
550            self.PopupMenu(self.data_menu) 
551                   
552    def on_right_click_data(self, event):
553        """
554        Allow Editing Data
555        """
556        #selection = event.GetSelection()
557        is_data = True
558        try:
559            id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData()
560            data_list, _ = \
561                        self.parent.get_data_manager().get_by_id(id_list=[id])
562            if not data_list:
563                is_data = False
564        except:
565            return
566        if self.data_menu is not None:
567            menu_enable = (data_class_name == "Data2D")
568            maskmenu_enable = (menu_enable and is_data)
569            self.data_menu.Enable(self.editmask_id, maskmenu_enable)
570            self.data_menu.Enable(self.plot3d_id, menu_enable)
571            self.PopupMenu(self.data_menu) 
572       
573    def onContextMenu(self, event): 
574        """
575        Retrieve the state selected state
576        """
577        # Skipping the save state functionality for release 0.9.0
578        #return
579        pos = event.GetPosition()
580        pos = self.ScreenToClient(pos)
581        self.PopupMenu(self.popUpMenu, pos) 
582     
583 
584    def on_check_item(self, event):
585        """
586        On check item
587        """
588        item = event.GetItem()
589        item.Check(not item.IsChecked()) 
590        self.enable_append()
591        self.enable_freeze()
592        self.enable_plot()
593        self.enable_import()
594        self.enable_remove()
595        event.Skip()
596       
597    def fill_cbox_analysis(self, plugin):
598        """
599        fill the combobox with analysis name
600        """
601        self.list_of_perspective = plugin
602        if self.parent is None or \
603            not hasattr(self.parent, "get_current_perspective") or \
604            len(self.list_of_perspective) == 0:
605            return
606        if self.parent is not None and self.perspective_cbox  is not None:
607            for plug in self.list_of_perspective:
608                if plug.get_perspective():
609                    self.perspective_cbox.Append(plug.sub_menu, plug)
610           
611            curr_pers = self.parent.get_current_perspective()
612            if curr_pers:
613                self.perspective_cbox.SetStringSelection(curr_pers.sub_menu)
614                self.enable_import()
615                       
616    def load_data_list(self, list):
617        """
618        add need data with its theory under the tree
619        """
620        if list:
621            for state_id, dstate in list.iteritems():
622                data = dstate.get_data()
623                theory_list = dstate.get_theory()
624                if data is not None:
625                    data_name = str(data.name)
626                    data_title = str(data.title)
627                    data_run = str(data.run)
628                    data_class = data.__class__.__name__
629                    path = dstate.get_path() 
630                    process_list = data.process
631                    data_id = data.id
632                    s_path = str(path)
633                    if state_id not in self.list_cb_data:
634                        #new state
635                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,
636                                        0, data_name, ct_type=1, 
637                                        data=(data_id, data_class, state_id))
638                        data_c.Check(True)
639                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
640                        d_t_c = self.tree_ctrl.AppendItem(d_i_c, 
641                                                      'Title: %s' % data_title)
642                        r_n_c = self.tree_ctrl.AppendItem(d_i_c, 
643                                                      'Run: %s' % data_run)
644                        i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
645                                                      'Type: %s' % data_class)
646                        p_c_c = self.tree_ctrl.AppendItem(d_i_c,
647                                                      "Path: '%s'" % s_path)
648                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
649                       
650                        for process in process_list:
651                            process_str = str(process).replace('\n',' ')
652                            if len(process_str)>20:
653                                process_str = process_str[:20]+' [...]'
654                            self.tree_ctrl.AppendItem(d_p_c, process_str)
655                        theory_child = self.tree_ctrl.AppendItem(data_c, 
656                                                                 "THEORIES")
657                        self.list_cb_data[state_id] = [data_c, 
658                                                       d_i_c,
659                                                       d_t_c,
660                                                       r_n_c,
661                                                       i_c_c,
662                                                       p_c_c,
663                                                       d_p_c,
664                                                       theory_child]
665                    else:
666                        data_ctrl_list =  self.list_cb_data[state_id]
667                        #This state is already display replace it contains
668                        data_c, d_i_c, d_t_c, r_n_c,  i_c_c, p_c_c, d_p_c, _ \
669                                = data_ctrl_list
670                        self.tree_ctrl.SetItemText(data_c, data_name) 
671                        temp = (data_id, data_class, state_id)
672                        self.tree_ctrl.SetItemPyData(data_c, temp) 
673                        self.tree_ctrl.SetItemText(i_c_c, 
674                                                   'Type: %s' % data_class)
675                        self.tree_ctrl.SetItemText(p_c_c, 
676                                                   'Path: %s' % s_path) 
677                        self.tree_ctrl.DeleteChildren(d_p_c) 
678                        for process in process_list:
679                            _ = self.tree_ctrl.AppendItem(d_p_c,
680                                                              process.__str__())
681                wx.CallAfter(self.append_theory, state_id, theory_list)
682            # Sort by data name
683            if self.tree_ctrl.root:
684                self.tree_ctrl.SortChildren(self.tree_ctrl.root)   
685        self.enable_remove()
686        self.enable_import()
687        self.enable_plot()
688        self.enable_freeze()
689        self.enable_selection()
690       
691    def _uncheck_all(self):
692        """
693        Uncheck all check boxes
694        """
695        for item in self.list_cb_data.values():
696            data_ctrl, _, _, _, _, _, _, _ = item
697            self.tree_ctrl.CheckItem(data_ctrl, False) 
698        self.enable_append()
699        self.enable_freeze()
700        self.enable_plot()
701        self.enable_import()
702        self.enable_remove()
703   
704    def append_theory(self, state_id, theory_list):
705        """
706        append theory object under data from a state of id = state_id
707        replace that theory if  already displayed
708        """
709        if not theory_list:
710            return 
711        if state_id not in self.list_cb_data.keys():
712            root = self.tree_ctrl_theory.root
713            tree = self.tree_ctrl_theory
714        else:
715            item = self.list_cb_data[state_id]
716            data_c, _, _, _, _, _, _, _ = item
717            root = data_c
718            tree = self.tree_ctrl
719        if root is not None:
720            wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 
721                                       state_id=state_id, 
722                                       theory_list=theory_list)
723     
724     
725    def append_theory_helper(self, tree, root, state_id, theory_list):
726        """
727        Append theory helper
728        """
729        if state_id in self.list_cb_theory.keys():
730            #update current list of theory for this data
731            theory_list_ctrl = self.list_cb_theory[state_id]
732
733            for theory_id, item in theory_list.iteritems():
734                theory_data, _ = item
735                if theory_data is None:
736                    name = "Unknown"
737                    theory_class = "Unknown"
738                    theory_id = "Unknown"
739                    temp = (None, None, None)
740                else:
741                    name = theory_data.name
742                    theory_class = theory_data.__class__.__name__
743                    theory_id = theory_data.id
744                    #if theory_state is not None:
745                    #    name = theory_state.model.name
746                    temp = (theory_id, theory_class, state_id)
747                if theory_id not in theory_list_ctrl:
748                    #add new theory
749                    t_child = tree.AppendItem(root,
750                                                    name, ct_type=1, data=temp)
751                    t_i_c = tree.AppendItem(t_child, 'Info')
752                    i_c_c = tree.AppendItem(t_i_c, 
753                                                  'Type: %s' % theory_class)
754                    t_p_c = tree.AppendItem(t_i_c, 'Process')
755                   
756                    for process in theory_data.process:
757                        tree.AppendItem(t_p_c, process.__str__())
758                    theory_list_ctrl[theory_id] = [t_child, 
759                                                   i_c_c, 
760                                                   t_p_c]
761                else:
762                    #replace theory
763                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
764                    tree.SetItemText(t_child, name) 
765                    tree.SetItemPyData(t_child, temp) 
766                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
767                    tree.DeleteChildren(t_p_c) 
768                    for process in theory_data.process:
769                        tree.AppendItem(t_p_c, process.__str__())
770             
771        else:
772            #data didn't have a theory associated it before
773            theory_list_ctrl = {}
774            for theory_id, item in theory_list.iteritems():
775                theory_data, _ = item
776                if theory_data is not None:
777                    name = theory_data.name
778                    theory_class = theory_data.__class__.__name__
779                    theory_id = theory_data.id
780                    #if theory_state is not None:
781                    #    name = theory_state.model.name
782                    temp = (theory_id, theory_class, state_id)
783                    t_child = tree.AppendItem(root,
784                            name, ct_type=1, 
785                            data=(theory_data.id, theory_class, state_id))
786                    t_i_c = tree.AppendItem(t_child, 'Info')
787                    i_c_c = tree.AppendItem(t_i_c, 
788                                                  'Type: %s' % theory_class)
789                    t_p_c = tree.AppendItem(t_i_c, 'Process')
790                   
791                    for process in theory_data.process:
792                        tree.AppendItem(t_p_c, process.__str__())
793           
794                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
795                #self.list_cb_theory[data_id] = theory_list_ctrl
796                self.list_cb_theory[state_id] = theory_list_ctrl
797       
798           
799   
800    def set_data_helper(self):
801        """
802        Set data helper
803        """
804        data_to_plot = []
805        state_to_plot = []
806        theory_to_plot = []
807        for value in self.list_cb_data.values():
808            item, _, _, _, _, _, _,  _ = value
809            if item.IsChecked():
810                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
811                data_to_plot.append(data_id)
812                if state_id not in state_to_plot:
813                    state_to_plot.append(state_id)
814           
815        for theory_dict in self.list_cb_theory.values():
816            for _, value in theory_dict.iteritems():
817                item, _, _ = value
818                if item.IsChecked():
819                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
820                    theory_to_plot.append(theory_id)
821                    if state_id not in state_to_plot:
822                        state_to_plot.append(state_id)
823        return data_to_plot, theory_to_plot, state_to_plot
824   
825    def remove_by_id(self, id):
826        """
827        Remove_dat by id
828        """
829        for item in self.list_cb_data.values():
830            data_c, _, _, _, _, _,  _, _ = item
831            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
832            if id == data_id:
833                self.tree_ctrl.Delete(data_c)
834                del self.list_cb_data[state_id]
835                del self.list_cb_theory[data_id]
836             
837    def load_error(self, error=None):
838        """
839        Pop up an error message.
840       
841        :param error: details error message to be displayed
842        """
843        if error is not None or str(error).strip() != "":
844            dial = wx.MessageDialog(self.parent, str(error), 
845                                    'Error Loading File',
846                                    wx.OK | wx.ICON_EXCLAMATION)
847            dial.ShowModal() 
848       
849    def _load_data(self, event):
850        """
851        send an event to the parent to trigger load from plugin module
852        """
853        if self.parent is not None:
854            wx.PostEvent(self.parent, NewLoadDataEvent())
855           
856
857    def on_remove(self, event):
858        """
859        Get a list of item checked and remove them from the treectrl
860        Ask the parent to remove reference to this item
861        """
862        msg = "This operation will delete the data sets checked "
863        msg += "and all the dependents."
864        msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)
865        if msg_box.ShowModal() != wx.ID_OK:
866            return
867       
868        data_to_remove, theory_to_remove, _ = self.set_data_helper()
869        data_key = []
870        theory_key = []
871        #remove  data from treectrl
872        for d_key, item in self.list_cb_data.iteritems():
873            data_c, _, _, _,  _, _, _, _ = item
874            if data_c.IsChecked():
875                self.tree_ctrl.Delete(data_c)
876                data_key.append(d_key)
877                if d_key in self.list_cb_theory.keys():
878                    theory_list_ctrl = self.list_cb_theory[d_key]
879                    theory_to_remove += theory_list_ctrl.keys()
880        # Remove theory from treectrl       
881        for _, theory_dict in self.list_cb_theory.iteritems():
882            for  key, value in theory_dict.iteritems():
883                item, _, _ = value
884                if item.IsChecked():
885                    try:
886                        self.tree_ctrl.Delete(item)
887                    except:
888                        pass
889                    theory_key.append(key)
890                   
891        #Remove data and related theory references
892        for key in data_key:
893            del self.list_cb_data[key]
894            if key in theory_key:
895                del self.list_cb_theory[key]
896        #remove theory  references independently of data
897        for key in theory_key:
898            for _, theory_dict in self.list_cb_theory.iteritems():
899                if key in theory_dict:
900                    for  key, value in theory_dict.iteritems():
901                        item, _, _ = value
902                        if item.IsChecked():
903                            try:
904                                self.tree_ctrl_theory.Delete(item)
905                            except:
906                                pass
907                    del theory_dict[key]
908                   
909           
910        self.parent.remove_data(data_id=data_to_remove,
911                                  theory_id=theory_to_remove)
912        self.enable_remove()
913        self.enable_freeze()
914        self.enable_remove_plot()
915       
916    def on_import(self, event=None):
917        """
918        Get all select data and set them to the current active perspetive
919        """
920        if event != None:
921            event.Skip()
922        data_id, theory_id, state_id = self.set_data_helper()
923        temp = data_id + state_id
924        self.parent.set_data(data_id=temp, theory_id=theory_id)
925       
926    def on_append_plot(self, event=None):
927        """
928        append plot to plot panel on focus
929        """
930        self._on_plot_selection()
931        data_id, theory_id, state_id = self.set_data_helper()
932        self.parent.plot_data(data_id=data_id, 
933                              state_id=state_id,
934                              theory_id=theory_id,
935                              append=True)
936   
937    def on_plot(self, event=None):
938        """
939        Send a list of data names to plot
940        """
941        data_id, theory_id, state_id = self.set_data_helper()
942        self.parent.plot_data(data_id=data_id, 
943                              state_id=state_id,
944                              theory_id=theory_id,
945                              append=False)
946        self.enable_remove_plot()
947         
948    def on_close_page(self, event=None):
949        """
950        On close
951        """
952        if event != None:
953            event.Skip()
954        # send parent to update menu with no show nor hide action
955        self.parent.show_data_panel(action=False)
956   
957    def on_freeze(self, event):
958        """
959        On freeze to make a theory to a data set
960        """
961        _, theory_id, state_id = self.set_data_helper()
962        if len(theory_id) > 0:
963            self.parent.freeze(data_id=state_id, theory_id=theory_id)
964            msg = "Freeze Theory:"
965            msg += " The theory(s) copied to the Data box as a data set."
966        else:
967            msg = "Freeze Theory: Requires at least one theory checked."
968        wx.PostEvent(self.parent, StatusEvent(status=msg))
969           
970    def set_active_perspective(self, name):
971        """
972        set the active perspective
973        """
974        self.perspective_cbox.SetStringSelection(name)
975        self.enable_import()
976       
977    def _on_delete_plot_panel(self, event):
978        """
979        get an event with attribute name and caption to delete existing name
980        from the combobox of the current panel
981        """
982        #name = event.name
983        caption = event.caption
984        if self.cb_plotpanel is not None:
985            pos = self.cb_plotpanel.FindString(str(caption)) 
986            if pos != wx.NOT_FOUND:
987                self.cb_plotpanel.Delete(pos)
988        self.enable_append()
989       
990    def set_panel_on_focus(self, name=None):
991        """
992        set the plot panel on focus
993        """
994        for _, value in self.parent.plot_panels.iteritems():
995            name_plot_panel = str(value.window_caption)
996            if name_plot_panel not in self.cb_plotpanel.GetItems():
997                self.cb_plotpanel.Append(name_plot_panel, value)
998            if name != None and name == name_plot_panel:
999                self.cb_plotpanel.SetStringSelection(name_plot_panel)
1000                break
1001        self.enable_append()
1002        self.enable_remove_plot()
1003       
1004    def _on_perspective_selection(self, event=None):
1005        """
1006        select the current perspective for guiframe
1007        """
1008        selection = self.perspective_cbox.GetSelection()
1009        if self.perspective_cbox.GetValue() != 'None':
1010            perspective = self.perspective_cbox.GetClientData(selection)
1011            perspective.on_perspective(event=None)
1012            self.parent.check_multimode(perspective=perspective)
1013               
1014    def _on_plot_selection(self, event=None):
1015        """
1016        On source combobox selection
1017        """
1018        if event != None:
1019            combo = event.GetEventObject()
1020            event.Skip()
1021        else:
1022            combo = self.cb_plotpanel
1023        selection = combo.GetSelection()
1024
1025        if combo.GetValue() != 'None':
1026            panel = combo.GetClientData(selection)
1027            self.parent.on_set_plot_focus(panel)   
1028           
1029    def on_close_plot(self, event):
1030        """
1031        clseo the panel on focus
1032        """ 
1033        self.enable_append()
1034        selection = self.cb_plotpanel.GetSelection()
1035        if self.cb_plotpanel.GetValue() != 'None':
1036            panel = self.cb_plotpanel.GetClientData(selection)
1037            if self.parent is not None and panel is not None:
1038                wx.PostEvent(self.parent, 
1039                             NewPlotEvent(group_id=panel.group_id,
1040                                          action="delete"))
1041        self.enable_remove_plot()
1042       
1043    def enable_remove_plot(self):
1044        """
1045        enable remove plot button if there is a plot panel on focus
1046        """
1047        pass
1048        #if self.cb_plotpanel.GetCount() == 0:
1049        #    self.bt_close_plot.Disable()
1050        #else:
1051        #    self.bt_close_plot.Enable()
1052           
1053    def enable_remove(self):
1054        """
1055        enable or disable remove button
1056        """
1057        n_t = self.tree_ctrl.GetCount()
1058        n_t_t = self.tree_ctrl_theory.GetCount()
1059        if n_t + n_t_t <= 0:
1060            self.bt_remove.Disable()
1061        else:
1062            self.bt_remove.Enable()
1063           
1064    def enable_import(self):
1065        """
1066        enable or disable send button
1067        """
1068        n_t = 0
1069        if self.tree_ctrl != None:
1070            n_t = self.tree_ctrl.GetCount()
1071        if n_t > 0 and len(self.list_of_perspective) > 0:
1072            self.bt_import.Enable()
1073        else:
1074            self.bt_import.Disable()
1075        if len(self.list_of_perspective) <= 0 or \
1076            self.perspective_cbox.GetValue()  in ["None",
1077                                                "No Active Application"]:
1078            self.perspective_cbox.Disable()
1079        else:
1080            self.perspective_cbox.Enable()
1081           
1082    def enable_plot(self):
1083        """
1084        enable or disable plot button
1085        """
1086        n_t = 0 
1087        n_t_t = 0
1088        if self.tree_ctrl != None:
1089            n_t = self.tree_ctrl.GetCount()
1090        if self.tree_ctrl_theory != None:
1091            n_t_t = self.tree_ctrl_theory.GetCount()
1092        if n_t + n_t_t <= 0:
1093            self.bt_plot.Disable()
1094        else:
1095            self.bt_plot.Enable()
1096        self.enable_append()
1097       
1098    def enable_append(self):
1099        """
1100        enable or disable append button
1101        """
1102        n_t = 0 
1103        n_t_t = 0
1104        if self.tree_ctrl != None:
1105            n_t = self.tree_ctrl.GetCount()
1106        if self.tree_ctrl_theory != None:
1107            n_t_t = self.tree_ctrl_theory.GetCount()
1108        if n_t + n_t_t <= 0: 
1109            self.bt_append_plot.Disable()
1110            self.cb_plotpanel.Disable()
1111        elif self.cb_plotpanel.GetCount() <= 0:
1112            self.cb_plotpanel.Disable()
1113            self.bt_append_plot.Disable()
1114        else:
1115            self.bt_append_plot.Enable()
1116            self.cb_plotpanel.Enable()
1117           
1118    def check_theory_to_freeze(self):
1119        """
1120        Check_theory_to_freeze
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 Theory1D
1291from sans.guiframe.data_state import DataState
1292
1293class State():
1294    """
1295    DataPanel State
1296    """
1297    def __init__(self):
1298        self.msg = ""
1299    def __str__(self):
1300        self.msg = "model mane : model1\n"
1301        self.msg += "params : \n"
1302        self.msg += "name  value\n"
1303        return self.msg
1304   
1305def set_data_state(data=None, path=None, theory=None, state=None):
1306    """
1307    Set data state
1308    """
1309    dstate = DataState(data=data)
1310    dstate.set_path(path=path)
1311    dstate.set_theory(theory, state)
1312 
1313    return dstate
1314   
1315if __name__ == "__main__":
1316   
1317    app = wx.App()
1318    try:
1319        #list_of_perspective = [('perspective2', False), ('perspective1', True)]
1320        data_list1 = {}
1321        # state 1
1322        data1 = Data2D()
1323        data1.name = "data2"
1324        data1.id = 1
1325        data1.append_empty_process()
1326        process1 = data1.process[len(data1.process)-1]
1327        process1.data = "07/01/2010"
1328        theory1 = Data2D()
1329        theory1.id = 34
1330        theory1.name = "theory1"
1331        path1 = "path1"
1332        state1 = State()
1333        data_list1['1'] = set_data_state(data1, path1, theory1, state1)
1334        #state 2
1335        data1 = Data2D()
1336        data1.name = "data2"
1337        data1.id = 76
1338        theory1 = Data2D()
1339        theory1.id = 78
1340        theory1.name = "CoreShell 07/24/25"
1341        path1 = "path2"
1342        #state3
1343        state1 = State()
1344        data_list1['2'] = set_data_state(data1, path1, theory1, state1)
1345        data1 = Data1D()
1346        data1.id = 3
1347        data1.name = "data2"
1348        theory1 = Theory1D()
1349        theory1.name = "CoreShell"
1350        theory1.id = 4
1351        theory1.append_empty_process()
1352        process1 = theory1.process[len(theory1.process)-1]
1353        process1.description = "this is my description"
1354        path1 = "path3"
1355        data1.append_empty_process()
1356        process1 = data1.process[len(data1.process)-1]
1357        process1.data = "07/22/2010"
1358        data_list1['4'] = set_data_state(data1, path1, theory1, state1)
1359        #state 4
1360        temp_data_list = {}
1361        data1.name = "data5 erasing data2"
1362        temp_data_list['4'] = set_data_state(data1, path1, theory1, state1)
1363        #state 5
1364        data1 = Data2D()
1365        data1.name = "data3"
1366        data1.id = 5
1367        data1.append_empty_process()
1368        process1 = data1.process[len(data1.process)-1]
1369        process1.data = "07/01/2010"
1370        theory1 = Theory1D()
1371        theory1.name = "Cylinder"
1372        path1 = "path2"
1373        state1 = State()
1374        dstate1 = set_data_state(data1, path1, theory1, state1)
1375        theory1 = Theory1D()
1376        theory1.id = 6
1377        theory1.name = "CoreShell"
1378        dstate1.set_theory(theory1)
1379        theory1 = Theory1D()
1380        theory1.id = 6
1381        theory1.name = "CoreShell replacing coreshell in data3"
1382        dstate1.set_theory(theory1)
1383        data_list1['3'] = dstate1
1384        #state 6
1385        data_list1['6'] = set_data_state(None, path1, theory1, state1)
1386        data_list1['6'] = set_data_state(theory=theory1, state=None)
1387        theory1 = Theory1D()
1388        theory1.id = 7
1389        data_list1['6'] = set_data_state(theory=theory1, state=None)
1390        data_list1['7'] = set_data_state(theory=theory1, state=None)
1391        window = DataFrame(list=data_list1)
1392        window.load_data_list(list=data_list1)
1393        window.Show(True)
1394        window.load_data_list(list=temp_data_list)
1395    except:
1396        #raise
1397        print "error", sys.exc_value
1398       
1399    app.MainLoop() 
1400   
1401   
Note: See TracBrowser for help on using the repository browser.