source: sasview/src/sas/sasgui/guiframe/data_panel.py @ 998ca90

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 998ca90 was 998ca90, checked in by krzywon, 7 years ago

#189 #12 Saving and loading project now fully saves and loads a simultaneous fits. Loading a project will reset Sasview state to its base state (with a warning). One error on load to fix before calling this finished.

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