source: sasview/guiframe/data_panel.py @ b461b8fe

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 b461b8fe was 8f19b69, checked in by Gervaise Alina <gervyh@…>, 13 years ago

add switch button to data_panel

  • Property mode set to 100644
File size: 45.6 KB
RevLine 
[3c44c66]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"""
[2a62d5c]13import os
[3c44c66]14import wx
[af7ba61]15# Check version
16toks = wx.__version__.split('.')
17if int(toks[1]) < 9:
[228a8bb]18    if int(toks[2]) < 12:
19        wx_version = 811
20    else:
21        wx_version = 812
[af7ba61]22else:
[228a8bb]23    wx_version = 900
[3c44c66]24import sys
[3feed3e]25import warnings
[13a63ab]26import logging
[3c44c66]27from wx.lib.scrolledpanel import ScrolledPanel
[3feed3e]28import  wx.lib.agw.customtreectrl as CT
29from sans.guiframe.dataFitting import Data1D
30from sans.guiframe.dataFitting import Data2D
[52725d6]31from sans.guiframe.panel_base import PanelBase
[2a62d5c]32from sans.guiframe.events import StatusEvent
[13a63ab]33from sans.guiframe.events import EVT_DELETE_PLOTPANEL
[a03d419]34from sans.guiframe.events import NewLoadDataEvent
[e26d0db]35from sans.guiframe.events import NewPlotEvent
[a03d419]36from sans.guiframe.gui_style import GUIFRAME
[80ddbd0]37from sans.guiframe.events import NewBatchEvent
[2a62d5c]38from DataLoader.loader import Loader
39
40try:
41    # Try to find a local config
42    import imp
43    path = os.getcwd()
44    if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \
45        (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))):
46        fObj, path, descr = imp.find_module('local_config', [path])
47        config = imp.load_module('local_config', fObj, path, descr) 
48    else:
49        # Try simply importing local_config
50        import local_config as config
51except:
52    # Didn't find local config, load the default
53    import config
54 
55extension_list = []
56if config.APPLICATION_STATE_EXTENSION is not None:
57    extension_list.append(config.APPLICATION_STATE_EXTENSION)
58EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list   
[99f9ecf]59PLUGINS_WLIST = config.PLUGINS_WLIST
60APPLICATION_WLIST = config.APPLICATION_WLIST
[3f0c330]61
62#Control panel width
[05ab3f0]63if sys.platform.count("darwin")==0:
[3f0c330]64    PANEL_WIDTH = 235
65    PANEL_HEIGHT = 700
66    CBOX_WIDTH = 140
67    BUTTON_WIDTH = 80
68    FONT_VARIANT = 0
[234a3fa]69    IS_MAC = False
[3f0c330]70else:
71    PANEL_WIDTH = 255
72    PANEL_HEIGHT = 750
73    CBOX_WIDTH = 155
74    BUTTON_WIDTH = 100
75    FONT_VARIANT = 1
[234a3fa]76    IS_MAC = True
[3f0c330]77
[1b1bbf9]78STYLE_FLAG =wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\
[91bdf87]79                    wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT
80                   
81                   
[3feed3e]82class DataTreeCtrl(CT.CustomTreeCtrl):
[3c44c66]83    """
84    Check list control to be used for Data Panel
85    """
[6db811e]86    def __init__(self, parent,*args, **kwds):
[73581ce]87        #agwstyle is introduced in wx.2.8.11 but is not working for mac
[228a8bb]88        if IS_MAC and wx_version < 812:
[91bdf87]89            try:
90                kwds['style'] = STYLE_FLAG
[d34f9f6]91                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
[91bdf87]92            except:
[af7ba61]93                del kwds['style']
[d34f9f6]94                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
[73581ce]95        else:
96            #agwstyle is introduced in wx.2.8.11 .argument working only for windows
97            try:
98                kwds['agwStyle'] = STYLE_FLAG
[d34f9f6]99                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
[73581ce]100            except:
101                try:
[d34f9f6]102                    del kwds['agwStyle']
[73581ce]103                    kwds['style'] = STYLE_FLAG
[d34f9f6]104                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
[73581ce]105                except:
[d34f9f6]106                    del kwds['style']
107                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
[3feed3e]108        self.root = self.AddRoot("Available Data")
[3c44c66]109       
[52725d6]110class DataPanel(ScrolledPanel, PanelBase):
[3c44c66]111    """
112    This panel displays data available in the application and widgets to
113    interact with data.
114    """
[3feed3e]115    ## Internal name for the AUI manager
116    window_name = "Data Panel"
117    ## Title to appear on top of the window
[1b1bbf9]118    window_caption = "Data Explorer"
[3feed3e]119    #type of window
120    window_type = "Data Panel"
121    ## Flag to tell the GUI manager that this panel is not
122    #  tied to any perspective
123    #ALWAYS_ON = True
[600eca2]124    def __init__(self, parent, 
125                 list=None,
[ea4dfe0]126                 size=(PANEL_WIDTH, PANEL_HEIGHT),
127                 list_of_perspective=None, manager=None, *args, **kwds):
[3feed3e]128        kwds['size']= size
[1b1bbf9]129        kwds['style'] = STYLE_FLAG
[3c44c66]130        ScrolledPanel.__init__(self, parent=parent, *args, **kwds)
[52725d6]131        PanelBase.__init__(self)
[3c44c66]132        self.SetupScrolling()
[3f0c330]133        #Set window's font size
134        self.SetWindowVariant(variant=FONT_VARIANT)
[2a62d5c]135        self.loader = Loader() 
136        #Default location
137        self._default_save_location = None 
[ee2b492]138        self.all_data1d = True
[3c44c66]139        self.parent = parent
[3feed3e]140        self.manager = manager
[600eca2]141        if list is None:
142            list = []
[3c44c66]143        self.list_of_data = list
[600eca2]144        if list_of_perspective is None:
145            list_of_perspective = []
[3feed3e]146        self.list_of_perspective = list_of_perspective
147        self.list_rb_perspectives= []
[c70eb7c]148        self.list_cb_data = {}
149        self.list_cb_theory = {}
[61ffd1e]150        self.tree_ctrl = None
151        self.tree_ctrl_theory = None
[600eca2]152        self.perspective_cbox = None
[5e8e615]153       
[3feed3e]154        self.owner = None
155        self.do_layout()
[600eca2]156        self.fill_cbox_analysis(self.list_of_perspective)
[1b1bbf9]157        self.Bind(wx.EVT_SHOW, self.on_close_page)
[13a63ab]158        if self.parent is not None:
159            self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel)
[c31fd9f]160     
[3feed3e]161    def do_layout(self):
[6db811e]162        """
163        """
[3c44c66]164        self.define_panel_structure()
165        self.layout_selection()
[5c4b674]166        self.layout_data_list()
[3c44c66]167        self.layout_button()
[8f19b69]168        self.layout_batch()
[3feed3e]169   
[3c44c66]170    def define_panel_structure(self):
171        """
172        Define the skeleton of the panel
173        """
[3feed3e]174        w, h = self.parent.GetSize()
[3c44c66]175        self.vbox  = wx.BoxSizer(wx.VERTICAL)
176        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
[1b1bbf9]177        self.sizer1.SetMinSize((w/13, h*2/5))
[cc061c3]178     
[3feed3e]179        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
[c6f2291]180        self.sizer3 = wx.FlexGridSizer(7, 2, 4, 1)
[3c44c66]181        self.sizer4 = wx.BoxSizer(wx.HORIZONTAL)
[18ec684]182        self.sizer5 = wx.BoxSizer(wx.VERTICAL)
183       
[2a62d5c]184        self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL,1)
185        self.vbox.Add(self.sizer1, 0, wx.EXPAND|wx.ALL,0)
186        self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL,1)
[026041c]187        self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL,5)
[2a62d5c]188        self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5)
[3feed3e]189       
[3c44c66]190        self.SetSizer(self.vbox)
191       
[3feed3e]192    def layout_selection(self):
[3c44c66]193        """
194        """
[3feed3e]195        select_txt = wx.StaticText(self, -1, 'Selection Options')
[bffa3d0]196        select_txt.SetForegroundColour('blue')
[3feed3e]197        self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
198        list_of_options = ['Select all Data',
199                            'Unselect all Data',
200                           'Select all Data 1D',
201                           'Unselect all Data 1D',
202                           'Select all Data 2D',
203                           'Unselect all Data 2D' ]
204        for option in list_of_options:
205            self.selection_cbox.Append(str(option))
[18ec684]206        self.selection_cbox.SetValue('Select all Data')
[3feed3e]207        wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type)
208        self.sizer5.AddMany([(select_txt,0, wx.ALL,5),
209                            (self.selection_cbox,0, wx.ALL,5)])
[61ffd1e]210        self.enable_selection()
211       
[5e8e615]212   
[3feed3e]213    def _on_selection_type(self, event):
[3c44c66]214        """
[3feed3e]215        Select data according to patterns
[3c44c66]216        """
[18ec684]217       
218        list_of_options = ['Select all Data',
219                            'Unselect all Data',
220                           'Select all Data 1D',
221                           'Unselect all Data 1D',
222                           'Select all Data 2D',
223                           'Unselect all Data 2D' ]
[3feed3e]224        option = self.selection_cbox.GetValue()
[18ec684]225       
226        pos = self.selection_cbox.GetSelection()
227        if pos == wx.NOT_FOUND:
228            return 
229        option = self.selection_cbox.GetString(pos)
[b5e79f7]230        for item in self.list_cb_data.values():
231            data_ctrl, _, _, _,_, _ = item
232            data_id, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 
[18ec684]233            if option == 'Select all Data':
[b5e79f7]234                self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]235            elif option == 'Unselect all Data':
[b5e79f7]236                self.tree_ctrl.CheckItem(data_ctrl, False)
[18ec684]237            elif option == 'Select all Data 1D':
238                if data_class == 'Data1D':
[b5e79f7]239                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]240            elif option == 'Unselect all Data 1D':
[c70eb7c]241                if data_class == 'Data1D':
[b5e79f7]242                    self.tree_ctrl.CheckItem(data_ctrl, False) 
[18ec684]243            elif option == 'Select all Data 1D':
[c70eb7c]244                if data_class == 'Data1D':
[b5e79f7]245                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]246            elif option == 'Select all Data 2D':
247                if data_class == 'Data2D':
[b5e79f7]248                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]249            elif option == 'Unselect all Data 2D':
250                if data_class == 'Data2D':
[b5e79f7]251                    self.tree_ctrl.CheckItem(data_ctrl, False) 
[1e3394f]252        self.enable_append()
253        self.enable_freeze()
254        self.enable_plot()
255        self.enable_import()
[248b918]256        self.enable_remove()
[18ec684]257               
[3c44c66]258    def layout_button(self):
259        """
260        Layout widgets related to buttons
261        """
[ea4dfe0]262        w, _ = self.GetSize()
[a03d419]263       
[2567003]264        self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 
265                                size=(BUTTON_WIDTH, -1))
[c461ebe]266        self.bt_add.SetToolTipString("Load data files")
[2a62d5c]267        wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data)
[c5a769e]268        self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data",
[248b918]269         size=(BUTTON_WIDTH, -1))
[c5a769e]270        self.bt_remove.SetToolTipString("Delete data from the application")
[248b918]271        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove)
[2567003]272        self.bt_import = wx.Button(self, wx.NewId(), "Send To",
273                                    size=(BUTTON_WIDTH, -1))
[3feed3e]274        self.bt_import.SetToolTipString("Send set of Data to active perspective")
[3c44c66]275        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import)
[df58ecab]276        self.perspective_cbox = wx.ComboBox(self, -1,
[600eca2]277                                style=wx.CB_READONLY)
[df58ecab]278        #self.perspective_cbox.SetMinSize((CBOX_WIDTH, -1))
[600eca2]279        wx.EVT_COMBOBOX(self.perspective_cbox,-1, 
280                        self._on_perspective_selection)
281   
[2567003]282        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To",
283                                        size=(BUTTON_WIDTH, -1))
[213892bc]284        self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel")
285        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot)
[3feed3e]286       
[2567003]287        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 
288                                 size=(BUTTON_WIDTH, -1))
[3c44c66]289        self.bt_plot.SetToolTipString("To trigger plotting")
290        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot)
291       
[2567003]292        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 
293                                   size=(BUTTON_WIDTH, -1))
[48665ed]294        self.bt_freeze.SetToolTipString("To trigger freeze a theory")
[c70eb7c]295        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze)
[e26d0db]296        #hide plot
[c5a769e]297        #self.bt_close_plot = wx.Button(self, wx.NewId(), "Delete Plot",
298        #                           size=(BUTTON_WIDTH, -1))
299        #self.bt_close_plot.SetToolTipString("Delete the plot panel on focus")
300        #wx.EVT_BUTTON(self, self.bt_close_plot.GetId(), self.on_close_plot)
[600eca2]301       
[df58ecab]302        self.cb_plotpanel = wx.ComboBox(self, -1, 
[0a2fdca]303                                style=wx.CB_READONLY|wx.CB_SORT)
[df58ecab]304        #self.cb_plotpanel.SetMinSize((CBOX_WIDTH, -1))
[0a2fdca]305        wx.EVT_COMBOBOX(self.cb_plotpanel,-1, self._on_plot_selection)
[5e8e615]306        self.cb_plotpanel.Disable()
[0a2fdca]307
[600eca2]308        self.sizer3.AddMany([(self.bt_add),
309                             ((10, 10)),
[248b918]310                             (self.bt_remove),
311                             ((10, 10)),
[2567003]312                             (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5),
[df58ecab]313                              (self.perspective_cbox, wx.EXPAND|wx.ADJUST_MINSIZE, 5),
[600eca2]314                              (self.bt_append_plot),
[df58ecab]315                              (self.cb_plotpanel, wx.EXPAND|wx.ADJUST_MINSIZE, 5),
[600eca2]316                              (self.bt_plot),
317                              ((10, 10)),
[c461ebe]318                              (self.bt_freeze),
[c5a769e]319                              #((10, 10)),
320                              #(self.bt_close_plot),
[c461ebe]321                              ((10, 10))])
322
[600eca2]323        self.sizer3.AddGrowableCol(1, 1)
[a03d419]324        self.show_data_button()
[248b918]325        self.enable_remove()
[f7d0b74]326        self.enable_import()
327        self.enable_plot()
328        self.enable_append()
329        self.enable_freeze()
[e26d0db]330        self.enable_remove_plot()
[3feed3e]331       
332    def layout_batch(self):
[3c44c66]333        """
334        """
[3feed3e]335        self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode',
336                                             style=wx.RB_GROUP)
337        self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode')
338       
339        self.rb_single_mode.SetValue(True)
340        self.rb_batch_mode.SetValue(False)
341        self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5),
342                            (self.rb_batch_mode,0, wx.ALL,5)])
[80ddbd0]343       
344    def on_single_mode(self, event):
345        """
346        change guiframe to its single mode
347        """
348        if self.parent is not None:
349                wx.PostEvent(self.parent, 
350                             NewBatchEvent(enable=False))
[8f19b69]351       
[80ddbd0]352    def on_batch_mode(self, event):
353        """
354        change guiframe to its batch mode
355        """
356        if self.parent is not None:
357                wx.PostEvent(self.parent, 
358                             NewBatchEvent(enable=True))
[3feed3e]359     
[91bdf87]360    def layout_data_list(self):
[bffa3d0]361        """
362        Add a listcrtl in the panel
363        """
364        tree_ctrl_label = wx.StaticText(self, -1, "Data")
365        tree_ctrl_label.SetForegroundColour('blue')
366        self.tree_ctrl = DataTreeCtrl(parent=self)
367        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
368        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory")
369        tree_ctrl_theory_label.SetForegroundColour('blue')
370        self.tree_ctrl_theory = DataTreeCtrl(parent=self)
371        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
372        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10)
373        self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10)
374        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10)
375        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10)
376           
[3feed3e]377    def onContextMenu(self, event): 
[3c44c66]378        """
[3feed3e]379        Retrieve the state selected state
[3c44c66]380        """
[3feed3e]381        # Skipping the save state functionality for release 0.9.0
382        #return
383        pos = event.GetPosition()
384        pos = self.ScreenToClient(pos)
385        self.PopupMenu(self.popUpMenu, pos) 
386     
[ee2b492]387 
[3feed3e]388    def on_check_item(self, event):
[3c44c66]389        """
390        """
[3feed3e]391        item = event.GetItem()
[ee2b492]392        item.Check(not item.IsChecked()) 
[1e3394f]393        self.enable_append()
394        self.enable_freeze()
395        self.enable_plot()
396        self.enable_import()
[248b918]397        self.enable_remove()
[ee2b492]398        event.Skip()
399       
[600eca2]400    def fill_cbox_analysis(self, plugin):
[ee2b492]401        """
[600eca2]402        fill the combobox with analysis name
[ee2b492]403        """
[600eca2]404        self.list_of_perspective = plugin
405        if self.parent is None or \
406            not hasattr(self.parent, "get_current_perspective") or \
407            len(self.list_of_perspective) == 0:
408            return
409        if self.parent is not None and self.perspective_cbox  is not None:
410            for plug in self.list_of_perspective:
411                if plug.get_perspective():
412                    self.perspective_cbox.Append(plug.sub_menu, plug)
413           
414            curr_pers = self.parent.get_current_perspective()
415            self.perspective_cbox.SetStringSelection(curr_pers.sub_menu)
416        self.enable_import()
417                       
[3feed3e]418    def load_data_list(self, list):
[3c44c66]419        """
[c70eb7c]420        add need data with its theory under the tree
[3c44c66]421        """
[61ffd1e]422        if list:
423            for state_id, dstate in list.iteritems():
424                data = dstate.get_data()
425                theory_list = dstate.get_theory()
426                if data is not None:
[755cac4]427                    data_name = str(data.name)
[61ffd1e]428                    data_class = data.__class__.__name__
429                    path = dstate.get_path() 
430                    process_list = data.process
431                    data_id = data.id
[76703da]432                    s_path = str(path)
[61ffd1e]433                    if state_id not in self.list_cb_data:
434                        #new state
435                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0,
436                                                           data_name, ct_type=1, 
437                                             data=(data_id, data_class, state_id))
438                        data_c.Check(True)
439                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
440                        i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
441                                                      'Type: %s' % data_class)
442                        p_c_c = self.tree_ctrl.AppendItem(d_i_c,
[603fb0f]443                                                      "Path: '%s'" % s_path)
[61ffd1e]444                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
445                       
446                        for process in process_list:
447                            i_t_c = self.tree_ctrl.AppendItem(d_p_c,
448                                                              process.__str__())
449                        theory_child = self.tree_ctrl.AppendItem(data_c, "THEORIES")
450                       
451                        self.list_cb_data[state_id] = [data_c, 
452                                                       d_i_c,
453                                                       i_c_c,
454                                                        p_c_c,
455                                                         d_p_c,
456                                                         theory_child]
457                    else:
458                        data_ctrl_list =  self.list_cb_data[state_id]
459                        #This state is already display replace it contains
460                        data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = data_ctrl_list
461                        self.tree_ctrl.SetItemText(data_c, data_name) 
462                        temp = (data_id, data_class, state_id)
463                        self.tree_ctrl.SetItemPyData(data_c, temp) 
464                        self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % data_class)
[76703da]465                        self.tree_ctrl.SetItemText(p_c_c, 'Path: %s' % s_path) 
[61ffd1e]466                        self.tree_ctrl.DeleteChildren(d_p_c) 
467                        for process in process_list:
468                            i_t_c = self.tree_ctrl.AppendItem(d_p_c,
469                                                              process.__str__())
470                self.append_theory(state_id, theory_list)
[248b918]471        self.enable_remove()
[f7d0b74]472        self.enable_import()
473        self.enable_plot()
474        self.enable_freeze()
[61ffd1e]475        self.enable_selection()
[91bdf87]476       
[48665ed]477    def _uncheck_all(self):
478        """
479        Uncheck all check boxes
480        """
481        for item in self.list_cb_data.values():
482            data_ctrl, _, _, _,_, _ = item
483            self.tree_ctrl.CheckItem(data_ctrl, False) 
[1e3394f]484        self.enable_append()
485        self.enable_freeze()
486        self.enable_plot()
487        self.enable_import()
[248b918]488        self.enable_remove()
[600eca2]489   
[91bdf87]490    def append_theory(self, state_id, theory_list):
[bffa3d0]491        """
492        append theory object under data from a state of id = state_id
493        replace that theory if  already displayed
494        """
495        if not theory_list:
496            return 
497        if state_id not in self.list_cb_data.keys():
498            root = self.tree_ctrl_theory.root
[91bdf87]499            tree = self.tree_ctrl_theory
[bffa3d0]500        else:
501            item = self.list_cb_data[state_id]
502            data_c, _, _, _, _, _ = item
503            root = data_c
[91bdf87]504            tree = self.tree_ctrl
[bffa3d0]505        if root is not None:
[91bdf87]506             self.append_theory_helper(tree=tree, root=root, 
[bffa3d0]507                                       state_id=state_id, 
508                                       theory_list=theory_list)
509     
[71bd773]510     
[91bdf87]511    def append_theory_helper(self, tree, root, state_id, theory_list):
[71bd773]512        """
513        """
514        if state_id in self.list_cb_theory.keys():
[c70eb7c]515            #update current list of theory for this data
[71bd773]516            theory_list_ctrl = self.list_cb_theory[state_id]
[c70eb7c]517
518            for theory_id, item in theory_list.iteritems():
[e88ebfd]519                theory_data, theory_state = item
[c70eb7c]520                if theory_data is None:
521                    name = "Unknown"
522                    theory_class = "Unknown"
523                    theory_id = "Unknown"
524                    temp = (None, None, None)
525                else:
526                    name = theory_data.name
527                    theory_class = theory_data.__class__.__name__
528                    theory_id = theory_data.id
[ee2b492]529                    #if theory_state is not None:
530                    #    name = theory_state.model.name
[c70eb7c]531                    temp = (theory_id, theory_class, state_id)
532                if theory_id not in theory_list_ctrl:
533                    #add new theory
[91bdf87]534                    t_child = tree.AppendItem(root,
[c70eb7c]535                                                    name, ct_type=1, data=temp)
[91bdf87]536                    t_i_c = tree.AppendItem(t_child, 'Info')
537                    i_c_c = tree.AppendItem(t_i_c, 
[c70eb7c]538                                                  'Type: %s' % theory_class)
[91bdf87]539                    t_p_c = tree.AppendItem(t_i_c, 'Process')
[c70eb7c]540                   
541                    for process in theory_data.process:
[91bdf87]542                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]543                                                          process.__str__())
544                    theory_list_ctrl[theory_id] = [t_child, 
545                                                   i_c_c, 
546                                                   t_p_c]
547                else:
548                    #replace theory
549                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
[91bdf87]550                    tree.SetItemText(t_child, name) 
551                    tree.SetItemPyData(t_child, temp) 
552                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
553                    tree.DeleteChildren(t_p_c) 
[c70eb7c]554                    for process in theory_data.process:
[91bdf87]555                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]556                                                          process.__str__())
557             
558        else:
559            #data didn't have a theory associated it before
560            theory_list_ctrl = {}
561            for theory_id, item in theory_list.iteritems():
[e88ebfd]562                theory_data, theory_state = item
[c70eb7c]563                if theory_data is not None:
[e88ebfd]564                    name = theory_data.name
[c70eb7c]565                    theory_class = theory_data.__class__.__name__
[e88ebfd]566                    theory_id = theory_data.id
[ee2b492]567                    #if theory_state is not None:
568                    #    name = theory_state.model.name
[e88ebfd]569                    temp = (theory_id, theory_class, state_id)
[91bdf87]570                    t_child = tree.AppendItem(root,
[e88ebfd]571                            name, ct_type=1, 
[c70eb7c]572                            data=(theory_data.id, theory_class, state_id))
[91bdf87]573                    t_i_c = tree.AppendItem(t_child, 'Info')
574                    i_c_c = tree.AppendItem(t_i_c, 
[c70eb7c]575                                                  'Type: %s' % theory_class)
[91bdf87]576                    t_p_c = tree.AppendItem(t_i_c, 'Process')
[c70eb7c]577                   
578                    for process in theory_data.process:
[91bdf87]579                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]580                                                          process.__str__())
581           
582                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
[71bd773]583                #self.list_cb_theory[data_id] = theory_list_ctrl
584                self.list_cb_theory[state_id] = theory_list_ctrl
[91bdf87]585       
[c70eb7c]586           
[ee2b492]587   
[3feed3e]588    def set_data_helper(self):
[3c44c66]589        """
590        """
[3feed3e]591        data_to_plot = []
[e88ebfd]592        state_to_plot = []
593        theory_to_plot = []
[c70eb7c]594        for value in self.list_cb_data.values():
595            item, _, _, _, _, _ = value
[3feed3e]596            if item.IsChecked():
[3658717e]597                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
598                data_to_plot.append(data_id)
599                if state_id not in state_to_plot:
600                    state_to_plot.append(state_id)
601           
[c70eb7c]602        for theory_dict in self.list_cb_theory.values():
603            for key, value in theory_dict.iteritems():
604                item, _, _ = value
605                if item.IsChecked():
[e88ebfd]606                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
[c70eb7c]607                    theory_to_plot.append(theory_id)
[e88ebfd]608                    if state_id not in state_to_plot:
609                        state_to_plot.append(state_id)
610        return data_to_plot, theory_to_plot, state_to_plot
[3feed3e]611   
[c70eb7c]612    def remove_by_id(self, id):
613        """
614        """
615        for item in self.list_cb_data.values():
616            data_c, _, _, _, _, theory_child = item
617            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
618            if id == data_id:
619                self.tree_ctrl.Delete(data_c)
620                del self.list_cb_data[state_id]
621                del self.list_cb_theory[data_id]
[ae83ad3]622             
[2a62d5c]623    def load_error(self, error=None):
624        """
625        Pop up an error message.
626       
627        :param error: details error message to be displayed
628        """
[8cb8c89]629        if error is not None or str(error).strip() != "":
630            dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File',
[2a62d5c]631                                wx.OK | wx.ICON_EXCLAMATION)
[8cb8c89]632            dial.ShowModal() 
[2a62d5c]633       
634    def _load_data(self, event):
635        """
[a03d419]636        send an event to the parent to trigger load from plugin module
[2a62d5c]637        """
638        if self.parent is not None:
[a03d419]639            wx.PostEvent(self.parent, NewLoadDataEvent())
[2a62d5c]640           
[a03d419]641
[3feed3e]642    def on_remove(self, event):
[18ec684]643        """
[3658717e]644        Get a list of item checked and remove them from the treectrl
645        Ask the parent to remove reference to this item
[18ec684]646        """
[665c083]647        data_to_remove, theory_to_remove, _ = self.set_data_helper()
648        data_key = []
649        theory_key = []
[3658717e]650        #remove  data from treectrl
651        for d_key, item in self.list_cb_data.iteritems():
[665c083]652            data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = item
653            if data_c.IsChecked():
654                self.tree_ctrl.Delete(data_c)
[3658717e]655                data_key.append(d_key)
656                if d_key in self.list_cb_theory.keys():
657                    theory_list_ctrl = self.list_cb_theory[d_key]
658                    theory_to_remove += theory_list_ctrl.keys()
659        # Remove theory from treectrl       
660        for t_key, theory_dict in self.list_cb_theory.iteritems():
661            for  key, value in theory_dict.iteritems():
[665c083]662                item, _, _ = value
663                if item.IsChecked():
[e26d0db]664                    try:
665                        self.tree_ctrl.Delete(item)
666                    except:
667                        pass
[665c083]668                    theory_key.append(key)
[e26d0db]669                   
[3658717e]670        #Remove data and related theory references
[665c083]671        for key in data_key:
672            del self.list_cb_data[key]
[3658717e]673            if key in theory_key:
674                del self.list_cb_theory[key]
675        #remove theory  references independently of data
[665c083]676        for key in theory_key:
[3658717e]677            for t_key, theory_dict in self.list_cb_theory.iteritems():
[71bd773]678                if key in theory_dict:
[e26d0db]679                    for  key, value in theory_dict.iteritems():
680                        item, _, _ = value
681                        if item.IsChecked():
682                            try:
683                                self.tree_ctrl_theory.Delete(item)
684                            except:
685                                pass
[71bd773]686                    del theory_dict[key]
[e26d0db]687                   
[3658717e]688           
[18ec684]689        self.parent.remove_data(data_id=data_to_remove,
[665c083]690                                  theory_id=theory_to_remove)
[248b918]691        self.enable_remove()
[f7d0b74]692        self.enable_freeze()
[e26d0db]693        self.enable_remove_plot()
[3c44c66]694       
[3feed3e]695    def on_import(self, event=None):
[3c44c66]696        """
[3feed3e]697        Get all select data and set them to the current active perspetive
[3c44c66]698        """
[e88ebfd]699        data_id, theory_id, state_id = self.set_data_helper()
[248b918]700        temp = data_id + state_id
701        self.parent.set_data(data_id=temp, theory_id=theory_id)
[e88ebfd]702       
[213892bc]703    def on_append_plot(self, event=None):
704        """
705        append plot to plot panel on focus
706        """
[0a2fdca]707        self._on_plot_selection()
[e88ebfd]708        data_id, theory_id, state_id = self.set_data_helper()
709        self.parent.plot_data(data_id=data_id, 
710                              state_id=state_id,
711                              theory_id=theory_id,
712                              append=True)
[213892bc]713   
[3feed3e]714    def on_plot(self, event=None):
[3c44c66]715        """
[3feed3e]716        Send a list of data names to plot
[3c44c66]717        """
[e88ebfd]718        data_id, theory_id, state_id = self.set_data_helper()
719        self.parent.plot_data(data_id=data_id, 
720                              state_id=state_id,
721                              theory_id=theory_id,
722                              append=False)
[e26d0db]723        self.enable_remove_plot()
[48665ed]724         
[1b1bbf9]725    def on_close_page(self, event=None):
726        """
727        On close
728        """
729        if event != None:
730            event.Skip()
731        # send parent to update menu with no show nor hide action
732        self.parent.show_data_panel(action=False)
733   
[c70eb7c]734    def on_freeze(self, event):
735        """
736        """
[e88ebfd]737        _, theory_id, state_id = self.set_data_helper()
[ee2b492]738        self.parent.freeze(data_id=state_id, theory_id=theory_id)
[c70eb7c]739       
[3feed3e]740    def set_active_perspective(self, name):
[3c44c66]741        """
[3feed3e]742        set the active perspective
[3c44c66]743        """
[600eca2]744        self.perspective_cbox.SetStringSelection(name)
[2a62d5c]745        self.enable_import()
746       
[13a63ab]747    def _on_delete_plot_panel(self, event):
748        """
749        get an event with attribute name and caption to delete existing name
750        from the combobox of the current panel
751        """
752        name = event.name
753        caption = event.caption
754        if self.cb_plotpanel is not None:
755            pos = self.cb_plotpanel.FindString(str(caption)) 
756            if pos != wx.NOT_FOUND:
757                self.cb_plotpanel.Delete(pos)
758        self.enable_append()
759       
[83a75c5]760    def set_panel_on_focus(self, name=None):
[3c44c66]761        """
[3feed3e]762        set the plot panel on focus
[3c44c66]763        """
[0a2fdca]764        for key, value in self.parent.plot_panels.iteritems():
765            name_plot_panel = str(value.window_caption)
766            if name_plot_panel not in self.cb_plotpanel.GetItems():
767                self.cb_plotpanel.Append(name_plot_panel, value)
[83a75c5]768            if name != None and name == name_plot_panel:
769                self.cb_plotpanel.SetStringSelection(name_plot_panel)
770                break
[f7d0b74]771        self.enable_append()
[e26d0db]772        self.enable_remove_plot()
[5e8e615]773       
[600eca2]774    def _on_perspective_selection(self, event=None):
775        """
776        select the current perspective for guiframe
777        """
778        selection = self.perspective_cbox.GetSelection()
779
780        if self.perspective_cbox.GetValue() != 'None':
781            perspective = self.perspective_cbox.GetClientData(selection)
782            perspective.on_perspective(event=None)
783       
[e26d0db]784    def _on_plot_selection(self, event=None):
[0a2fdca]785        """
786        On source combobox selection
787        """
788        if event != None:
789            combo = event.GetEventObject()
[b113128]790            event.Skip()
[0a2fdca]791        else:
792            combo = self.cb_plotpanel
793        selection = combo.GetSelection()
794
795        if combo.GetValue() != 'None':
796            panel = combo.GetClientData(selection)
797            self.parent.on_set_plot_focus(panel)   
[2a62d5c]798           
[e26d0db]799    def on_close_plot(self, event):
800        """
801        clseo the panel on focus
802        """ 
803        self.enable_append()
804        selection = self.cb_plotpanel.GetSelection()
805        if self.cb_plotpanel.GetValue() != 'None':
806            panel = self.cb_plotpanel.GetClientData(selection)
807            if self.parent is not None and panel is not None:
808                wx.PostEvent(self.parent, 
809                             NewPlotEvent(group_id=panel.group_id,
810                                          action="delete"))
811        self.enable_remove_plot()
812       
813    def enable_remove_plot(self):
814        """
815        enable remove plot button if there is a plot panel on focus
816        """
[c5a769e]817        pass
818        #if self.cb_plotpanel.GetCount() == 0:
819        #    self.bt_close_plot.Disable()
820        #else:
821        #    self.bt_close_plot.Enable()
[e26d0db]822           
[2a62d5c]823    def enable_remove(self):
824        """
825        enable or disable remove button
826        """
827        n_t = self.tree_ctrl.GetCount()
828        n_t_t = self.tree_ctrl_theory.GetCount()
829        if n_t + n_t_t <= 0:
830            self.bt_remove.Disable()
831        else:
832            self.bt_remove.Enable()
833           
834    def enable_import(self):
835        """
836        enable or disable send button
837        """
[61ffd1e]838        n_t = 0
839        if self.tree_ctrl != None:
840            n_t = self.tree_ctrl.GetCount()
[600eca2]841        if n_t > 0 and len(self.list_of_perspective) > 0:
842            self.bt_import.Enable()
843        else:
[2a62d5c]844            self.bt_import.Disable()
[600eca2]845        if len(self.list_of_perspective) <= 0 or \
846            self.perspective_cbox.GetValue()  in ["None",
847                                                "No Active Application"]:
848            self.perspective_cbox.Disable()
[2a62d5c]849        else:
[600eca2]850            self.perspective_cbox.Enable()
[f7d0b74]851           
852    def enable_plot(self):
853        """
854        enable or disable plot button
855        """
[600eca2]856        n_t = 0 
857        n_t_t = 0
858        if self.tree_ctrl != None:
859            n_t = self.tree_ctrl.GetCount()
860        if self.tree_ctrl_theory != None:
861            n_t_t = self.tree_ctrl_theory.GetCount()
[f7d0b74]862        if n_t + n_t_t <= 0:
863            self.bt_plot.Disable()
864        else:
865            self.bt_plot.Enable()
[5e8e615]866        self.enable_append()
867       
[f7d0b74]868    def enable_append(self):
869        """
870        enable or disable append button
871        """
[600eca2]872        n_t = 0 
873        n_t_t = 0
874        if self.tree_ctrl != None:
875            n_t = self.tree_ctrl.GetCount()
876        if self.tree_ctrl_theory != None:
877            n_t_t = self.tree_ctrl_theory.GetCount()
878        if n_t + n_t_t <= 0: 
[f7d0b74]879            self.bt_append_plot.Disable()
[600eca2]880            self.cb_plotpanel.Disable()
[5e8e615]881        elif self.cb_plotpanel.GetCount() <= 0:
[600eca2]882                self.cb_plotpanel.Disable()
[5e8e615]883                self.bt_append_plot.Disable()
[f7d0b74]884        else:
885            self.bt_append_plot.Enable()
[df8cc63]886            self.cb_plotpanel.Enable()
[f7d0b74]887           
[1e3394f]888    def check_theory_to_freeze(self):
889        """
890        """
[f7d0b74]891    def enable_freeze(self):
892        """
893        enable or disable the freeze button
894        """
[61ffd1e]895        n_t_t = 0
896        n_l = 0
897        if self.tree_ctrl_theory != None:
898            n_t_t = self.tree_ctrl_theory.GetCount()
[f7d0b74]899        n_l = len(self.list_cb_theory)
[5e8e615]900        if (n_t_t + n_l > 0):
[f7d0b74]901            self.bt_freeze.Enable()
[1e3394f]902        else:
903            self.bt_freeze.Disable()
[f7d0b74]904       
[61ffd1e]905    def enable_selection(self):
906        """
907        enable or disable combobo box selection
908        """
909        n_t = 0
910        n_t_t = 0
911        if self.tree_ctrl != None:
912            n_t = self.tree_ctrl.GetCount()
913        if self.tree_ctrl_theory != None:
914            n_t_t = self.tree_ctrl_theory.GetCount()
915        if n_t + n_t_t > 0 and self.selection_cbox != None:
916            self.selection_cbox.Enable()
917        else:
918            self.selection_cbox.Disable()
919           
[a03d419]920    def show_data_button(self):
921        """
922        show load data and remove data button if
923        dataloader on else hide them
924        """
925        try:
926            gui_style = self.parent.get_style()
927            style = gui_style & GUIFRAME.DATALOADER_ON
928            if style == GUIFRAME.DATALOADER_ON: 
929                #self.bt_remove.Show(True)
930                self.bt_add.Show(True) 
931            else:
932                #self.bt_remove.Hide()
933                self.bt_add.Hide()
934        except: 
935            #self.bt_remove.Hide()
936            self.bt_add.Hide() 
[e26d0db]937   
[60fff67]938
939
940WIDTH = 400
941HEIGHT = 300
942
943
944class DataDialog(wx.Dialog):
945    """
946    Allow file selection at loading time
947    """
948    def __init__(self, data_list, parent=None, text='', *args, **kwds):
949        wx.Dialog.__init__(self, parent, *args, **kwds)
950        self.SetTitle("Data Selection")
951        self.SetSize((WIDTH, HEIGHT))
952        self.list_of_ctrl = []
953        if not data_list:
954            return 
955        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
956        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
957        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
958        self.sizer = wx.GridBagSizer(5, 5)
959        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
960                               size=(WIDTH-20, HEIGHT-50))
961        self._panel.SetupScrolling()
962        self.__do_layout(data_list, text=text)
963       
964    def __do_layout(self, data_list, text=''):
965        """
966        layout the dialog
967        """
968        if not data_list or len(data_list) <= 1:
969            return 
970        #add text
971       
972        text = "Deleting these file reset some panels.\n"
973        text += "Do you want to proceed?\n"
974        text_ctrl = wx.StaticText(self, -1, str(text))
975        self._sizer_txt.Add(text_ctrl)
976        iy = 0
977        ix = 0
978        data_count = 0
979        for (data_name, in_use, sub_menu) in range(len(data_list)):
980            if in_use == True:
981                ctrl_name = wx.StaticBox(self, -1, str(data_name))
982                ctrl_in_use = wx.StaticBox(self, -1, " is used by ")
983                plug_name = str(sub_menu) + "\n"
984                ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)
985                self.sizer.Add(ctrl_name, (iy, ix),
986                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
987                ix += 1
988                self._sizer_button.Add(ctrl_in_use, 1,
989                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
990                ix += 1
991                self._sizer_button.Add(plug_name, 1,
992                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
993            iy += 1
994        self._panel.SetSizer(self.sizer)
995        #add sizer
996        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
997        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
998        self._sizer_button.Add(button_cancel, 0,
999                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1000        button_OK = wx.Button(self, wx.ID_OK, "Ok")
1001        button_OK.SetFocus()
1002        self._sizer_button.Add(button_OK, 0,
1003                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1004        static_line = wx.StaticLine(self, -1)
1005       
1006        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
1007        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
1008        self._sizer_main.Add(self._data_text_ctrl, 0, 
1009                             wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
1010        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
1011        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
1012        self.SetSizer(self._sizer_main)
1013        self.Layout()
1014       
1015    def get_data(self):
1016        """
1017        return the selected data
1018        """
1019        temp = []
1020        for item in self.list_of_ctrl:
1021            cb, data = item
1022            if cb.GetValue():
1023                temp.append(data)
1024        return temp
1025   
1026    def _count_selected_data(self, event):
1027        """
1028        count selected data
1029        """
1030        if event.GetEventObject().GetValue():
1031            self._nb_selected_data += 1
1032        else:
1033            self._nb_selected_data -= 1
1034        select_data_text = " %s Data selected.\n" % str(self._nb_selected_data)
1035        self._data_text_ctrl.SetLabel(select_data_text)
1036        if self._nb_selected_data <= self._max_data:
1037            self._data_text_ctrl.SetForegroundColour('blue')
1038        else:
1039            self._data_text_ctrl.SetForegroundColour('red')
1040       
1041                 
[f7d0b74]1042       
[3c44c66]1043class DataFrame(wx.Frame):
[3feed3e]1044    ## Internal name for the AUI manager
1045    window_name = "Data Panel"
1046    ## Title to appear on top of the window
1047    window_caption = "Data Panel"
1048    ## Flag to tell the GUI manager that this panel is not
1049    #  tied to any perspective
1050    ALWAYS_ON = True
1051   
[ea4dfe0]1052    def __init__(self, parent=None, owner=None, manager=None,size=(300, 800),
[3feed3e]1053                         list_of_perspective=[],list=[], *args, **kwds):
[cc061c3]1054        kwds['size'] = size
[3c44c66]1055        kwds['id'] = -1
[3feed3e]1056        kwds['title']= "Loaded Data"
[3c44c66]1057        wx.Frame.__init__(self, parent=parent, *args, **kwds)
1058        self.parent = parent
1059        self.owner = owner
1060        self.manager = manager
[32c0841]1061        self.panel = DataPanel(parent=self, 
[cc061c3]1062                               #size=size,
[32c0841]1063                               list_of_perspective=list_of_perspective)
[3feed3e]1064     
1065    def load_data_list(self, list=[]):
[3c44c66]1066        """
1067        Fill the list inside its panel
1068        """
[3feed3e]1069        self.panel.load_data_list(list=list)
[3c44c66]1070       
[5e8e615]1071   
[3feed3e]1072   
1073from dataFitting import Data1D
1074from dataFitting import Data2D, Theory1D
1075from data_state import DataState
1076import sys
1077class State():
1078    def __init__(self):
1079        self.msg = ""
1080    def __str__(self):
1081        self.msg = "model mane : model1\n"
1082        self.msg += "params : \n"
1083        self.msg += "name  value\n"
1084        return msg
[71bd773]1085def set_data_state(data=None, path=None, theory=None, state=None):
[3feed3e]1086    dstate = DataState(data=data)
1087    dstate.set_path(path=path)
[c70eb7c]1088    dstate.set_theory(theory, state)
1089 
[3feed3e]1090    return dstate
1091"""'
1092data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"),
1093            ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"),
1094            ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"),
1095            ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"),
1096            ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")]
1097"""     
[3c44c66]1098if __name__ == "__main__":
[3feed3e]1099   
[3c44c66]1100    app = wx.App()
[3feed3e]1101    try:
1102        list_of_perspective = [('perspective2', False), ('perspective1', True)]
1103        data_list = {}
[c70eb7c]1104        # state 1
[ee2b492]1105        data = Data2D()
1106        data.name = "data2"
[584c4c4]1107        data.id = 1
[c70eb7c]1108        data.append_empty_process()
1109        process = data.process[len(data.process)-1]
1110        process.data = "07/01/2010"
[ee2b492]1111        theory = Data2D()
[584c4c4]1112        theory.id = 34
[c70eb7c]1113        theory.name = "theory1"
[3feed3e]1114        path = "path1"
1115        state = State()
1116        data_list['1']=set_data_state(data, path,theory, state)
[c70eb7c]1117        #state 2
[ee2b492]1118        data = Data2D()
[3feed3e]1119        data.name = "data2"
[584c4c4]1120        data.id = 76
[ee2b492]1121        theory = Data2D()
[584c4c4]1122        theory.id = 78
[3feed3e]1123        theory.name = "CoreShell 07/24/25"
1124        path = "path2"
[c70eb7c]1125        #state3
[3feed3e]1126        state = State()
1127        data_list['2']=set_data_state(data, path,theory, state)
1128        data = Data1D()
[584c4c4]1129        data.id = 3
[3feed3e]1130        data.name = "data2"
1131        theory = Theory1D()
1132        theory.name = "CoreShell"
[584c4c4]1133        theory.id = 4
[c70eb7c]1134        theory.append_empty_process()
1135        process = theory.process[len(theory.process)-1]
1136        process.description = "this is my description"
[3feed3e]1137        path = "path3"
[c70eb7c]1138        data.append_empty_process()
1139        process = data.process[len(data.process)-1]
1140        process.data = "07/22/2010"
[3feed3e]1141        data_list['4']=set_data_state(data, path,theory, state)
[c70eb7c]1142        #state 4
1143        temp_data_list = {}
1144        data.name = "data5 erasing data2"
1145        temp_data_list['4'] = set_data_state(data, path,theory, state)
1146        #state 5
[3feed3e]1147        data = Data2D()
1148        data.name = "data3"
[584c4c4]1149        data.id = 5
[c70eb7c]1150        data.append_empty_process()
1151        process = data.process[len(data.process)-1]
1152        process.data = "07/01/2010"
[3feed3e]1153        theory = Theory1D()
[c70eb7c]1154        theory.name = "Cylinder"
[3feed3e]1155        path = "path2"
1156        state = State()
1157        dstate= set_data_state(data, path,theory, state)
1158        theory = Theory1D()
[584c4c4]1159        theory.id = 6
[c70eb7c]1160        theory.name = "CoreShell"
1161        dstate.set_theory(theory)
1162        theory = Theory1D()
1163        theory.id = 6
1164        theory.name = "CoreShell replacing coreshell in data3"
[3feed3e]1165        dstate.set_theory(theory)
[c70eb7c]1166        data_list['3'] = dstate
1167        #state 6
1168        data_list['6']=set_data_state(None, path,theory, state)
[71bd773]1169        data_list['6']=set_data_state(theory=theory, state=None)
1170        theory = Theory1D()
1171        theory.id = 7
1172        data_list['6']=set_data_state(theory=theory, state=None)
1173        data_list['7']=set_data_state(theory=theory, state=None)
[3feed3e]1174        window = DataFrame(list=data_list)
[c70eb7c]1175        window.load_data_list(list=data_list)
[3feed3e]1176        window.Show(True)
[c70eb7c]1177        window.load_data_list(list=temp_data_list)
[3feed3e]1178    except:
1179        #raise
1180        print "error",sys.exc_value
[c70eb7c]1181       
[3c44c66]1182    app.MainLoop() 
1183   
1184   
Note: See TracBrowser for help on using the repository browser.