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

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since fe1eb94 was d6e36e44, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Select/deselct children datasets when select/deselect all is clicked (fixes #259)

  • 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):
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        msg = "This operation will delete the data sets checked "
898        msg += "and all the dependents."
899        msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)
900        if msg_box.ShowModal() != wx.ID_OK:
901            return
902
903        data_to_remove, theory_to_remove, _ = self.set_data_helper()
904        data_key = []
905        theory_key = []
906        #remove  data from treectrl
907        for d_key, item in self.list_cb_data.iteritems():
908            data_c, _, _, _,  _, _, _, _ = item
909            if data_c.IsChecked():
910                self.tree_ctrl.Delete(data_c)
911                data_key.append(d_key)
912                if d_key in self.list_cb_theory.keys():
913                    theory_list_ctrl = self.list_cb_theory[d_key]
914                    theory_to_remove += theory_list_ctrl.keys()
915        # Remove theory from treectrl
916        for _, theory_dict in self.list_cb_theory.iteritems():
917            for  key, value in theory_dict.iteritems():
918                item, _, _ = value
919                if item.IsChecked():
920                    try:
921                        self.tree_ctrl.Delete(item)
922                    except:
923                        pass
924                    theory_key.append(key)
925
926        #Remove data and related theory references
927        for key in data_key:
928            del self.list_cb_data[key]
929            if key in theory_key:
930                del self.list_cb_theory[key]
931        #remove theory  references independently of data
932        for key in theory_key:
933            for _, theory_dict in self.list_cb_theory.iteritems():
934                if key in theory_dict:
935                    for  key, value in theory_dict.iteritems():
936                        item, _, _ = value
937                        if item.IsChecked():
938                            try:
939                                self.tree_ctrl_theory.Delete(item)
940                            except:
941                                pass
942                    del theory_dict[key]
943
944
945        self.parent.remove_data(data_id=data_to_remove,
946                                  theory_id=theory_to_remove)
947        self.enable_remove()
948        self.enable_freeze()
949        self.enable_remove_plot()
950
951    def on_import(self, event=None):
952        """
953        Get all select data and set them to the current active perspetive
954        """
955        if event != None:
956            event.Skip()
957        data_id, theory_id, state_id = self.set_data_helper()
958        temp = data_id + state_id
959        self.parent.set_data(data_id=temp, theory_id=theory_id)
960
961    def on_append_plot(self, event=None):
962        """
963        append plot to plot panel on focus
964        """
965        self._on_plot_selection()
966        data_id, theory_id, state_id = self.set_data_helper()
967        self.parent.plot_data(data_id=data_id,
968                              state_id=state_id,
969                              theory_id=theory_id,
970                              append=True)
971
972    def on_plot(self, event=None):
973        """
974        Send a list of data names to plot
975        """
976        data_id, theory_id, state_id = self.set_data_helper()
977        self.parent.plot_data(data_id=data_id,
978                              state_id=state_id,
979                              theory_id=theory_id,
980                              append=False)
981        self.enable_remove_plot()
982
983    def on_close_page(self, event=None):
984        """
985        On close
986        """
987        if event != None:
988            event.Skip()
989        # send parent to update menu with no show nor hide action
990        self.parent.show_data_panel(action=False)
991
992    def on_freeze(self, event):
993        """
994        On freeze to make a theory to a data set
995        """
996        _, theory_id, state_id = self.set_data_helper()
997        if len(theory_id) > 0:
998            self.parent.freeze(data_id=state_id, theory_id=theory_id)
999            msg = "Freeze Theory:"
1000            msg += " The theory(s) copied to the Data box as a data set."
1001        else:
1002            msg = "Freeze Theory: Requires at least one theory checked."
1003        wx.PostEvent(self.parent, StatusEvent(status=msg))
1004
1005    def set_active_perspective(self, name):
1006        """
1007        set the active perspective
1008        """
1009        self.perspective_cbox.SetStringSelection(name)
1010        self.enable_import()
1011
1012    def _on_delete_plot_panel(self, event):
1013        """
1014        get an event with attribute name and caption to delete existing name
1015        from the combobox of the current panel
1016        """
1017        #name = event.name
1018        caption = event.caption
1019        if self.cb_plotpanel is not None:
1020            pos = self.cb_plotpanel.FindString(str(caption))
1021            if pos != wx.NOT_FOUND:
1022                self.cb_plotpanel.Delete(pos)
1023        self.enable_append()
1024
1025    def set_panel_on_focus(self, name=None):
1026        """
1027        set the plot panel on focus
1028        """
1029        if self.cb_plotpanel and self.cb_plotpanel.IsBeingDeleted():
1030            return
1031        for _, value in self.parent.plot_panels.iteritems():
1032            name_plot_panel = str(value.window_caption)
1033            if name_plot_panel not in self.cb_plotpanel.GetItems():
1034                self.cb_plotpanel.Append(name_plot_panel, value)
1035            if name != None and name == name_plot_panel:
1036                self.cb_plotpanel.SetStringSelection(name_plot_panel)
1037                break
1038        self.enable_append()
1039        self.enable_remove_plot()
1040
1041    def set_plot_unfocus(self):
1042        """
1043        Unfocus plot
1044        """
1045        return
1046
1047    def _on_perspective_selection(self, event=None):
1048        """
1049        select the current perspective for guiframe
1050        """
1051        selection = self.perspective_cbox.GetSelection()
1052        if self.perspective_cbox.GetValue() != 'None':
1053            perspective = self.perspective_cbox.GetClientData(selection)
1054            perspective.on_perspective(event=None)
1055            self.parent.check_multimode(perspective=perspective)
1056
1057    def _on_plot_selection(self, event=None):
1058        """
1059        On source combobox selection
1060        """
1061        if event != None:
1062            combo = event.GetEventObject()
1063            event.Skip()
1064        else:
1065            combo = self.cb_plotpanel
1066        selection = combo.GetSelection()
1067
1068        if combo.GetValue() != 'None':
1069            panel = combo.GetClientData(selection)
1070            self.parent.on_set_plot_focus(panel)
1071
1072    def on_close_plot(self, event):
1073        """
1074        clseo the panel on focus
1075        """
1076        self.enable_append()
1077        selection = self.cb_plotpanel.GetSelection()
1078        if self.cb_plotpanel.GetValue() != 'None':
1079            panel = self.cb_plotpanel.GetClientData(selection)
1080            if self.parent is not None and panel is not None:
1081                wx.PostEvent(self.parent,
1082                             NewPlotEvent(group_id=panel.group_id,
1083                                          action="delete"))
1084        self.enable_remove_plot()
1085
1086    def set_frame(self, frame):
1087        """
1088        """
1089        self.frame = frame
1090
1091    def get_frame(self):
1092        """
1093        """
1094        return self.frame
1095
1096    def on_help(self, event):
1097        """
1098        Bring up the data manager Documentation whenever
1099        the HELP button is clicked.
1100
1101        Calls DocumentationWindow with the path of the location within the
1102        documentation tree (after /doc/ ....".  Note that when using old
1103        versions of Wx (before 2.9) and thus not the release version of
1104        installers, the help comes up at the top level of the file as
1105        webbrowser does not pass anything past the # to the browser when it is
1106        running "file:///...."
1107
1108    :param evt: Triggers on clicking the help button
1109    """
1110
1111        #import documentation window here to avoid circular imports
1112        #if put at top of file with rest of imports.
1113        from documentation_window import DocumentationWindow
1114
1115        _TreeLocation = "user/sasgui/guiframe/data_explorer_help.html"
1116        _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "",
1117                                          "Data Explorer Help")
1118
1119    def on_close(self, event):
1120        """
1121        On close event
1122        """
1123        self.parent.show_data_panel(event)
1124
1125    def set_schedule_full_draw(self, panel=None, func='del'):
1126        """
1127        Send full draw to guimanager
1128        """
1129        self.parent.set_schedule_full_draw(panel, func)
1130
1131    def enable_remove_plot(self):
1132        """
1133        enable remove plot button if there is a plot panel on focus
1134        """
1135        pass
1136        #if self.cb_plotpanel.GetCount() == 0:
1137        #    self.bt_close_plot.Disable()
1138        #else:
1139        #    self.bt_close_plot.Enable()
1140
1141    def enable_remove(self):
1142        """
1143        enable or disable remove button
1144        """
1145        n_t = self.tree_ctrl.GetCount()
1146        n_t_t = self.tree_ctrl_theory.GetCount()
1147        if n_t + n_t_t <= 0:
1148            self.bt_remove.Disable()
1149        else:
1150            self.bt_remove.Enable()
1151
1152    def enable_import(self):
1153        """
1154        enable or disable send button
1155        """
1156        n_t = 0
1157        if self.tree_ctrl != None:
1158            n_t = self.tree_ctrl.GetCount()
1159        if n_t > 0 and len(self.list_of_perspective) > 0:
1160            self.bt_import.Enable()
1161        else:
1162            self.bt_import.Disable()
1163        if len(self.list_of_perspective) <= 0 or \
1164            self.perspective_cbox.GetValue()  in ["None",
1165                                                "No Active Application"]:
1166            self.perspective_cbox.Disable()
1167        else:
1168            self.perspective_cbox.Enable()
1169
1170    def enable_plot(self):
1171        """
1172        enable or disable plot button
1173        """
1174        n_t = 0
1175        n_t_t = 0
1176        if self.tree_ctrl != None:
1177            n_t = self.tree_ctrl.GetCount()
1178        if self.tree_ctrl_theory != None:
1179            n_t_t = self.tree_ctrl_theory.GetCount()
1180        if n_t + n_t_t <= 0:
1181            self.bt_plot.Disable()
1182        else:
1183            self.bt_plot.Enable()
1184        self.enable_append()
1185
1186    def enable_append(self):
1187        """
1188        enable or disable append button
1189        """
1190        n_t = 0
1191        n_t_t = 0
1192        if self.tree_ctrl != None:
1193            n_t = self.tree_ctrl.GetCount()
1194        if self.tree_ctrl_theory != None:
1195            n_t_t = self.tree_ctrl_theory.GetCount()
1196        if n_t + n_t_t <= 0:
1197            self.bt_append_plot.Disable()
1198            self.cb_plotpanel.Disable()
1199        elif self.cb_plotpanel.GetCount() <= 0:
1200            self.cb_plotpanel.Disable()
1201            self.bt_append_plot.Disable()
1202        else:
1203            self.bt_append_plot.Enable()
1204            self.cb_plotpanel.Enable()
1205
1206    def check_theory_to_freeze(self):
1207        """
1208        Check_theory_to_freeze
1209        """
1210    def enable_freeze(self):
1211        """
1212        enable or disable the freeze button
1213        """
1214        n_t_t = 0
1215        n_l = 0
1216        if self.tree_ctrl_theory != None:
1217            n_t_t = self.tree_ctrl_theory.GetCount()
1218        n_l = len(self.list_cb_theory)
1219        if (n_t_t + n_l > 0):
1220            self.bt_freeze.Enable()
1221        else:
1222            self.bt_freeze.Disable()
1223
1224    def enable_selection(self):
1225        """
1226        enable or disable combobo box selection
1227        """
1228        n_t = 0
1229        n_t_t = 0
1230        if self.tree_ctrl != None:
1231            n_t = self.tree_ctrl.GetCount()
1232        if self.tree_ctrl_theory != None:
1233            n_t_t = self.tree_ctrl_theory.GetCount()
1234        if n_t + n_t_t > 0 and self.selection_cbox != None:
1235            self.selection_cbox.Enable()
1236        else:
1237            self.selection_cbox.Disable()
1238
1239    def show_data_button(self):
1240        """
1241        show load data and remove data button if
1242        dataloader on else hide them
1243        """
1244        try:
1245            gui_style = self.parent.get_style()
1246            style = gui_style & GUIFRAME.DATALOADER_ON
1247            if style == GUIFRAME.DATALOADER_ON:
1248                #self.bt_remove.Show(True)
1249                self.bt_add.Show(True)
1250            else:
1251                #self.bt_remove.Hide()
1252                self.bt_add.Hide()
1253        except:
1254            #self.bt_remove.Hide()
1255            self.bt_add.Hide()
1256
1257
1258
1259WIDTH = 400
1260HEIGHT = 300
1261
1262
1263class DataDialog(wx.Dialog):
1264    """
1265    Allow file selection at loading time
1266    """
1267    def __init__(self, data_list, parent=None, text='', *args, **kwds):
1268        wx.Dialog.__init__(self, parent, *args, **kwds)
1269        self.SetTitle("Data Selection")
1270        self.SetSize((WIDTH, HEIGHT))
1271        self.list_of_ctrl = []
1272        if not data_list:
1273            return
1274        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
1275        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
1276        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
1277        self.sizer = wx.GridBagSizer(5, 5)
1278        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
1279                               size=(WIDTH-20, HEIGHT-50))
1280        self._panel.SetupScrolling()
1281        self.__do_layout(data_list, text=text)
1282
1283    def __do_layout(self, data_list, text=''):
1284        """
1285        layout the dialog
1286        """
1287        if not data_list or len(data_list) <= 1:
1288            return
1289        #add text
1290
1291        text = "Deleting these file reset some panels.\n"
1292        text += "Do you want to proceed?\n"
1293        text_ctrl = wx.StaticText(self, -1, str(text))
1294        self._sizer_txt.Add(text_ctrl)
1295        iy = 0
1296        ix = 0
1297        #data_count = 0
1298        for (data_name, in_use, sub_menu) in range(len(data_list)):
1299            if in_use == True:
1300                ctrl_name = wx.StaticBox(self, -1, str(data_name))
1301                ctrl_in_use = wx.StaticBox(self, -1, " is used by ")
1302                plug_name = str(sub_menu) + "\n"
1303                #ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)
1304                self.sizer.Add(ctrl_name, (iy, ix),
1305                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
1306                ix += 1
1307                self._sizer_button.Add(ctrl_in_use, 1,
1308                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1309                ix += 1
1310                self._sizer_button.Add(plug_name, 1,
1311                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1312            iy += 1
1313        self._panel.SetSizer(self.sizer)
1314        #add sizer
1315        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1316        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
1317        self._sizer_button.Add(button_cancel, 0,
1318                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1319        button_OK = wx.Button(self, wx.ID_OK, "Ok")
1320        button_OK.SetFocus()
1321        self._sizer_button.Add(button_OK, 0,
1322                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1323        static_line = wx.StaticLine(self, -1)
1324
1325        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
1326        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
1327        #self._sizer_main.Add(self._data_text_ctrl, 0,
1328        #                     wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
1329        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
1330        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
1331        self.SetSizer(self._sizer_main)
1332        self.Layout()
1333
1334    def get_data(self):
1335        """
1336        return the selected data
1337        """
1338        temp = []
1339        for item in self.list_of_ctrl:
1340            cb, data = item
1341            if cb.GetValue():
1342                temp.append(data)
1343        return temp
1344
1345class DataFrame(wx.Frame):
1346    """
1347    Data Frame
1348    """
1349    ## Internal name for the AUI manager
1350    window_name = "Data Panel"
1351    ## Title to appear on top of the window
1352    window_caption = "Data Panel"
1353    ## Flag to tell the GUI manager that this panel is not
1354    #  tied to any perspective
1355    ALWAYS_ON = True
1356
1357    def __init__(self, parent=None, owner=None, manager=None, size=(300, 800),
1358                         list_of_perspective=[], list=[], *args, **kwds):
1359        kwds['size'] = size
1360        kwds['id'] = -1
1361        kwds['title'] = "Loaded Data"
1362        wx.Frame.__init__(self, parent=parent, *args, **kwds)
1363        self.parent = parent
1364        self.owner = owner
1365        self._manager = manager
1366        self.panel = DataPanel(parent=self,
1367                               manager=manager,
1368                               list_of_perspective=list_of_perspective)
1369
1370    def load_data_list(self, list=[]):
1371        """
1372        Fill the list inside its panel
1373        """
1374        self.panel.load_data_list(list=list)
1375
1376
1377
1378from sas.sasgui.guiframe.dataFitting import Theory1D
1379from sas.sasgui.guiframe.data_state import DataState
1380
1381class State():
1382    """
1383    DataPanel State
1384    """
1385    def __init__(self):
1386        self.msg = ""
1387    def __str__(self):
1388        self.msg = "model mane : model1\n"
1389        self.msg += "params : \n"
1390        self.msg += "name  value\n"
1391        return self.msg
1392
1393def set_data_state(data=None, path=None, theory=None, state=None):
1394    """
1395    Set data state
1396    """
1397    dstate = DataState(data=data)
1398    dstate.set_path(path=path)
1399    dstate.set_theory(theory, state)
1400
1401    return dstate
1402
1403if __name__ == "__main__":
1404
1405    app = wx.App()
1406    try:
1407        #list_of_perspective = [('perspective2', False), ('perspective1', True)]
1408        data_list1 = {}
1409        # state 1
1410        data1 = Data2D()
1411        data1.name = "data2"
1412        data1.id = 1
1413        data1.append_empty_process()
1414        process1 = data1.process[len(data1.process)-1]
1415        process1.data = "07/01/2010"
1416        theory1 = Data2D()
1417        theory1.id = 34
1418        theory1.name = "theory1"
1419        path1 = "path1"
1420        state1 = State()
1421        data_list1['1'] = set_data_state(data1, path1, theory1, state1)
1422        #state 2
1423        data1 = Data2D()
1424        data1.name = "data2"
1425        data1.id = 76
1426        theory1 = Data2D()
1427        theory1.id = 78
1428        theory1.name = "CoreShell 07/24/25"
1429        path1 = "path2"
1430        #state3
1431        state1 = State()
1432        data_list1['2'] = set_data_state(data1, path1, theory1, state1)
1433        data1 = Data1D()
1434        data1.id = 3
1435        data1.name = "data2"
1436        theory1 = Theory1D()
1437        theory1.name = "CoreShell"
1438        theory1.id = 4
1439        theory1.append_empty_process()
1440        process1 = theory1.process[len(theory1.process)-1]
1441        process1.description = "this is my description"
1442        path1 = "path3"
1443        data1.append_empty_process()
1444        process1 = data1.process[len(data1.process)-1]
1445        process1.data = "07/22/2010"
1446        data_list1['4'] = set_data_state(data1, path1, theory1, state1)
1447        #state 4
1448        temp_data_list = {}
1449        data1.name = "data5 erasing data2"
1450        temp_data_list['4'] = set_data_state(data1, path1, theory1, state1)
1451        #state 5
1452        data1 = Data2D()
1453        data1.name = "data3"
1454        data1.id = 5
1455        data1.append_empty_process()
1456        process1 = data1.process[len(data1.process)-1]
1457        process1.data = "07/01/2010"
1458        theory1 = Theory1D()
1459        theory1.name = "Cylinder"
1460        path1 = "path2"
1461        state1 = State()
1462        dstate1 = set_data_state(data1, path1, theory1, state1)
1463        theory1 = Theory1D()
1464        theory1.id = 6
1465        theory1.name = "CoreShell"
1466        dstate1.set_theory(theory1)
1467        theory1 = Theory1D()
1468        theory1.id = 6
1469        theory1.name = "CoreShell replacing coreshell in data3"
1470        dstate1.set_theory(theory1)
1471        data_list1['3'] = dstate1
1472        #state 6
1473        data_list1['6'] = set_data_state(None, path1, theory1, state1)
1474        data_list1['6'] = set_data_state(theory=theory1, state=None)
1475        theory1 = Theory1D()
1476        theory1.id = 7
1477        data_list1['6'] = set_data_state(theory=theory1, state=None)
1478        data_list1['7'] = set_data_state(theory=theory1, state=None)
1479        window = DataFrame(list=data_list1)
1480        window.load_data_list(list=data_list1)
1481        window.Show(True)
1482        window.load_data_list(list=temp_data_list)
1483    except:
1484        #raise
1485        print "error", sys.exc_value
1486
1487    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.