source: sasview/guiframe/data_panel.py @ 8b6ab2d

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 8b6ab2d was c31fd9f, checked in by Jae Cho <jhjcho@…>, 13 years ago

all scrollwindows: unfocus child when scrolling: wx2.9 bug fix

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