source: sasview/guiframe/data_panel.py @ dce84c0

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

working on the freeze option

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