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

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 6605880 was 6605880, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Fixing code style problems

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