source: sasview/guiframe/data_panel.py @ dc7e46ac

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 dc7e46ac was 6d727ae, checked in by Jae Cho <jhjcho@…>, 14 years ago

moving a new feature (fast reacting plot panels) from branch

  • Property mode set to 100644
File size: 32.2 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"""
13import wx
14import sys
[3feed3e]15import warnings
[3c44c66]16from wx.lib.scrolledpanel import ScrolledPanel
[3feed3e]17import  wx.lib.agw.customtreectrl as CT
18from sans.guiframe.dataFitting import Data1D
19from sans.guiframe.dataFitting import Data2D
[52725d6]20from sans.guiframe.panel_base import PanelBase
[3feed3e]21
22PANEL_WIDTH = 200
[5c4b674]23#PANEL_HEIGHT = 560
[6d727ae]24PANEL_HEIGHT = 840
[91bdf87]25STYLE_FLAG = wx.SUNKEN_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\
26                    wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT
27                   
28                   
[3feed3e]29class DataTreeCtrl(CT.CustomTreeCtrl):
[3c44c66]30    """
31    Check list control to be used for Data Panel
32    """
[6db811e]33    def __init__(self, parent,*args, **kwds):
[be56c8c]34        #agwstyle is introduced in wx.2.8.11
[91bdf87]35        try:
36            kwds['agwStyle'] = STYLE_FLAG
37        except:
38            try:
39                kwds['style'] = STYLE_FLAG
40            except:
41                raise
42       
[3feed3e]43        CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
44        self.root = self.AddRoot("Available Data")
[3c44c66]45       
[52725d6]46class DataPanel(ScrolledPanel, PanelBase):
[3c44c66]47    """
48    This panel displays data available in the application and widgets to
49    interact with data.
50    """
[3feed3e]51    ## Internal name for the AUI manager
52    window_name = "Data Panel"
53    ## Title to appear on top of the window
54    window_caption = "Data Panel"
55    #type of window
56    window_type = "Data Panel"
57    ## Flag to tell the GUI manager that this panel is not
58    #  tied to any perspective
59    #ALWAYS_ON = True
60    def __init__(self, parent, list=[],list_of_perspective=[],
[5c4b674]61                 size=(PANEL_WIDTH,PANEL_HEIGHT), manager=None, *args, **kwds):
[3feed3e]62        kwds['size']= size
[3c44c66]63        ScrolledPanel.__init__(self, parent=parent, *args, **kwds)
[52725d6]64        PanelBase.__init__(self)
[3c44c66]65        self.SetupScrolling()
[ee2b492]66        self.all_data1d = True
[3c44c66]67        self.parent = parent
[3feed3e]68        self.manager = manager
[3c44c66]69        self.list_of_data = list
[3feed3e]70        self.list_of_perspective = list_of_perspective
71        self.list_rb_perspectives= []
[c70eb7c]72        self.list_cb_data = {}
73        self.list_cb_theory = {}
74       
[3feed3e]75        self.owner = None
76        self.do_layout()
[6db811e]77       
[3feed3e]78    def do_layout(self):
[6db811e]79        """
80        """
[3c44c66]81        self.define_panel_structure()
82        self.layout_selection()
[5c4b674]83        self.layout_data_list()
[3c44c66]84        self.layout_button()
[3feed3e]85        self.layout_batch()
86   
[3c44c66]87    def define_panel_structure(self):
88        """
89        Define the skeleton of the panel
90        """
[3feed3e]91        w, h = self.parent.GetSize()
[3c44c66]92        self.vbox  = wx.BoxSizer(wx.VERTICAL)
93        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
[cc061c3]94        self.sizer1.SetMinSize((w/12, h*2/5))
95     
[3feed3e]96        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
97        self.sizer3 = wx.GridBagSizer(5,5)
[3c44c66]98        self.sizer4 = wx.BoxSizer(wx.HORIZONTAL)
[18ec684]99        self.sizer5 = wx.BoxSizer(wx.VERTICAL)
100       
[3feed3e]101        self.vbox.Add(self.sizer5, 0,wx.EXPAND|wx.ALL,10)
102        self.vbox.Add(self.sizer1, 0,wx.EXPAND|wx.ALL,0)
103        self.vbox.Add(self.sizer2, 0,wx.EXPAND|wx.ALL,10)
104        self.vbox.Add(self.sizer3, 0,wx.EXPAND|wx.ALL,10)
105        self.vbox.Add(self.sizer4, 0,wx.EXPAND|wx.ALL,10)
106       
[3c44c66]107        self.SetSizer(self.vbox)
108       
[3feed3e]109    def layout_selection(self):
[3c44c66]110        """
111        """
[3feed3e]112        select_txt = wx.StaticText(self, -1, 'Selection Options')
[bffa3d0]113        select_txt.SetForegroundColour('blue')
[3feed3e]114        self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
115        list_of_options = ['Select all Data',
116                            'Unselect all Data',
117                           'Select all Data 1D',
118                           'Unselect all Data 1D',
119                           'Select all Data 2D',
120                           'Unselect all Data 2D' ]
121        for option in list_of_options:
122            self.selection_cbox.Append(str(option))
[18ec684]123        self.selection_cbox.SetValue('Select all Data')
[3feed3e]124        wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type)
125        self.sizer5.AddMany([(select_txt,0, wx.ALL,5),
126                            (self.selection_cbox,0, wx.ALL,5)])
127    def layout_perspective(self, list_of_perspective=[]):
[3c44c66]128        """
129        Layout widgets related to the list of plug-ins of the gui_manager
130        """
[3feed3e]131        if len(list_of_perspective)==0:
132            return
133        w, h = self.parent.GetSize()
134        box_description_2= wx.StaticBox(self, -1, "Set Active Perspective")
135        self.boxsizer_2 = wx.StaticBoxSizer(box_description_2, wx.HORIZONTAL)
136        self.sizer_perspective = wx.GridBagSizer(5,5)
137        self.boxsizer_2.Add(self.sizer_perspective)
138        self.sizer2.Add(self.boxsizer_2,1, wx.ALL, 10)
139        self.list_of_perspective = list_of_perspective
140        self.sizer_perspective.Clear(True)
141        self.list_rb_perspectives = []
142       
143        nb_active_perspective = 0
[3c44c66]144        if list_of_perspective:
145            ix = 0 
146            iy = 0
[3feed3e]147            for perspective_name, is_active in list_of_perspective:
148               
149                if is_active:
150                    nb_active_perspective += 1
151                if nb_active_perspective == 1:
[ea5692d]152                    rb = wx.RadioButton(self, -1, perspective_name,
153                                        style=wx.RB_GROUP)
[3feed3e]154                    rb.SetToolTipString("Data will be applied to this perspective")
155                    rb.SetValue(is_active)
156                else:
157                    rb = wx.RadioButton(self, -1, perspective_name)
158                    rb.SetToolTipString("Data will be applied to this perspective")
159                    #only one perpesctive can be active
160                    rb.SetValue(False)
161               
162                self.Bind(wx.EVT_RADIOBUTTON, self.on_set_active_perspective,
163                                                     id=rb.GetId())
164                self.list_rb_perspectives.append(rb)
165                self.sizer_perspective.Add(rb,(iy, ix),(1,1),
166                               wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
[3c44c66]167                iy += 1
168        else:
169            rb = wx.RadioButton(self, -1, 'No Perspective',
170                                                      style=wx.RB_GROUP)
171            rb.SetValue(True)
172            rb.Disable()
173            ix = 0 
174            iy = 0
[3feed3e]175            self.sizer_perspective.Add(rb,(iy, ix),(1,1),
[3c44c66]176                           wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)
[3feed3e]177           
178    def _on_selection_type(self, event):
[3c44c66]179        """
[3feed3e]180        Select data according to patterns
[3c44c66]181        """
[18ec684]182       
183        list_of_options = ['Select all Data',
184                            'Unselect all Data',
185                           'Select all Data 1D',
186                           'Unselect all Data 1D',
187                           'Select all Data 2D',
188                           'Unselect all Data 2D' ]
[3feed3e]189        option = self.selection_cbox.GetValue()
[18ec684]190       
191        pos = self.selection_cbox.GetSelection()
192        if pos == wx.NOT_FOUND:
193            return 
194        option = self.selection_cbox.GetString(pos)
[b5e79f7]195        for item in self.list_cb_data.values():
196            data_ctrl, _, _, _,_, _ = item
197            data_id, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 
[18ec684]198            if option == 'Select all Data':
[b5e79f7]199                self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]200            elif option == 'Unselect all Data':
[b5e79f7]201                self.tree_ctrl.CheckItem(data_ctrl, False)
[18ec684]202            elif option == 'Select all Data 1D':
203                if data_class == 'Data1D':
[b5e79f7]204                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]205            elif option == 'Unselect all Data 1D':
[c70eb7c]206                if data_class == 'Data1D':
[b5e79f7]207                    self.tree_ctrl.CheckItem(data_ctrl, False) 
[18ec684]208            elif option == 'Select all Data 1D':
[c70eb7c]209                if data_class == 'Data1D':
[b5e79f7]210                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]211            elif option == 'Select all Data 2D':
212                if data_class == 'Data2D':
[b5e79f7]213                    self.tree_ctrl.CheckItem(data_ctrl, True) 
[18ec684]214            elif option == 'Unselect all Data 2D':
215                if data_class == 'Data2D':
[b5e79f7]216                    self.tree_ctrl.CheckItem(data_ctrl, False) 
[18ec684]217               
[3feed3e]218    def on_set_active_perspective(self, event):
[3c44c66]219        """
[3feed3e]220        Select the active perspective
221        """
222        ctrl = event.GetEventObject()
[3c44c66]223       
224    def layout_button(self):
225        """
226        Layout widgets related to buttons
227        """
[3feed3e]228        self.bt_import = wx.Button(self, wx.NewId(), "Send To")
229        self.bt_import.SetToolTipString("Send set of Data to active perspective")
[3c44c66]230        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import)
231       
[3feed3e]232        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To")
[213892bc]233        self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel")
234        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot)
[3feed3e]235       
236        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot")
[3c44c66]237        self.bt_plot.SetToolTipString("To trigger plotting")
238        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot)
239       
[c70eb7c]240        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze")
241        self.bt_freeze.SetToolTipString("To trigger freeze")
242        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze)
243       
[d828481]244        self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data")
245        self.bt_remove.SetToolTipString("Remove data from the application")
[3feed3e]246        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove)
247       
[c5e84fb]248        self.tctrl_perspective = wx.StaticText(self, -1, 'No Active Application')
[3feed3e]249        self.tctrl_perspective.SetToolTipString("Active Application")
[213892bc]250        self.tctrl_plotpanel = wx.StaticText(self, -1, 'No Plot panel on focus')
251        self.tctrl_plotpanel.SetToolTipString("Active Plot Panel")
[18ec684]252   
[3feed3e]253        ix = 0
254        iy = 0
255        self.sizer3.Add(self.bt_import,( iy, ix),(1,1), 
256                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
257        ix += 1
258        self.sizer3.Add(self.tctrl_perspective,(iy, ix),(1,1),
259                          wx.EXPAND|wx.ADJUST_MINSIZE, 0)     
260        ix = 0         
261        iy += 1 
262        self.sizer3.Add(self.bt_append_plot,( iy, ix),(1,1), 
263                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
264        ix += 1
265        self.sizer3.Add(self.tctrl_plotpanel,(iy, ix),(1,1),
266                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
267        ix = 0         
268        iy += 1 
269        self.sizer3.Add(self.bt_plot,( iy, ix),(1,1), 
270                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
271        ix = 0         
272        iy += 1 
[c70eb7c]273        self.sizer3.Add(self.bt_freeze,( iy, ix),(1,1), 
274                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
275        ix = 0         
276        iy += 1 
[3feed3e]277        self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), 
278                             wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
279       
[18ec684]280       
[3feed3e]281     
282    def layout_batch(self):
[3c44c66]283        """
284        """
[3feed3e]285       
286        self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode',
287                                             style=wx.RB_GROUP)
288        self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode')
289       
290        self.rb_single_mode.SetValue(True)
291        self.rb_batch_mode.SetValue(False)
292        self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5),
293                            (self.rb_batch_mode,0, wx.ALL,5)])
294     
[91bdf87]295    def old_layout_data_list(self):
[3c44c66]296        """
[3feed3e]297        Add a listcrtl in the panel
[3c44c66]298        """
[6db811e]299        self.tree_ctrl = DataTreeCtrl(parent=self)
[ee2b492]300        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
[ea5692d]301        self.sizer1.Add(self.tree_ctrl,1, wx.EXPAND|wx.ALL, 10)
[71bd773]302        self.theory_root = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0,
303                                                   "THEORIES", ct_type=0)
[bffa3d0]304   
[91bdf87]305    def layout_data_list(self):
[bffa3d0]306        """
307        Add a listcrtl in the panel
308        """
309        tree_ctrl_label = wx.StaticText(self, -1, "Data")
310        tree_ctrl_label.SetForegroundColour('blue')
311        self.tree_ctrl = DataTreeCtrl(parent=self)
312        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
313        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory")
314        tree_ctrl_theory_label.SetForegroundColour('blue')
315        self.tree_ctrl_theory = DataTreeCtrl(parent=self)
316        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
317        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10)
318        self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10)
319        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10)
320        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10)
321           
[3feed3e]322    def onContextMenu(self, event): 
[3c44c66]323        """
[3feed3e]324        Retrieve the state selected state
[3c44c66]325        """
[3feed3e]326        # Skipping the save state functionality for release 0.9.0
327        #return
328        pos = event.GetPosition()
329        pos = self.ScreenToClient(pos)
330        self.PopupMenu(self.popUpMenu, pos) 
331     
[ee2b492]332 
[3feed3e]333    def on_check_item(self, event):
[3c44c66]334        """
335        """
[3feed3e]336        item = event.GetItem()
[ee2b492]337        item.Check(not item.IsChecked()) 
338        self.enable_button(item)
339        event.Skip()
340       
341    def enable_button(self, item):
342        """
343        """
344        _, data_class, _= self.tree_ctrl.GetItemPyData(item) 
345        if item.IsChecked():
346            self.all_data1d &= (data_class != "Data2D")
347            if self.all_data1d:
348                self.bt_freeze.Enable()
349            else:
350                self.bt_freeze.Disable()
351        else:
352            self.all_data1d |= True
353            self.all_data1d &= (data_class != "Data2D")
354            if self.all_data1d:
355                self.bt_freeze.Enable()
356            else:
357                self.bt_freeze.Disable()
358               
[3feed3e]359    def load_data_list(self, list):
[3c44c66]360        """
[c70eb7c]361        add need data with its theory under the tree
[3c44c66]362        """
[3feed3e]363        if not list:
364            return
[3c44c66]365       
[c70eb7c]366        for state_id, dstate in list.iteritems():
[3feed3e]367            data = dstate.get_data()
[71bd773]368            theory_list = dstate.get_theory()
369            if data is not None:
[3feed3e]370                data_name = data.name
[c70eb7c]371                data_class = data.__class__.__name__
372                path = dstate.get_path() 
373                process_list = data.process
374                data_id = data.id
[3feed3e]375               
[71bd773]376                if state_id not in self.list_cb_data:
377                    #new state
378                    data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0,
379                                                       data_name, ct_type=1, 
380                                         data=(data_id, data_class, state_id))
381                    data_c.Check(True)
382                    self.enable_button(data_c)
383                    d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
384                    i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
385                                                  'Type: %s' % data_class)
386                    p_c_c = self.tree_ctrl.AppendItem(d_i_c,
387                                                  'Path: %s' % str(path))
388                    d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
389                   
390                    for process in process_list:
391                        i_t_c = self.tree_ctrl.AppendItem(d_p_c,
392                                                          process.__str__())
393                    theory_child = self.tree_ctrl.AppendItem(data_c, "THEORIES")
394                   
395                    self.list_cb_data[state_id] = [data_c, 
396                                                   d_i_c,
397                                                   i_c_c,
398                                                    p_c_c,
399                                                     d_p_c,
400                                                     theory_child]
401                else:
402                    data_ctrl_list =  self.list_cb_data[state_id]
403                    #This state is already display replace it contains
404                    data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = data_ctrl_list
405                    self.tree_ctrl.SetItemText(data_c, data_name) 
406                    temp = (data_id, data_class, state_id)
407                    self.tree_ctrl.SetItemPyData(data_c, temp) 
408                    self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % data_class)
409                    self.tree_ctrl.SetItemText(p_c_c, 'Path: %s' % str(path)) 
410                    self.tree_ctrl.DeleteChildren(d_p_c) 
411                    for process in process_list:
412                        i_t_c = self.tree_ctrl.AppendItem(d_p_c,
413                                                          process.__str__())
[c70eb7c]414            self.append_theory(state_id, theory_list)
[91bdf87]415       
[c70eb7c]416   
[91bdf87]417    def old_append_theory(self, state_id, theory_list):
[c70eb7c]418        """
419        append theory object under data from a state of id = state_id
420        replace that theory if  already displayed
421        """
422        if not theory_list:
423            return 
424        if state_id not in self.list_cb_data.keys():
[71bd773]425            root = self.theory_root
426        else:
427            item = self.list_cb_data[state_id]
428            data_c, _, _, _, _, _ = item
429            root = data_c
430        if root is not None:
431             self.append_theory_helper(root=root, 
432                                       state_id=state_id, 
433                                       theory_list=theory_list)
[91bdf87]434    def append_theory(self, state_id, theory_list):
[bffa3d0]435        """
436        append theory object under data from a state of id = state_id
437        replace that theory if  already displayed
438        """
439        if not theory_list:
440            return 
441        if state_id not in self.list_cb_data.keys():
442            root = self.tree_ctrl_theory.root
[91bdf87]443            tree = self.tree_ctrl_theory
[bffa3d0]444        else:
445            item = self.list_cb_data[state_id]
446            data_c, _, _, _, _, _ = item
447            root = data_c
[91bdf87]448            tree = self.tree_ctrl
[bffa3d0]449        if root is not None:
[91bdf87]450             self.append_theory_helper(tree=tree, root=root, 
[bffa3d0]451                                       state_id=state_id, 
452                                       theory_list=theory_list)
453     
[71bd773]454     
[91bdf87]455    def append_theory_helper(self, tree, root, state_id, theory_list):
[71bd773]456        """
457        """
458        if state_id in self.list_cb_theory.keys():
[c70eb7c]459            #update current list of theory for this data
[71bd773]460            theory_list_ctrl = self.list_cb_theory[state_id]
[c70eb7c]461
462            for theory_id, item in theory_list.iteritems():
[e88ebfd]463                theory_data, theory_state = item
[c70eb7c]464                if theory_data is None:
465                    name = "Unknown"
466                    theory_class = "Unknown"
467                    theory_id = "Unknown"
468                    temp = (None, None, None)
469                else:
470                    name = theory_data.name
471                    theory_class = theory_data.__class__.__name__
472                    theory_id = theory_data.id
[ee2b492]473                    #if theory_state is not None:
474                    #    name = theory_state.model.name
[c70eb7c]475                    temp = (theory_id, theory_class, state_id)
476                if theory_id not in theory_list_ctrl:
477                    #add new theory
[91bdf87]478                    t_child = tree.AppendItem(root,
[c70eb7c]479                                                    name, ct_type=1, data=temp)
[91bdf87]480                    t_i_c = tree.AppendItem(t_child, 'Info')
481                    i_c_c = tree.AppendItem(t_i_c, 
[c70eb7c]482                                                  'Type: %s' % theory_class)
[91bdf87]483                    t_p_c = tree.AppendItem(t_i_c, 'Process')
[c70eb7c]484                   
485                    for process in theory_data.process:
[91bdf87]486                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]487                                                          process.__str__())
488                    theory_list_ctrl[theory_id] = [t_child, 
489                                                   i_c_c, 
490                                                   t_p_c]
491                else:
492                    #replace theory
493                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
[91bdf87]494                    tree.SetItemText(t_child, name) 
495                    tree.SetItemPyData(t_child, temp) 
496                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
497                    tree.DeleteChildren(t_p_c) 
[c70eb7c]498                    for process in theory_data.process:
[91bdf87]499                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]500                                                          process.__str__())
501             
502        else:
503            #data didn't have a theory associated it before
504            theory_list_ctrl = {}
505            for theory_id, item in theory_list.iteritems():
[e88ebfd]506                theory_data, theory_state = item
[c70eb7c]507                if theory_data is not None:
[e88ebfd]508                    name = theory_data.name
[c70eb7c]509                    theory_class = theory_data.__class__.__name__
[e88ebfd]510                    theory_id = theory_data.id
[ee2b492]511                    #if theory_state is not None:
512                    #    name = theory_state.model.name
[e88ebfd]513                    temp = (theory_id, theory_class, state_id)
[91bdf87]514                    t_child = tree.AppendItem(root,
[e88ebfd]515                            name, ct_type=1, 
[c70eb7c]516                            data=(theory_data.id, theory_class, state_id))
[91bdf87]517                    t_i_c = tree.AppendItem(t_child, 'Info')
518                    i_c_c = tree.AppendItem(t_i_c, 
[c70eb7c]519                                                  'Type: %s' % theory_class)
[91bdf87]520                    t_p_c = tree.AppendItem(t_i_c, 'Process')
[c70eb7c]521                   
522                    for process in theory_data.process:
[91bdf87]523                        i_t_c = tree.AppendItem(t_p_c,
[c70eb7c]524                                                          process.__str__())
525           
526                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
[71bd773]527                #self.list_cb_theory[data_id] = theory_list_ctrl
528                self.list_cb_theory[state_id] = theory_list_ctrl
[91bdf87]529       
[c70eb7c]530           
[ee2b492]531   
[3feed3e]532    def set_data_helper(self):
[3c44c66]533        """
534        """
[3feed3e]535        data_to_plot = []
[e88ebfd]536        state_to_plot = []
537        theory_to_plot = []
[c70eb7c]538        for value in self.list_cb_data.values():
539            item, _, _, _, _, _ = value
[3feed3e]540            if item.IsChecked():
[3658717e]541                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
542                data_to_plot.append(data_id)
543                if state_id not in state_to_plot:
544                    state_to_plot.append(state_id)
545           
[c70eb7c]546        for theory_dict in self.list_cb_theory.values():
547            for key, value in theory_dict.iteritems():
548                item, _, _ = value
549                if item.IsChecked():
[e88ebfd]550                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
[c70eb7c]551                    theory_to_plot.append(theory_id)
[e88ebfd]552                    if state_id not in state_to_plot:
553                        state_to_plot.append(state_id)
554        return data_to_plot, theory_to_plot, state_to_plot
[3feed3e]555   
[c70eb7c]556    def remove_by_id(self, id):
557        """
558        """
559        for item in self.list_cb_data.values():
560            data_c, _, _, _, _, theory_child = item
561            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
562            if id == data_id:
563                self.tree_ctrl.Delete(data_c)
564                del self.list_cb_data[state_id]
565                del self.list_cb_theory[data_id]
[ae83ad3]566             
[3feed3e]567    def on_remove(self, event):
[18ec684]568        """
[3658717e]569        Get a list of item checked and remove them from the treectrl
570        Ask the parent to remove reference to this item
[18ec684]571        """
[665c083]572        data_to_remove, theory_to_remove, _ = self.set_data_helper()
573        data_key = []
574        theory_key = []
[3658717e]575        #remove  data from treectrl
576        for d_key, item in self.list_cb_data.iteritems():
[665c083]577            data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = item
578            if data_c.IsChecked():
579                self.tree_ctrl.Delete(data_c)
[3658717e]580                data_key.append(d_key)
581                if d_key in self.list_cb_theory.keys():
582                    theory_list_ctrl = self.list_cb_theory[d_key]
583                    theory_to_remove += theory_list_ctrl.keys()
584        # Remove theory from treectrl       
585        for t_key, theory_dict in self.list_cb_theory.iteritems():
586            for  key, value in theory_dict.iteritems():
[665c083]587                item, _, _ = value
588                if item.IsChecked():
589                    self.tree_ctrl.Delete(item)
590                    theory_key.append(key)
[3658717e]591        #Remove data and related theory references
[665c083]592        for key in data_key:
593            del self.list_cb_data[key]
[3658717e]594            if key in theory_key:
595                del self.list_cb_theory[key]
596        #remove theory  references independently of data
[665c083]597        for key in theory_key:
[3658717e]598            for t_key, theory_dict in self.list_cb_theory.iteritems():
[71bd773]599                if key in theory_dict:
600                    del theory_dict[key]
[3658717e]601           
[18ec684]602        self.parent.remove_data(data_id=data_to_remove,
[665c083]603                                  theory_id=theory_to_remove)
[3c44c66]604       
[3feed3e]605    def on_import(self, event=None):
[3c44c66]606        """
[3feed3e]607        Get all select data and set them to the current active perspetive
[3c44c66]608        """
[e88ebfd]609        data_id, theory_id, state_id = self.set_data_helper()
610        self.parent.set_data(data_id)
611        self.parent.set_data(state_id=state_id, theory_id=theory_id)
612       
[213892bc]613    def on_append_plot(self, event=None):
614        """
615        append plot to plot panel on focus
616        """
[e88ebfd]617        data_id, theory_id, state_id = self.set_data_helper()
618        self.parent.plot_data(data_id=data_id, 
619                              state_id=state_id,
620                              theory_id=theory_id,
621                              append=True)
[213892bc]622   
[3feed3e]623    def on_plot(self, event=None):
[3c44c66]624        """
[3feed3e]625        Send a list of data names to plot
[3c44c66]626        """
[e88ebfd]627        data_id, theory_id, state_id = self.set_data_helper()
628        self.parent.plot_data(data_id=data_id, 
629                              state_id=state_id,
630                              theory_id=theory_id,
631                              append=False)
[3feed3e]632       
[c70eb7c]633    def on_freeze(self, event):
634        """
635        """
[e88ebfd]636        _, theory_id, state_id = self.set_data_helper()
[ee2b492]637        self.parent.freeze(data_id=state_id, theory_id=theory_id)
[c70eb7c]638       
[3feed3e]639    def set_active_perspective(self, name):
[3c44c66]640        """
[3feed3e]641        set the active perspective
[3c44c66]642        """
[3feed3e]643        self.tctrl_perspective.SetLabel(str(name))
[c5e84fb]644     
[3feed3e]645    def set_panel_on_focus(self, name):
[3c44c66]646        """
[3feed3e]647        set the plot panel on focus
[3c44c66]648        """
[3feed3e]649        self.tctrl_plotpanel.SetLabel(str(name))
[e88ebfd]650 
[c70eb7c]651   
[3feed3e]652
[3c44c66]653
654class DataFrame(wx.Frame):
[3feed3e]655    ## Internal name for the AUI manager
656    window_name = "Data Panel"
657    ## Title to appear on top of the window
658    window_caption = "Data Panel"
659    ## Flag to tell the GUI manager that this panel is not
660    #  tied to any perspective
661    ALWAYS_ON = True
662   
[cc061c3]663    def __init__(self, parent=None, owner=None, manager=None,size=(400, 800),
[3feed3e]664                         list_of_perspective=[],list=[], *args, **kwds):
[cc061c3]665        kwds['size'] = size
[3c44c66]666        kwds['id'] = -1
[3feed3e]667        kwds['title']= "Loaded Data"
[3c44c66]668        wx.Frame.__init__(self, parent=parent, *args, **kwds)
669        self.parent = parent
670        self.owner = owner
671        self.manager = manager
[32c0841]672        self.panel = DataPanel(parent=self, 
[cc061c3]673                               #size=size,
[32c0841]674                               list_of_perspective=list_of_perspective)
[3feed3e]675     
676    def load_data_list(self, list=[]):
[3c44c66]677        """
678        Fill the list inside its panel
679        """
[3feed3e]680        self.panel.load_data_list(list=list)
[3c44c66]681       
[3feed3e]682    def layout_perspective(self, list_of_perspective=[]):
[3c44c66]683        """
684        """
685        self.panel.layout_perspective(list_of_perspective=list_of_perspective)
[c70eb7c]686   
687   
[32c0841]688       
[3feed3e]689   
690from dataFitting import Data1D
691from dataFitting import Data2D, Theory1D
692from data_state import DataState
693import sys
694class State():
695    def __init__(self):
696        self.msg = ""
697    def __str__(self):
698        self.msg = "model mane : model1\n"
699        self.msg += "params : \n"
700        self.msg += "name  value\n"
701        return msg
[71bd773]702def set_data_state(data=None, path=None, theory=None, state=None):
[3feed3e]703    dstate = DataState(data=data)
704    dstate.set_path(path=path)
[c70eb7c]705    dstate.set_theory(theory, state)
706 
[3feed3e]707    return dstate
708"""'
709data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"),
710            ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"),
711            ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"),
712            ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"),
713            ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")]
714"""     
[3c44c66]715if __name__ == "__main__":
[3feed3e]716   
[3c44c66]717    app = wx.App()
[3feed3e]718    try:
719        list_of_perspective = [('perspective2', False), ('perspective1', True)]
720        data_list = {}
[c70eb7c]721        # state 1
[ee2b492]722        data = Data2D()
723        data.name = "data2"
[584c4c4]724        data.id = 1
[c70eb7c]725        data.append_empty_process()
726        process = data.process[len(data.process)-1]
727        process.data = "07/01/2010"
[ee2b492]728        theory = Data2D()
[584c4c4]729        theory.id = 34
[c70eb7c]730        theory.name = "theory1"
[3feed3e]731        path = "path1"
732        state = State()
733        data_list['1']=set_data_state(data, path,theory, state)
[c70eb7c]734        #state 2
[ee2b492]735        data = Data2D()
[3feed3e]736        data.name = "data2"
[584c4c4]737        data.id = 76
[ee2b492]738        theory = Data2D()
[584c4c4]739        theory.id = 78
[3feed3e]740        theory.name = "CoreShell 07/24/25"
741        path = "path2"
[c70eb7c]742        #state3
[3feed3e]743        state = State()
744        data_list['2']=set_data_state(data, path,theory, state)
745        data = Data1D()
[584c4c4]746        data.id = 3
[3feed3e]747        data.name = "data2"
748        theory = Theory1D()
749        theory.name = "CoreShell"
[584c4c4]750        theory.id = 4
[c70eb7c]751        theory.append_empty_process()
752        process = theory.process[len(theory.process)-1]
753        process.description = "this is my description"
[3feed3e]754        path = "path3"
[c70eb7c]755        data.append_empty_process()
756        process = data.process[len(data.process)-1]
757        process.data = "07/22/2010"
[3feed3e]758        data_list['4']=set_data_state(data, path,theory, state)
[c70eb7c]759        #state 4
760        temp_data_list = {}
761        data.name = "data5 erasing data2"
762        temp_data_list['4'] = set_data_state(data, path,theory, state)
763        #state 5
[3feed3e]764        data = Data2D()
765        data.name = "data3"
[584c4c4]766        data.id = 5
[c70eb7c]767        data.append_empty_process()
768        process = data.process[len(data.process)-1]
769        process.data = "07/01/2010"
[3feed3e]770        theory = Theory1D()
[c70eb7c]771        theory.name = "Cylinder"
[3feed3e]772        path = "path2"
773        state = State()
774        dstate= set_data_state(data, path,theory, state)
775        theory = Theory1D()
[584c4c4]776        theory.id = 6
[c70eb7c]777        theory.name = "CoreShell"
778        dstate.set_theory(theory)
779        theory = Theory1D()
780        theory.id = 6
781        theory.name = "CoreShell replacing coreshell in data3"
[3feed3e]782        dstate.set_theory(theory)
[c70eb7c]783        data_list['3'] = dstate
784        #state 6
785        data_list['6']=set_data_state(None, path,theory, state)
[71bd773]786        data_list['6']=set_data_state(theory=theory, state=None)
787        theory = Theory1D()
788        theory.id = 7
789        data_list['6']=set_data_state(theory=theory, state=None)
790        data_list['7']=set_data_state(theory=theory, state=None)
[3feed3e]791        window = DataFrame(list=data_list)
[c70eb7c]792        window.load_data_list(list=data_list)
793        #window.layout_perspective(list_of_perspective=list_of_perspective)
[3feed3e]794        window.Show(True)
[c70eb7c]795        window.load_data_list(list=temp_data_list)
[3feed3e]796    except:
797        #raise
798        print "error",sys.exc_value
[c70eb7c]799       
[3c44c66]800    app.MainLoop() 
801   
802   
Note: See TracBrowser for help on using the repository browser.