source: sasview/guiframe/data_panel.py @ 3658717e

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 3658717e was 3658717e, checked in by Gervaise Alina <gervyh@…>, 13 years ago

working on delete file

  • Property mode set to 100644
File size: 30.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 = 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                    theory_list_ctrl[theory_id] = [t_child, 
460                                                   i_c_c, 
461                                                   t_p_c]
462                else:
463                    #replace theory
464                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
465                    self.tree_ctrl.SetItemText(t_child, name) 
466                    self.tree_ctrl.SetItemPyData(t_child, temp) 
467                    self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % theory_class) 
468                    self.tree_ctrl.DeleteChildren(t_p_c) 
469                    for process in theory_data.process:
470                        i_t_c = self.tree_ctrl.AppendItem(t_p_c,
471                                                          process.__str__())
472             
473        else:
474            #data didn't have a theory associated it before
475            theory_list_ctrl = {}
476            for theory_id, item in theory_list.iteritems():
477                theory_data, theory_state = item
478                if theory_data is not None:
479                    name = theory_data.name
480                    theory_class = theory_data.__class__.__name__
481                    theory_id = theory_data.id
482                    #if theory_state is not None:
483                    #    name = theory_state.model.name
484                    temp = (theory_id, theory_class, state_id)
485                    t_child = self.tree_ctrl.AppendItem(theory_child,
486                            name, ct_type=1, 
487                            data=(theory_data.id, theory_class, state_id))
488                    t_i_c = self.tree_ctrl.AppendItem(t_child, 'Info')
489                    i_c_c = self.tree_ctrl.AppendItem(t_i_c, 
490                                                  'Type: %s' % theory_class)
491                    t_p_c = self.tree_ctrl.AppendItem(t_i_c, 'Process')
492                   
493                    for process in theory_data.process:
494                        i_t_c = self.tree_ctrl.AppendItem(t_p_c,
495                                                          process.__str__())
496           
497                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
498                self.list_cb_theory[data_id] = theory_list_ctrl
499           
500   
501    def set_data_helper(self):
502        """
503        """
504        data_to_plot = []
505        state_to_plot = []
506        theory_to_plot = []
507        for value in self.list_cb_data.values():
508            item, _, _, _, _, _ = value
509            if item.IsChecked():
510                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
511                data_to_plot.append(data_id)
512                if state_id not in state_to_plot:
513                    state_to_plot.append(state_id)
514           
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        Get a list of item checked and remove them from the treectrl
539        Ask the parent to remove reference to this item
540        """
541        data_to_remove, theory_to_remove, _ = self.set_data_helper()
542        data_key = []
543        theory_key = []
544        #remove  data from treectrl
545        for d_key, item in self.list_cb_data.iteritems():
546            data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = item
547            if data_c.IsChecked():
548                self.tree_ctrl.Delete(data_c)
549                data_key.append(d_key)
550                if d_key in self.list_cb_theory.keys():
551                    theory_list_ctrl = self.list_cb_theory[d_key]
552                    theory_to_remove += theory_list_ctrl.keys()
553        # Remove theory from treectrl       
554        for t_key, theory_dict in self.list_cb_theory.iteritems():
555            for  key, value in theory_dict.iteritems():
556                item, _, _ = value
557                if item.IsChecked():
558                    self.tree_ctrl.Delete(item)
559                    theory_key.append(key)
560        #Remove data and related theory references
561        for key in data_key:
562            del self.list_cb_data[key]
563            if key in theory_key:
564                del self.list_cb_theory[key]
565        #remove theory  references independently of data
566        for key in theory_key:
567            for t_key, theory_dict in self.list_cb_theory.iteritems():
568                del theory_dict[key]
569           
570        self.parent.remove_data(data_id=data_to_remove,
571                                  theory_id=theory_to_remove)
572       
573    def on_import(self, event=None):
574        """
575        Get all select data and set them to the current active perspetive
576        """
577        data_id, theory_id, state_id = self.set_data_helper()
578        self.parent.set_data(data_id)
579        self.parent.set_data(state_id=state_id, theory_id=theory_id)
580       
581    def on_append_plot(self, event=None):
582        """
583        append plot to plot panel on focus
584        """
585        data_id, theory_id, state_id = self.set_data_helper()
586        self.parent.plot_data(data_id=data_id, 
587                              state_id=state_id,
588                              theory_id=theory_id,
589                              append=True)
590   
591    def on_plot(self, event=None):
592        """
593        Send a list of data names to plot
594        """
595        data_id, theory_id, state_id = self.set_data_helper()
596        self.parent.plot_data(data_id=data_id, 
597                              state_id=state_id,
598                              theory_id=theory_id,
599                              append=False)
600       
601    def on_freeze(self, event):
602        """
603        """
604        _, theory_id, state_id = self.set_data_helper()
605        self.parent.freeze(data_id=state_id, theory_id=theory_id)
606       
607    def set_active_perspective(self, name):
608        """
609        set the active perspective
610        """
611        self.tctrl_perspective.SetLabel(str(name))
612     
613    def set_panel_on_focus(self, name):
614        """
615        set the plot panel on focus
616        """
617        self.tctrl_plotpanel.SetLabel(str(name))
618 
619   
620
621
622class DataFrame(wx.Frame):
623    ## Internal name for the AUI manager
624    window_name = "Data Panel"
625    ## Title to appear on top of the window
626    window_caption = "Data Panel"
627    ## Flag to tell the GUI manager that this panel is not
628    #  tied to any perspective
629    ALWAYS_ON = True
630   
631    def __init__(self, parent=None, owner=None, manager=None,size=(400, 800),
632                         list_of_perspective=[],list=[], *args, **kwds):
633        kwds['size'] = size
634        kwds['id'] = -1
635        kwds['title']= "Loaded Data"
636        wx.Frame.__init__(self, parent=parent, *args, **kwds)
637        self.parent = parent
638        self.owner = owner
639        self.manager = manager
640        self.panel = DataPanel(parent=self, 
641                               #size=size,
642                               list_of_perspective=list_of_perspective)
643     
644    def load_data_list(self, list=[]):
645        """
646        Fill the list inside its panel
647        """
648        self.panel.load_data_list(list=list)
649       
650    def layout_perspective(self, list_of_perspective=[]):
651        """
652        """
653        self.panel.layout_perspective(list_of_perspective=list_of_perspective)
654   
655   
656       
657   
658from dataFitting import Data1D
659from dataFitting import Data2D, Theory1D
660from data_state import DataState
661import sys
662class State():
663    def __init__(self):
664        self.msg = ""
665    def __str__(self):
666        self.msg = "model mane : model1\n"
667        self.msg += "params : \n"
668        self.msg += "name  value\n"
669        return msg
670def set_data_state(data, path, theory, state):
671    dstate = DataState(data=data)
672    dstate.set_path(path=path)
673    dstate.set_theory(theory, state)
674 
675    return dstate
676"""'
677data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"),
678            ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"),
679            ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"),
680            ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"),
681            ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")]
682"""     
683if __name__ == "__main__":
684   
685    app = wx.App()
686    try:
687        list_of_perspective = [('perspective2', False), ('perspective1', True)]
688        data_list = {}
689        # state 1
690        data = Data2D()
691        data.name = "data2"
692        data.id = 1
693        data.append_empty_process()
694        process = data.process[len(data.process)-1]
695        process.data = "07/01/2010"
696        theory = Data2D()
697        theory.id = 34
698        theory.name = "theory1"
699        path = "path1"
700        state = State()
701        data_list['1']=set_data_state(data, path,theory, state)
702        #state 2
703        data = Data2D()
704        data.name = "data2"
705        data.id = 76
706        theory = Data2D()
707        theory.id = 78
708        theory.name = "CoreShell 07/24/25"
709        path = "path2"
710        #state3
711        state = State()
712        data_list['2']=set_data_state(data, path,theory, state)
713        data = Data1D()
714        data.id = 3
715        data.name = "data2"
716        theory = Theory1D()
717        theory.name = "CoreShell"
718        theory.id = 4
719        theory.append_empty_process()
720        process = theory.process[len(theory.process)-1]
721        process.description = "this is my description"
722        path = "path3"
723        data.append_empty_process()
724        process = data.process[len(data.process)-1]
725        process.data = "07/22/2010"
726        data_list['4']=set_data_state(data, path,theory, state)
727        #state 4
728        temp_data_list = {}
729        data.name = "data5 erasing data2"
730        temp_data_list['4'] = set_data_state(data, path,theory, state)
731        #state 5
732        data = Data2D()
733        data.name = "data3"
734        data.id = 5
735        data.append_empty_process()
736        process = data.process[len(data.process)-1]
737        process.data = "07/01/2010"
738        theory = Theory1D()
739        theory.name = "Cylinder"
740        path = "path2"
741        state = State()
742        dstate= set_data_state(data, path,theory, state)
743        theory = Theory1D()
744        theory.id = 6
745        theory.name = "CoreShell"
746        dstate.set_theory(theory)
747        theory = Theory1D()
748        theory.id = 6
749        theory.name = "CoreShell replacing coreshell in data3"
750        dstate.set_theory(theory)
751        data_list['3'] = dstate
752        #state 6
753        data_list['6']=set_data_state(None, path,theory, state)
754       
755        window = DataFrame(list=data_list)
756        window.load_data_list(list=data_list)
757        #window.layout_perspective(list_of_perspective=list_of_perspective)
758        window.Show(True)
759        window.load_data_list(list=temp_data_list)
760    except:
761        #raise
762        print "error",sys.exc_value
763       
764    app.MainLoop() 
765   
766   
Note: See TracBrowser for help on using the repository browser.