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

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

reducing pylint warnings

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