source: sasview/sansguiframe/src/sans/guiframe/data_panel.py @ 9e9e9a5

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 9e9e9a5 was 318b5bbb, checked in by Jae Cho <jhjcho@…>, 12 years ago

Added polarization and magnetic stuffs

  • Property mode set to 100644
File size: 53.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
14from wx.build import build_options
15# Check version
16toks = str(wx.__version__).split('.')
17if int(toks[1]) < 9:
18    if int(toks[2]) < 12:
19        wx_version = 811
20    else:
21        wx_version = 812
22else:
23    wx_version = 900
24import sys
25from wx.lib.scrolledpanel import ScrolledPanel
26import  wx.lib.agw.customtreectrl as CT
27from sans.guiframe.dataFitting import Data1D
28from sans.guiframe.dataFitting import Data2D
29from sans.guiframe.panel_base import PanelBase
30from sans.guiframe.events import StatusEvent
31from sans.guiframe.events import EVT_DELETE_PLOTPANEL
32from sans.guiframe.events import NewLoadDataEvent
33from sans.guiframe.events import NewPlotEvent
34from sans.guiframe.gui_style import GUIFRAME
35from sans.guiframe.events import NewBatchEvent
36from sans.dataloader.loader import Loader
37#from sans.guiframe.local_perspectives.plotting.masking \
38#    import FloatPanel as QucikPlotDialog
39from sans.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame \
40        as QucikPlotDialog
41import sans.guiframe.config as config
42 
43extension_list = []
44if config.APPLICATION_STATE_EXTENSION is not None:
45    extension_list.append(config.APPLICATION_STATE_EXTENSION)
46EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list   
47PLUGINS_WLIST = config.PLUGINS_WLIST
48APPLICATION_WLIST = config.APPLICATION_WLIST
49
50#Control panel width
51if sys.platform.count("win32") > 0:
52    PANEL_WIDTH = 235
53    PANEL_HEIGHT = 700
54    CBOX_WIDTH = 140
55    BUTTON_WIDTH = 80
56    FONT_VARIANT = 0
57    IS_MAC = False
58else:
59    PANEL_WIDTH = 255
60    PANEL_HEIGHT = 750
61    CBOX_WIDTH = 155
62    BUTTON_WIDTH = 100
63    FONT_VARIANT = 1
64    IS_MAC = True
65
66STYLE_FLAG = wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\
67                    wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT
68                   
69                   
70class DataTreeCtrl(CT.CustomTreeCtrl):
71    """
72    Check list control to be used for Data Panel
73    """
74    def __init__(self, parent, *args, **kwds):
75        #agwstyle is introduced in wx.2.8.11 but is not working for mac
76        if IS_MAC and wx_version < 812:
77            try:
78                kwds['style'] = STYLE_FLAG
79                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
80            except:
81                del kwds['style']
82                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
83        else:
84            # agwstyle is introduced in wx.2.8.11
85            # argument working only for windows
86            try:
87                kwds['agwStyle'] = STYLE_FLAG
88                CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
89            except:
90                try:
91                    del kwds['agwStyle']
92                    kwds['style'] = STYLE_FLAG
93                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
94                except:
95                    del kwds['style']
96                    CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds)
97        self.root = self.AddRoot("Available Data")
98                   
99    def OnCompareItems(self, item1, item2):
100        """
101        Overrides OnCompareItems in wx.TreeCtrl.
102        Used by the SortChildren method.
103        """
104        # Get the item data
105        data_1 = self.GetItemText(item1)
106        data_2 = self.GetItemText(item2)
107        # Compare the item data
108        if data_1 < data_2:
109            return -1
110        elif data_1 > data_2:
111            return 1
112        else:
113            return 0
114       
115class DataPanel(ScrolledPanel, PanelBase):
116    """
117    This panel displays data available in the application and widgets to
118    interact with data.
119    """
120    ## Internal name for the AUI manager
121    window_name = "Data Panel"
122    ## Title to appear on top of the window
123    window_caption = "Data Explorer"
124    #type of window
125    window_type = "Data Panel"
126    ## Flag to tell the GUI manager that this panel is not
127    #  tied to any perspective
128    #ALWAYS_ON = True
129    def __init__(self, parent, 
130                 list=None,
131                 size=(PANEL_WIDTH, PANEL_HEIGHT),
132                 list_of_perspective=None, manager=None, *args, **kwds):
133        kwds['size'] = size
134        kwds['style'] = STYLE_FLAG
135        ScrolledPanel.__init__(self, parent=parent, *args, **kwds)
136        PanelBase.__init__(self)
137        self.SetupScrolling()
138        #Set window's font size
139        self.SetWindowVariant(variant=FONT_VARIANT)
140        self.loader = Loader() 
141        #Default location
142        self._default_save_location = None 
143        self.all_data1d = True
144        self.parent = parent
145        self.manager = manager
146        if list is None:
147            list = []
148        self.list_of_data = list
149        if list_of_perspective is None:
150            list_of_perspective = []
151        self.list_of_perspective = list_of_perspective
152        self.list_rb_perspectives = []
153        self.list_cb_data = {}
154        self.list_cb_theory = {}
155        self.tree_ctrl = None
156        self.tree_ctrl_theory = None
157        self.perspective_cbox = None
158        ## Create context menu for page
159        self.data_menu = None
160        self.popUpMenu = None
161        self.plot3d_id = None
162        self.editmask_id = None
163        # Default attr
164        self.vbox  = None
165        self.sizer1 = None
166        self.sizer2 = None
167        self.sizer3 = None
168        self.sizer4 = None
169        self.sizer5 = None
170        self.selection_cbox = None
171        self.bt_add = None
172        self.bt_remove = None
173        self.bt_import = None
174        self.bt_append_plot = None
175        self.bt_plot = None
176        self.bt_freeze = None
177        self.cb_plotpanel = None
178        self.rb_single_mode = None
179        self.rb_batch_mode = None
180
181        self.owner = None
182        self.do_layout()
183        self.fill_cbox_analysis(self.list_of_perspective)
184        self.Bind(wx.EVT_SHOW, self.on_close_page)
185        if self.parent is not None:
186            self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel)
187     
188    def do_layout(self):
189        """
190            Create the panel layout
191        """
192        self.define_panel_structure()
193        self.layout_selection()
194        self.layout_data_list()
195        self.layout_batch()
196        self.layout_button()
197       
198    def disable_app_combo(self, enable):
199        """
200        Disable app combo box
201        """
202        self.perspective_cbox.Enable(enable)
203       
204    def define_panel_structure(self):
205        """
206        Define the skeleton of the panel
207        """
208        w, h = self.parent.GetSize()
209        self.vbox  = wx.BoxSizer(wx.VERTICAL)
210        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
211        self.sizer1.SetMinSize(wx.Size(w/13, h*2/5))
212     
213        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
214        self.sizer3 = wx.FlexGridSizer(9, 2, 4, 1)
215        self.sizer4 = wx.BoxSizer(wx.VERTICAL)
216        self.sizer5 = wx.BoxSizer(wx.VERTICAL)
217       
218        self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL, 1)
219        self.vbox.Add(self.sizer1, 1, wx.EXPAND|wx.ALL, 0)
220        self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL, 1)
221        self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL, 10)
222        #self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5)
223       
224        self.SetSizer(self.vbox)
225       
226    def layout_selection(self):
227        """
228            Create selection option combo box
229        """
230        select_txt = wx.StaticText(self, -1, 'Selection Options')
231        select_txt.SetForegroundColour('blue')
232        self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY)
233        list_of_options = ['Select all Data',
234                            'Unselect all Data',
235                           'Select all Data 1D',
236                           'Unselect all Data 1D',
237                           'Select all Data 2D',
238                           'Unselect all Data 2D' ]
239        for option in list_of_options:
240            self.selection_cbox.Append(str(option))
241        self.selection_cbox.SetValue('Select all Data')
242        wx.EVT_COMBOBOX(self.selection_cbox, -1, self._on_selection_type)
243        self.sizer5.AddMany([(select_txt, 0, wx.ALL, 5), 
244                            (self.selection_cbox, 0, wx.ALL,5)])
245        self.enable_selection()
246       
247   
248    def _on_selection_type(self, event):
249        """
250            Select data according to patterns
251            :param event: UI event
252        """
253        option = self.selection_cbox.GetValue()
254       
255        pos = self.selection_cbox.GetSelection()
256        if pos == wx.NOT_FOUND:
257            return 
258        option = self.selection_cbox.GetString(pos)
259        for item in self.list_cb_data.values():
260            data_ctrl, _, _, _, _, _, _, _ = item
261            _, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) 
262            if option == 'Select all Data':
263                self.tree_ctrl.CheckItem(data_ctrl, True) 
264            elif option == 'Unselect all Data':
265                self.tree_ctrl.CheckItem(data_ctrl, False)
266            elif option == 'Select all Data 1D':
267                if data_class == 'Data1D':
268                    self.tree_ctrl.CheckItem(data_ctrl, True) 
269            elif option == 'Unselect all Data 1D':
270                if data_class == 'Data1D':
271                    self.tree_ctrl.CheckItem(data_ctrl, False) 
272            elif option == 'Select all Data 1D':
273                if data_class == 'Data1D':
274                    self.tree_ctrl.CheckItem(data_ctrl, True) 
275            elif option == 'Select all Data 2D':
276                if data_class == 'Data2D':
277                    self.tree_ctrl.CheckItem(data_ctrl, True) 
278            elif option == 'Unselect all Data 2D':
279                if data_class == 'Data2D':
280                    self.tree_ctrl.CheckItem(data_ctrl, False) 
281        self.enable_append()
282        self.enable_freeze()
283        self.enable_plot()
284        self.enable_import()
285        self.enable_remove()
286               
287    def layout_button(self):
288        """
289        Layout widgets related to buttons
290        """
291        self.bt_add = wx.Button(self, wx.NewId(), "Load Data", 
292                                size=(BUTTON_WIDTH, -1))
293        self.bt_add.SetToolTipString("Load data files")
294        wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data)
295        self.bt_remove = wx.Button(self, wx.NewId(), "Delete Data",
296         size=(BUTTON_WIDTH, -1))
297        self.bt_remove.SetToolTipString("Delete data from the application")
298        wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove)
299        self.bt_import = wx.Button(self, wx.NewId(), "Send To",
300                                    size=(BUTTON_WIDTH, -1))
301        self.bt_import.SetToolTipString("Send Data set to active perspective")
302        wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import)
303        self.perspective_cbox = wx.ComboBox(self, -1,
304                                style=wx.CB_READONLY)
305        if not IS_MAC:
306            self.perspective_cbox.SetMinSize((BUTTON_WIDTH*1.6, -1))
307        wx.EVT_COMBOBOX(self.perspective_cbox, -1, 
308                        self._on_perspective_selection)
309   
310        self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To",
311                                        size=(BUTTON_WIDTH, -1))
312        self.bt_append_plot.SetToolTipString( \
313                                "Plot the selected data in the active panel")
314        wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot)
315       
316        self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", 
317                                 size=(BUTTON_WIDTH, -1))
318        self.bt_plot.SetToolTipString("To trigger plotting")
319        wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot)
320       
321        self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", 
322                                   size=(BUTTON_WIDTH, -1))
323        freeze_tip = "To trigger freeze a theory: making a copy\n"
324        freeze_tip += "of the theory checked to Data box,\n"
325        freeze_tip += "     so that it can act like a real data set."
326        self.bt_freeze.SetToolTipString(freeze_tip)
327        wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze)
328       
329        if sys.platform == 'darwin' and build_options.WXPORT == 'osx_cocoa':
330            self.cb_plotpanel = wx.ComboBox(self, -1, 
331                                            style=wx.CB_READONLY)
332        else:
333            self.cb_plotpanel = wx.ComboBox(self, -1, 
334                                            style=wx.CB_READONLY|wx.CB_SORT)
335        wx.EVT_COMBOBOX(self.cb_plotpanel, -1, self._on_plot_selection)
336        self.cb_plotpanel.Disable()
337
338        self.sizer3.AddMany([(self.bt_add),
339                             ((10, 10)),
340                             (self.bt_remove),
341                             ((10, 10)),
342                             (self.bt_freeze),
343                             ((10, 10)),
344                             (self.bt_plot),
345                             ((10, 10)),
346                             (self.bt_append_plot),
347                             (self.cb_plotpanel, 
348                              wx.EXPAND|wx.ADJUST_MINSIZE, 5),
349                             ((5, 5)),
350                             ((5, 5)),
351                             (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5),
352                             (self.perspective_cbox, 
353                              wx.EXPAND|wx.ADJUST_MINSIZE, 5),
354                             ((10, 10)),
355                             (self.sizer4),
356                             ((10, 40)),
357                             ((10, 40))])
358
359        self.sizer3.AddGrowableCol(1, 1)
360        self.show_data_button()
361        self.enable_remove()
362        self.enable_import()
363        self.enable_plot()
364        self.enable_append()
365        self.enable_freeze()
366        self.enable_remove_plot()
367       
368    def layout_batch(self):
369        """
370            Set up batch mode options
371        """
372        self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode',
373                                             style=wx.RB_GROUP)
374        self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode')
375        self.Bind(wx.EVT_RADIOBUTTON, self.on_single_mode,
376                     id=self.rb_single_mode.GetId())
377        self.Bind(wx.EVT_RADIOBUTTON, self.on_batch_mode,
378                   id=self.rb_batch_mode.GetId())
379       
380        self.rb_single_mode.SetValue(not self.parent.batch_on)
381        self.rb_batch_mode.SetValue(self.parent.batch_on)
382        self.sizer4.AddMany([(self.rb_single_mode, 0, wx.ALL, 4),
383                             (self.rb_batch_mode, 0, wx.ALL, 4)])
384       
385    def on_single_mode(self, event):
386        """
387            Change to single mode
388            :param event: UI event
389        """
390        if self.parent is not None:
391            wx.PostEvent(self.parent, NewBatchEvent(enable=False))
392       
393    def on_batch_mode(self, event):
394        """
395            Change to batch mode
396            :param event: UI event
397        """
398        if self.parent is not None:
399            wx.PostEvent(self.parent, 
400                         NewBatchEvent(enable=True))
401   
402    def _get_data_selection(self, event): 
403        """
404            Get data selection from the right click
405            :param event: UI event
406        """
407        data = None
408        #selection = event.GetSelection()
409        id, _, _ = self.FindFocus().GetSelection().GetData()
410        data_list, theory_list = \
411                        self.parent.get_data_manager().get_by_id(id_list=[id])
412        if data_list:
413            data = data_list.values()[0]
414        if data == None:
415            data = theory_list.values()[0][0]
416        return data
417   
418    def on_edit_data(self, event):
419        """
420        Pop Up Data Editor
421        """
422        data = self._get_data_selection(event)
423        from sans.guiframe.local_perspectives.plotting.masking \
424            import MaskPanel as MaskDialog
425       
426        panel = MaskDialog(parent=self.parent, base=self, 
427                           data=data, id=wx.NewId())
428        panel.ShowModal()
429   
430    def on_plot_3d(self, event):
431        """
432        Frozen image of 3D
433        """
434        data = self._get_data_selection(event)
435        from sans.guiframe.local_perspectives.plotting.masking \
436        import FloatPanel as Float3dDialog
437       
438        panel = Float3dDialog(base=self, data=data, 
439                              dimension=3, id=wx.NewId())
440        panel.ShowModal()   
441   
442    def on_quick_plot(self, event):
443        """
444        Frozen plot
445        """
446        data = self._get_data_selection(event)
447        if data.__class__.__name__ == "Data2D":
448            dimension = 2
449        else:
450            dimension = 1 
451        #panel = QucikPlotDialog(base=self, data=data,
452        #                        dimension=dimension, id=wx.NewId())
453        frame = QucikPlotDialog(self, -1, "Plot " + data.name, 'log_{10}')
454        self.parent.put_icon(frame)
455        frame.add_plot(data)
456        #frame.SetTitle(title)
457        frame.Show(True)
458        frame.SetFocus()
459        #panel.ShowModal()   
460   
461    def on_data_info(self, event):
462        """
463        Data Info panel
464        """
465        data = self._get_data_selection(event)
466        if data.__class__.__name__ == "Data2D":
467            self.parent.show_data2d(data, data.name)
468        else:
469            self.parent.show_data1d(data, data.name)
470       
471    def on_save_as(self, event):
472        """
473        Save data as a file
474        """
475        data = self._get_data_selection(event)
476        #path = None
477        default_name = data.name
478        if default_name.count('.') > 0:
479            default_name = default_name.split('.')[0]
480        default_name += "_out"
481        if self.parent != None:
482            if issubclass(data.__class__, Data1D):
483                self.parent.save_data1d(data, default_name)
484            elif issubclass(data.__class__, Data2D):
485                self.parent.save_data2d(data, default_name)
486            else:
487                print "unable to save this type of data"
488       
489    def layout_data_list(self):
490        """
491        Add a listcrtl in the panel
492        """
493        tree_ctrl_label = wx.StaticText(self, -1, "Data")
494        tree_ctrl_label.SetForegroundColour('blue')
495        self.tree_ctrl = DataTreeCtrl(parent=self, style=wx.SUNKEN_BORDER)
496        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
497        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click_data)
498        ## Create context menu for page
499        self.data_menu = wx.Menu()
500        id = wx.NewId()
501        name = "Data Info"
502        msg = "Show Data Info"
503        self.data_menu.Append(id, name, msg)
504        wx.EVT_MENU(self, id, self.on_data_info)
505       
506        id = wx.NewId()
507        name = "Save As"
508        msg = "Save Theory/Data as a file"
509        self.data_menu.Append(id, name, msg)
510        wx.EVT_MENU(self, id, self.on_save_as)
511   
512        quickplot_id = wx.NewId()
513        name = "Quick Plot"
514        msg = "Plot the current Data"
515        self.data_menu.Append(quickplot_id, name, msg)
516        wx.EVT_MENU(self, quickplot_id, self.on_quick_plot)
517       
518        self.plot3d_id = wx.NewId()
519        name = "Quick 3DPlot (Slow)"
520        msg = "Plot3D the current 2D Data"
521        self.data_menu.Append(self.plot3d_id, name, msg)
522        wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d)
523           
524        self.editmask_id = wx.NewId()
525        name = "Edit Mask"
526        msg = "Edit Mask for the current 2D Data"
527        self.data_menu.Append(self.editmask_id, name, msg)
528        wx.EVT_MENU(self, self.editmask_id, self.on_edit_data)
529       
530        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory")
531        tree_ctrl_theory_label.SetForegroundColour('blue')
532        self.tree_ctrl_theory = DataTreeCtrl(parent=self, 
533                                                    style=wx.SUNKEN_BORDER)
534        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, 
535                                                    self.on_check_item)
536        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU, 
537                                   self.on_right_click_theory)
538        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10)
539        self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10)
540        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10)
541        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10)
542           
543    def on_right_click_theory(self, event):
544        """
545        On click theory data
546        """
547        try:
548            id, data_class_name, _ = \
549                            self.tree_ctrl_theory.GetSelection().GetData()
550            _, _ = self.parent.get_data_manager().get_by_id(id_list=[id])
551        except:
552            return
553        if self.data_menu is not None:
554            menu_enable = (data_class_name == "Data2D")
555            self.data_menu.Enable(self.editmask_id, False)
556            self.data_menu.Enable(self.plot3d_id, menu_enable)
557            self.PopupMenu(self.data_menu) 
558                   
559    def on_right_click_data(self, event):
560        """
561        Allow Editing Data
562        """
563        #selection = event.GetSelection()
564        is_data = True
565        try:
566            id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData()
567            data_list, _ = \
568                        self.parent.get_data_manager().get_by_id(id_list=[id])
569            if not data_list:
570                is_data = False
571        except:
572            return
573        if self.data_menu is not None:
574            menu_enable = (data_class_name == "Data2D")
575            maskmenu_enable = (menu_enable and is_data)
576            self.data_menu.Enable(self.editmask_id, maskmenu_enable)
577            self.data_menu.Enable(self.plot3d_id, menu_enable)
578            self.PopupMenu(self.data_menu) 
579       
580    def onContextMenu(self, event): 
581        """
582        Retrieve the state selected state
583        """
584        # Skipping the save state functionality for release 0.9.0
585        #return
586        pos = event.GetPosition()
587        pos = self.ScreenToClient(pos)
588        self.PopupMenu(self.popUpMenu, pos) 
589     
590 
591    def on_check_item(self, event):
592        """
593        On check item
594        """
595        item = event.GetItem()
596        item.Check(not item.IsChecked()) 
597        self.enable_append()
598        self.enable_freeze()
599        self.enable_plot()
600        self.enable_import()
601        self.enable_remove()
602        event.Skip()
603       
604    def fill_cbox_analysis(self, plugin):
605        """
606        fill the combobox with analysis name
607        """
608        self.list_of_perspective = plugin
609        if self.parent is None or \
610            not hasattr(self.parent, "get_current_perspective") or \
611            len(self.list_of_perspective) == 0:
612            return
613        if self.parent is not None and self.perspective_cbox  is not None:
614            for plug in self.list_of_perspective:
615                if plug.get_perspective():
616                    self.perspective_cbox.Append(plug.sub_menu, plug)
617           
618            curr_pers = self.parent.get_current_perspective()
619            if curr_pers:
620                self.perspective_cbox.SetStringSelection(curr_pers.sub_menu)
621                self.enable_import()
622                       
623    def load_data_list(self, list):
624        """
625        add need data with its theory under the tree
626        """
627        if list:
628            for state_id, dstate in list.iteritems():
629                data = dstate.get_data()
630                theory_list = dstate.get_theory()
631                if data is not None:
632                    data_name = str(data.name)
633                    data_title = str(data.title)
634                    data_run = str(data.run)
635                    data_class = data.__class__.__name__
636                    path = dstate.get_path() 
637                    process_list = data.process
638                    data_id = data.id
639                    s_path = str(path)
640                    if state_id not in self.list_cb_data:
641                        #new state
642                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,
643                                        0, data_name, ct_type=1, 
644                                        data=(data_id, data_class, state_id))
645                        data_c.Check(True)
646                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
647                        d_t_c = self.tree_ctrl.AppendItem(d_i_c, 
648                                                      'Title: %s' % data_title)
649                        r_n_c = self.tree_ctrl.AppendItem(d_i_c, 
650                                                      'Run: %s' % data_run)
651                        i_c_c = self.tree_ctrl.AppendItem(d_i_c, 
652                                                      'Type: %s' % data_class)
653                        p_c_c = self.tree_ctrl.AppendItem(d_i_c,
654                                                      "Path: '%s'" % s_path)
655                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
656                       
657                        for process in process_list:
658                            process_str = str(process).replace('\n',' ')
659                            if len(process_str)>20:
660                                process_str = process_str[:20]+' [...]'
661                            self.tree_ctrl.AppendItem(d_p_c, process_str)
662                        theory_child = self.tree_ctrl.AppendItem(data_c, 
663                                                                 "THEORIES")
664                        self.list_cb_data[state_id] = [data_c, 
665                                                       d_i_c,
666                                                       d_t_c,
667                                                       r_n_c,
668                                                       i_c_c,
669                                                       p_c_c,
670                                                       d_p_c,
671                                                       theory_child]
672                    else:
673                        data_ctrl_list =  self.list_cb_data[state_id]
674                        #This state is already display replace it contains
675                        data_c, d_i_c, d_t_c, r_n_c,  i_c_c, p_c_c, d_p_c, _ \
676                                = data_ctrl_list
677                        self.tree_ctrl.SetItemText(data_c, data_name) 
678                        temp = (data_id, data_class, state_id)
679                        self.tree_ctrl.SetItemPyData(data_c, temp) 
680                        self.tree_ctrl.SetItemText(i_c_c, 
681                                                   'Type: %s' % data_class)
682                        self.tree_ctrl.SetItemText(p_c_c, 
683                                                   'Path: %s' % s_path) 
684                        self.tree_ctrl.DeleteChildren(d_p_c) 
685                        for process in process_list:
686                            _ = self.tree_ctrl.AppendItem(d_p_c,
687                                                              process.__str__())
688                wx.CallAfter(self.append_theory, state_id, theory_list)
689            # Sort by data name
690            if self.tree_ctrl.root:
691                self.tree_ctrl.SortChildren(self.tree_ctrl.root)   
692        self.enable_remove()
693        self.enable_import()
694        self.enable_plot()
695        self.enable_freeze()
696        self.enable_selection()
697       
698    def _uncheck_all(self):
699        """
700        Uncheck all check boxes
701        """
702        for item in self.list_cb_data.values():
703            data_ctrl, _, _, _, _, _, _, _ = item
704            self.tree_ctrl.CheckItem(data_ctrl, False) 
705        self.enable_append()
706        self.enable_freeze()
707        self.enable_plot()
708        self.enable_import()
709        self.enable_remove()
710   
711    def append_theory(self, state_id, theory_list):
712        """
713        append theory object under data from a state of id = state_id
714        replace that theory if  already displayed
715        """
716        if not theory_list:
717            return 
718        if state_id not in self.list_cb_data.keys():
719            root = self.tree_ctrl_theory.root
720            tree = self.tree_ctrl_theory
721        else:
722            item = self.list_cb_data[state_id]
723            data_c, _, _, _, _, _, _, _ = item
724            root = data_c
725            tree = self.tree_ctrl
726        if root is not None:
727            wx.CallAfter(self.append_theory_helper, tree=tree, root=root, 
728                                       state_id=state_id, 
729                                       theory_list=theory_list)
730     
731     
732    def append_theory_helper(self, tree, root, state_id, theory_list):
733        """
734        Append theory helper
735        """
736        if state_id in self.list_cb_theory.keys():
737            #update current list of theory for this data
738            theory_list_ctrl = self.list_cb_theory[state_id]
739
740            for theory_id, item in theory_list.iteritems():
741                theory_data, _ = item
742                if theory_data is None:
743                    name = "Unknown"
744                    theory_class = "Unknown"
745                    theory_id = "Unknown"
746                    temp = (None, None, None)
747                else:
748                    name = theory_data.name
749                    theory_class = theory_data.__class__.__name__
750                    theory_id = theory_data.id
751                    #if theory_state is not None:
752                    #    name = theory_state.model.name
753                    temp = (theory_id, theory_class, state_id)
754                if theory_id not in theory_list_ctrl:
755                    #add new theory
756                    t_child = tree.AppendItem(root,
757                                                    name, ct_type=1, data=temp)
758                    t_i_c = tree.AppendItem(t_child, 'Info')
759                    i_c_c = tree.AppendItem(t_i_c, 
760                                                  'Type: %s' % theory_class)
761                    t_p_c = tree.AppendItem(t_i_c, 'Process')
762                   
763                    for process in theory_data.process:
764                        tree.AppendItem(t_p_c, process.__str__())
765                    theory_list_ctrl[theory_id] = [t_child, 
766                                                   i_c_c, 
767                                                   t_p_c]
768                else:
769                    #replace theory
770                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
771                    tree.SetItemText(t_child, name) 
772                    tree.SetItemPyData(t_child, temp) 
773                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class) 
774                    tree.DeleteChildren(t_p_c) 
775                    for process in theory_data.process:
776                        tree.AppendItem(t_p_c, process.__str__())
777             
778        else:
779            #data didn't have a theory associated it before
780            theory_list_ctrl = {}
781            for theory_id, item in theory_list.iteritems():
782                theory_data, _ = item
783                if theory_data is not None:
784                    name = theory_data.name
785                    theory_class = theory_data.__class__.__name__
786                    theory_id = theory_data.id
787                    #if theory_state is not None:
788                    #    name = theory_state.model.name
789                    temp = (theory_id, theory_class, state_id)
790                    t_child = tree.AppendItem(root,
791                            name, ct_type=1, 
792                            data=(theory_data.id, theory_class, state_id))
793                    t_i_c = tree.AppendItem(t_child, 'Info')
794                    i_c_c = tree.AppendItem(t_i_c, 
795                                                  'Type: %s' % theory_class)
796                    t_p_c = tree.AppendItem(t_i_c, 'Process')
797                   
798                    for process in theory_data.process:
799                        tree.AppendItem(t_p_c, process.__str__())
800           
801                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
802                #self.list_cb_theory[data_id] = theory_list_ctrl
803                self.list_cb_theory[state_id] = theory_list_ctrl
804       
805           
806   
807    def set_data_helper(self):
808        """
809        Set data helper
810        """
811        data_to_plot = []
812        state_to_plot = []
813        theory_to_plot = []
814        for value in self.list_cb_data.values():
815            item, _, _, _, _, _, _,  _ = value
816            if item.IsChecked():
817                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
818                data_to_plot.append(data_id)
819                if state_id not in state_to_plot:
820                    state_to_plot.append(state_id)
821           
822        for theory_dict in self.list_cb_theory.values():
823            for _, value in theory_dict.iteritems():
824                item, _, _ = value
825                if item.IsChecked():
826                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
827                    theory_to_plot.append(theory_id)
828                    if state_id not in state_to_plot:
829                        state_to_plot.append(state_id)
830        return data_to_plot, theory_to_plot, state_to_plot
831   
832    def remove_by_id(self, id):
833        """
834        Remove_dat by id
835        """
836        for item in self.list_cb_data.values():
837            data_c, _, _, _, _, _,  _, _ = item
838            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) 
839            if id == data_id:
840                self.tree_ctrl.Delete(data_c)
841                del self.list_cb_data[state_id]
842                del self.list_cb_theory[data_id]
843             
844    def load_error(self, error=None):
845        """
846        Pop up an error message.
847       
848        :param error: details error message to be displayed
849        """
850        if error is not None or str(error).strip() != "":
851            dial = wx.MessageDialog(self.parent, str(error), 
852                                    'Error Loading File',
853                                    wx.OK | wx.ICON_EXCLAMATION)
854            dial.ShowModal() 
855       
856    def _load_data(self, event):
857        """
858        send an event to the parent to trigger load from plugin module
859        """
860        if self.parent is not None:
861            wx.PostEvent(self.parent, NewLoadDataEvent())
862           
863
864    def on_remove(self, event):
865        """
866        Get a list of item checked and remove them from the treectrl
867        Ask the parent to remove reference to this item
868        """
869        msg = "This operation will delete the data sets checked "
870        msg += "and all the dependents."
871        msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)
872        if msg_box.ShowModal() != wx.ID_OK:
873            return
874       
875        data_to_remove, theory_to_remove, _ = self.set_data_helper()
876        data_key = []
877        theory_key = []
878        #remove  data from treectrl
879        for d_key, item in self.list_cb_data.iteritems():
880            data_c, _, _, _,  _, _, _, _ = item
881            if data_c.IsChecked():
882                self.tree_ctrl.Delete(data_c)
883                data_key.append(d_key)
884                if d_key in self.list_cb_theory.keys():
885                    theory_list_ctrl = self.list_cb_theory[d_key]
886                    theory_to_remove += theory_list_ctrl.keys()
887        # Remove theory from treectrl       
888        for _, theory_dict in self.list_cb_theory.iteritems():
889            for  key, value in theory_dict.iteritems():
890                item, _, _ = value
891                if item.IsChecked():
892                    try:
893                        self.tree_ctrl.Delete(item)
894                    except:
895                        pass
896                    theory_key.append(key)
897                   
898        #Remove data and related theory references
899        for key in data_key:
900            del self.list_cb_data[key]
901            if key in theory_key:
902                del self.list_cb_theory[key]
903        #remove theory  references independently of data
904        for key in theory_key:
905            for _, theory_dict in self.list_cb_theory.iteritems():
906                if key in theory_dict:
907                    for  key, value in theory_dict.iteritems():
908                        item, _, _ = value
909                        if item.IsChecked():
910                            try:
911                                self.tree_ctrl_theory.Delete(item)
912                            except:
913                                pass
914                    del theory_dict[key]
915                   
916           
917        self.parent.remove_data(data_id=data_to_remove,
918                                  theory_id=theory_to_remove)
919        self.enable_remove()
920        self.enable_freeze()
921        self.enable_remove_plot()
922       
923    def on_import(self, event=None):
924        """
925        Get all select data and set them to the current active perspetive
926        """
927        if event != None:
928            event.Skip()
929        data_id, theory_id, state_id = self.set_data_helper()
930        temp = data_id + state_id
931        self.parent.set_data(data_id=temp, theory_id=theory_id)
932       
933    def on_append_plot(self, event=None):
934        """
935        append plot to plot panel on focus
936        """
937        self._on_plot_selection()
938        data_id, theory_id, state_id = self.set_data_helper()
939        self.parent.plot_data(data_id=data_id, 
940                              state_id=state_id,
941                              theory_id=theory_id,
942                              append=True)
943   
944    def on_plot(self, event=None):
945        """
946        Send a list of data names to plot
947        """
948        data_id, theory_id, state_id = self.set_data_helper()
949        self.parent.plot_data(data_id=data_id, 
950                              state_id=state_id,
951                              theory_id=theory_id,
952                              append=False)
953        self.enable_remove_plot()
954         
955    def on_close_page(self, event=None):
956        """
957        On close
958        """
959        if event != None:
960            event.Skip()
961        # send parent to update menu with no show nor hide action
962        self.parent.show_data_panel(action=False)
963   
964    def on_freeze(self, event):
965        """
966        On freeze to make a theory to a data set
967        """
968        _, theory_id, state_id = self.set_data_helper()
969        if len(theory_id) > 0:
970            self.parent.freeze(data_id=state_id, theory_id=theory_id)
971            msg = "Freeze Theory:"
972            msg += " The theory(s) copied to the Data box as a data set."
973        else:
974            msg = "Freeze Theory: Requires at least one theory checked."
975        wx.PostEvent(self.parent, StatusEvent(status=msg))
976           
977    def set_active_perspective(self, name):
978        """
979        set the active perspective
980        """
981        self.perspective_cbox.SetStringSelection(name)
982        self.enable_import()
983       
984    def _on_delete_plot_panel(self, event):
985        """
986        get an event with attribute name and caption to delete existing name
987        from the combobox of the current panel
988        """
989        #name = event.name
990        caption = event.caption
991        if self.cb_plotpanel is not None:
992            pos = self.cb_plotpanel.FindString(str(caption)) 
993            if pos != wx.NOT_FOUND:
994                self.cb_plotpanel.Delete(pos)
995        self.enable_append()
996       
997    def set_panel_on_focus(self, name=None):
998        """
999        set the plot panel on focus
1000        """
1001        for _, value in self.parent.plot_panels.iteritems():
1002            name_plot_panel = str(value.window_caption)
1003            if name_plot_panel not in self.cb_plotpanel.GetItems():
1004                self.cb_plotpanel.Append(name_plot_panel, value)
1005            if name != None and name == name_plot_panel:
1006                self.cb_plotpanel.SetStringSelection(name_plot_panel)
1007                break
1008        self.enable_append()
1009        self.enable_remove_plot()
1010       
1011    def _on_perspective_selection(self, event=None):
1012        """
1013        select the current perspective for guiframe
1014        """
1015        selection = self.perspective_cbox.GetSelection()
1016        if self.perspective_cbox.GetValue() != 'None':
1017            perspective = self.perspective_cbox.GetClientData(selection)
1018            perspective.on_perspective(event=None)
1019            self.parent.check_multimode(perspective=perspective)
1020               
1021    def _on_plot_selection(self, event=None):
1022        """
1023        On source combobox selection
1024        """
1025        if event != None:
1026            combo = event.GetEventObject()
1027            event.Skip()
1028        else:
1029            combo = self.cb_plotpanel
1030        selection = combo.GetSelection()
1031
1032        if combo.GetValue() != 'None':
1033            panel = combo.GetClientData(selection)
1034            self.parent.on_set_plot_focus(panel)   
1035           
1036    def on_close_plot(self, event):
1037        """
1038        clseo the panel on focus
1039        """ 
1040        self.enable_append()
1041        selection = self.cb_plotpanel.GetSelection()
1042        if self.cb_plotpanel.GetValue() != 'None':
1043            panel = self.cb_plotpanel.GetClientData(selection)
1044            if self.parent is not None and panel is not None:
1045                wx.PostEvent(self.parent, 
1046                             NewPlotEvent(group_id=panel.group_id,
1047                                          action="delete"))
1048        self.enable_remove_plot()
1049       
1050    def enable_remove_plot(self):
1051        """
1052        enable remove plot button if there is a plot panel on focus
1053        """
1054        pass
1055        #if self.cb_plotpanel.GetCount() == 0:
1056        #    self.bt_close_plot.Disable()
1057        #else:
1058        #    self.bt_close_plot.Enable()
1059           
1060    def enable_remove(self):
1061        """
1062        enable or disable remove button
1063        """
1064        n_t = self.tree_ctrl.GetCount()
1065        n_t_t = self.tree_ctrl_theory.GetCount()
1066        if n_t + n_t_t <= 0:
1067            self.bt_remove.Disable()
1068        else:
1069            self.bt_remove.Enable()
1070           
1071    def enable_import(self):
1072        """
1073        enable or disable send button
1074        """
1075        n_t = 0
1076        if self.tree_ctrl != None:
1077            n_t = self.tree_ctrl.GetCount()
1078        if n_t > 0 and len(self.list_of_perspective) > 0:
1079            self.bt_import.Enable()
1080        else:
1081            self.bt_import.Disable()
1082        if len(self.list_of_perspective) <= 0 or \
1083            self.perspective_cbox.GetValue()  in ["None",
1084                                                "No Active Application"]:
1085            self.perspective_cbox.Disable()
1086        else:
1087            self.perspective_cbox.Enable()
1088           
1089    def enable_plot(self):
1090        """
1091        enable or disable plot button
1092        """
1093        n_t = 0 
1094        n_t_t = 0
1095        if self.tree_ctrl != None:
1096            n_t = self.tree_ctrl.GetCount()
1097        if self.tree_ctrl_theory != None:
1098            n_t_t = self.tree_ctrl_theory.GetCount()
1099        if n_t + n_t_t <= 0:
1100            self.bt_plot.Disable()
1101        else:
1102            self.bt_plot.Enable()
1103        self.enable_append()
1104       
1105    def enable_append(self):
1106        """
1107        enable or disable append button
1108        """
1109        n_t = 0 
1110        n_t_t = 0
1111        if self.tree_ctrl != None:
1112            n_t = self.tree_ctrl.GetCount()
1113        if self.tree_ctrl_theory != None:
1114            n_t_t = self.tree_ctrl_theory.GetCount()
1115        if n_t + n_t_t <= 0: 
1116            self.bt_append_plot.Disable()
1117            self.cb_plotpanel.Disable()
1118        elif self.cb_plotpanel.GetCount() <= 0:
1119            self.cb_plotpanel.Disable()
1120            self.bt_append_plot.Disable()
1121        else:
1122            self.bt_append_plot.Enable()
1123            self.cb_plotpanel.Enable()
1124           
1125    def check_theory_to_freeze(self):
1126        """
1127        Check_theory_to_freeze
1128        """
1129    def enable_freeze(self):
1130        """
1131        enable or disable the freeze button
1132        """
1133        n_t_t = 0
1134        n_l = 0
1135        if self.tree_ctrl_theory != None:
1136            n_t_t = self.tree_ctrl_theory.GetCount()
1137        n_l = len(self.list_cb_theory)
1138        if (n_t_t + n_l > 0):
1139            self.bt_freeze.Enable()
1140        else:
1141            self.bt_freeze.Disable()
1142       
1143    def enable_selection(self):
1144        """
1145        enable or disable combobo box selection
1146        """
1147        n_t = 0
1148        n_t_t = 0
1149        if self.tree_ctrl != None:
1150            n_t = self.tree_ctrl.GetCount()
1151        if self.tree_ctrl_theory != None:
1152            n_t_t = self.tree_ctrl_theory.GetCount()
1153        if n_t + n_t_t > 0 and self.selection_cbox != None:
1154            self.selection_cbox.Enable()
1155        else:
1156            self.selection_cbox.Disable()
1157           
1158    def show_data_button(self):
1159        """
1160        show load data and remove data button if
1161        dataloader on else hide them
1162        """
1163        try:
1164            gui_style = self.parent.get_style()
1165            style = gui_style & GUIFRAME.DATALOADER_ON
1166            if style == GUIFRAME.DATALOADER_ON: 
1167                #self.bt_remove.Show(True)
1168                self.bt_add.Show(True) 
1169            else:
1170                #self.bt_remove.Hide()
1171                self.bt_add.Hide()
1172        except: 
1173            #self.bt_remove.Hide()
1174            self.bt_add.Hide() 
1175   
1176
1177
1178WIDTH = 400
1179HEIGHT = 300
1180
1181
1182class DataDialog(wx.Dialog):
1183    """
1184    Allow file selection at loading time
1185    """
1186    def __init__(self, data_list, parent=None, text='', *args, **kwds):
1187        wx.Dialog.__init__(self, parent, *args, **kwds)
1188        self.SetTitle("Data Selection")
1189        self.SetSize((WIDTH, HEIGHT))
1190        self.list_of_ctrl = []
1191        if not data_list:
1192            return 
1193        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
1194        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
1195        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
1196        self.sizer = wx.GridBagSizer(5, 5)
1197        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
1198                               size=(WIDTH-20, HEIGHT-50))
1199        self._panel.SetupScrolling()
1200        self.__do_layout(data_list, text=text)
1201       
1202    def __do_layout(self, data_list, text=''):
1203        """
1204        layout the dialog
1205        """
1206        if not data_list or len(data_list) <= 1:
1207            return 
1208        #add text
1209       
1210        text = "Deleting these file reset some panels.\n"
1211        text += "Do you want to proceed?\n"
1212        text_ctrl = wx.StaticText(self, -1, str(text))
1213        self._sizer_txt.Add(text_ctrl)
1214        iy = 0
1215        ix = 0
1216        #data_count = 0
1217        for (data_name, in_use, sub_menu) in range(len(data_list)):
1218            if in_use == True:
1219                ctrl_name = wx.StaticBox(self, -1, str(data_name))
1220                ctrl_in_use = wx.StaticBox(self, -1, " is used by ")
1221                plug_name = str(sub_menu) + "\n"
1222                #ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)
1223                self.sizer.Add(ctrl_name, (iy, ix),
1224                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
1225                ix += 1
1226                self._sizer_button.Add(ctrl_in_use, 1,
1227                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1228                ix += 1
1229                self._sizer_button.Add(plug_name, 1,
1230                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1231            iy += 1
1232        self._panel.SetSizer(self.sizer)
1233        #add sizer
1234        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1235        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
1236        self._sizer_button.Add(button_cancel, 0,
1237                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1238        button_OK = wx.Button(self, wx.ID_OK, "Ok")
1239        button_OK.SetFocus()
1240        self._sizer_button.Add(button_OK, 0,
1241                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1242        static_line = wx.StaticLine(self, -1)
1243       
1244        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
1245        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
1246        #self._sizer_main.Add(self._data_text_ctrl, 0,
1247        #                     wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
1248        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
1249        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
1250        self.SetSizer(self._sizer_main)
1251        self.Layout()
1252       
1253    def get_data(self):
1254        """
1255        return the selected data
1256        """
1257        temp = []
1258        for item in self.list_of_ctrl:
1259            cb, data = item
1260            if cb.GetValue():
1261                temp.append(data)
1262        return temp
1263           
1264class DataFrame(wx.Frame):
1265    """
1266    Data Frame
1267    """
1268    ## Internal name for the AUI manager
1269    window_name = "Data Panel"
1270    ## Title to appear on top of the window
1271    window_caption = "Data Panel"
1272    ## Flag to tell the GUI manager that this panel is not
1273    #  tied to any perspective
1274    ALWAYS_ON = True
1275   
1276    def __init__(self, parent=None, owner=None, manager=None, size=(300, 800),
1277                         list_of_perspective=[], list=[], *args, **kwds):
1278        kwds['size'] = size
1279        kwds['id'] = -1
1280        kwds['title'] = "Loaded Data"
1281        wx.Frame.__init__(self, parent=parent, *args, **kwds)
1282        self.parent = parent
1283        self.owner = owner
1284        self.manager = manager
1285        self.panel = DataPanel(parent=self, 
1286                               #size=size,
1287                               list_of_perspective=list_of_perspective)
1288     
1289    def load_data_list(self, list=[]):
1290        """
1291        Fill the list inside its panel
1292        """
1293        self.panel.load_data_list(list=list)
1294       
1295   
1296   
1297from sans.guiframe.dataFitting import Theory1D
1298from sans.guiframe.data_state import DataState
1299
1300class State():
1301    """
1302    DataPanel State
1303    """
1304    def __init__(self):
1305        self.msg = ""
1306    def __str__(self):
1307        self.msg = "model mane : model1\n"
1308        self.msg += "params : \n"
1309        self.msg += "name  value\n"
1310        return self.msg
1311   
1312def set_data_state(data=None, path=None, theory=None, state=None):
1313    """
1314    Set data state
1315    """
1316    dstate = DataState(data=data)
1317    dstate.set_path(path=path)
1318    dstate.set_theory(theory, state)
1319 
1320    return dstate
1321   
1322if __name__ == "__main__":
1323   
1324    app = wx.App()
1325    try:
1326        #list_of_perspective = [('perspective2', False), ('perspective1', True)]
1327        data_list1 = {}
1328        # state 1
1329        data1 = Data2D()
1330        data1.name = "data2"
1331        data1.id = 1
1332        data1.append_empty_process()
1333        process1 = data1.process[len(data1.process)-1]
1334        process1.data = "07/01/2010"
1335        theory1 = Data2D()
1336        theory1.id = 34
1337        theory1.name = "theory1"
1338        path1 = "path1"
1339        state1 = State()
1340        data_list1['1'] = set_data_state(data1, path1, theory1, state1)
1341        #state 2
1342        data1 = Data2D()
1343        data1.name = "data2"
1344        data1.id = 76
1345        theory1 = Data2D()
1346        theory1.id = 78
1347        theory1.name = "CoreShell 07/24/25"
1348        path1 = "path2"
1349        #state3
1350        state1 = State()
1351        data_list1['2'] = set_data_state(data1, path1, theory1, state1)
1352        data1 = Data1D()
1353        data1.id = 3
1354        data1.name = "data2"
1355        theory1 = Theory1D()
1356        theory1.name = "CoreShell"
1357        theory1.id = 4
1358        theory1.append_empty_process()
1359        process1 = theory1.process[len(theory1.process)-1]
1360        process1.description = "this is my description"
1361        path1 = "path3"
1362        data1.append_empty_process()
1363        process1 = data1.process[len(data1.process)-1]
1364        process1.data = "07/22/2010"
1365        data_list1['4'] = set_data_state(data1, path1, theory1, state1)
1366        #state 4
1367        temp_data_list = {}
1368        data1.name = "data5 erasing data2"
1369        temp_data_list['4'] = set_data_state(data1, path1, theory1, state1)
1370        #state 5
1371        data1 = Data2D()
1372        data1.name = "data3"
1373        data1.id = 5
1374        data1.append_empty_process()
1375        process1 = data1.process[len(data1.process)-1]
1376        process1.data = "07/01/2010"
1377        theory1 = Theory1D()
1378        theory1.name = "Cylinder"
1379        path1 = "path2"
1380        state1 = State()
1381        dstate1 = set_data_state(data1, path1, theory1, state1)
1382        theory1 = Theory1D()
1383        theory1.id = 6
1384        theory1.name = "CoreShell"
1385        dstate1.set_theory(theory1)
1386        theory1 = Theory1D()
1387        theory1.id = 6
1388        theory1.name = "CoreShell replacing coreshell in data3"
1389        dstate1.set_theory(theory1)
1390        data_list1['3'] = dstate1
1391        #state 6
1392        data_list1['6'] = set_data_state(None, path1, theory1, state1)
1393        data_list1['6'] = set_data_state(theory=theory1, state=None)
1394        theory1 = Theory1D()
1395        theory1.id = 7
1396        data_list1['6'] = set_data_state(theory=theory1, state=None)
1397        data_list1['7'] = set_data_state(theory=theory1, state=None)
1398        window = DataFrame(list=data_list1)
1399        window.load_data_list(list=data_list1)
1400        window.Show(True)
1401        window.load_data_list(list=temp_data_list)
1402    except:
1403        #raise
1404        print "error", sys.exc_value
1405       
1406    app.MainLoop() 
1407   
1408   
Note: See TracBrowser for help on using the repository browser.