source: sasview/guiframe/data_panel.py @ 1a7ec34

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 1a7ec34 was 73581ce, checked in by Gervaise Alina <gervyh@…>, 14 years ago

fix customtreectrl style for mac

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