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

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 28c9e5a was 3603b2e, checked in by Jae Cho <jhjcho@…>, 13 years ago

event skip on import

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