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

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 66aeb15 was 66aeb15, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

data panel: put the data/theory label in the tree root so it is visible even when the tree is closed

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