source: sasview/guiframe/data_panel.py @ 0a2fdca

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

fixing plot panel and control panels focusing problems

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