source: sasview/guiframe/data_panel.py @ f69b5830

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 f69b5830 was 1b1bbf9, checked in by Jae Cho <jhjcho@…>, 14 years ago

focus color (plots) and adjust panel sizes a bit

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