source: sasview/guiframe/data_panel.py @ 6512644

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 6512644 was b5e79f7, checked in by Gervaise Alina <gervyh@…>, 14 years ago

fix datapanel

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