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

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 c8e1996 was c8e1996, checked in by krzywon, 8 years ago

Fixes #738: No errors are thrown on loading projects with fits, plus linting.

  • Property mode set to 100644
File size: 56.1 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, *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("Available Data")
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        tree_ctrl_label = wx.StaticText(self, -1, "Data")
523        tree_ctrl_label.SetForegroundColour('blue')
524        self.tree_ctrl = DataTreeCtrl(parent=self, style=wx.SUNKEN_BORDER)
525        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item)
526        self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_MENU, self.on_right_click_data)
527        # Create context menu for page
528        self.data_menu = wx.Menu()
529        id = wx.NewId()
530        name = "Data Info"
531        msg = "Show Data Info"
532        self.data_menu.Append(id, name, msg)
533        wx.EVT_MENU(self, id, self.on_data_info)
534
535        id = wx.NewId()
536        name = "Save As"
537        msg = "Save Theory/Data as a file"
538        self.data_menu.Append(id, name, msg)
539        wx.EVT_MENU(self, id, self.on_save_as)
540
541        quickplot_id = wx.NewId()
542        name = "Quick Plot"
543        msg = "Plot the current Data"
544        self.data_menu.Append(quickplot_id, name, msg)
545        wx.EVT_MENU(self, quickplot_id, self.on_quick_plot)
546
547        self.plot3d_id = wx.NewId()
548        name = "Quick 3DPlot (Slow)"
549        msg = "Plot3D the current 2D Data"
550        self.data_menu.Append(self.plot3d_id, name, msg)
551        wx.EVT_MENU(self, self.plot3d_id, self.on_plot_3d)
552
553        self.editmask_id = wx.NewId()
554        name = "Edit Mask"
555        msg = "Edit Mask for the current 2D Data"
556        self.data_menu.Append(self.editmask_id, name, msg)
557        wx.EVT_MENU(self, self.editmask_id, self.on_edit_data)
558
559        tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory")
560        tree_ctrl_theory_label.SetForegroundColour('blue')
561        self.tree_ctrl_theory = DataTreeCtrl(parent=self,
562                                             style=wx.SUNKEN_BORDER)
563        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING,
564                                   self.on_check_item)
565        self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_MENU,
566                                   self.on_right_click_theory)
567        self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10)
568        self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND | wx.ALL, 10)
569        self.sizer1.Add(tree_ctrl_theory_label, 0,  wx.LEFT, 10)
570        self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND | wx.ALL, 10)
571
572    def on_right_click_theory(self, event):
573        """
574        On click theory data
575        """
576        try:
577            id, data_class_name, _ = \
578                            self.tree_ctrl_theory.GetSelection().GetData()
579            _, _ = self.parent.get_data_manager().get_by_id(id_list=[id])
580        except:
581            return
582        if self.data_menu is not None:
583            menu_enable = (data_class_name == "Data2D")
584            self.data_menu.Enable(self.editmask_id, False)
585            self.data_menu.Enable(self.plot3d_id, menu_enable)
586            self.PopupMenu(self.data_menu)
587
588    def on_right_click_data(self, event):
589        """
590        Allow Editing Data
591        """
592        # selection = event.GetSelection()
593        is_data = True
594        try:
595            id, data_class_name, _ = self.tree_ctrl.GetSelection().GetData()
596            data_list, _ = \
597                self.parent.get_data_manager().get_by_id(id_list=[id])
598            if not data_list:
599                is_data = False
600        except:
601            return
602        if self.data_menu is not None:
603            menu_enable = (data_class_name == "Data2D")
604            maskmenu_enable = (menu_enable and is_data)
605            self.data_menu.Enable(self.editmask_id, maskmenu_enable)
606            self.data_menu.Enable(self.plot3d_id, menu_enable)
607            self.PopupMenu(self.data_menu)
608
609    def onContextMenu(self, event):
610        """
611        Retrieve the state selected state
612        """
613        # Skipping the save state functionality for release 0.9.0
614        # return
615        pos = event.GetPosition()
616        pos = self.ScreenToClient(pos)
617        self.PopupMenu(self.popUpMenu, pos)
618
619    def on_check_item(self, event):
620        """
621        On check item
622        """
623        item = event.GetItem()
624        item.Check(not item.IsChecked())
625        self.enable_append()
626        self.enable_freeze()
627        self.enable_plot()
628        self.enable_import()
629        self.enable_remove()
630        event.Skip()
631
632    def fill_cbox_analysis(self, plugin):
633        """
634        fill the combobox with analysis name
635        """
636        self.list_of_perspective = plugin
637        if self.parent is None or \
638            not hasattr(self.parent, "get_current_perspective") or \
639                        len(self.list_of_perspective) == 0:
640            return
641        if self.parent is not None and self.perspective_cbox is not None:
642            for plug in self.list_of_perspective:
643                if plug.get_perspective():
644                    self.perspective_cbox.Append(plug.sub_menu, plug)
645
646            curr_pers = self.parent.get_current_perspective()
647            if curr_pers:
648                self.perspective_cbox.SetStringSelection(curr_pers.sub_menu)
649                self.enable_import()
650
651    def load_data_list(self, list):
652        """
653        add need data with its theory under the tree
654        """
655        if list:
656            for state_id, dstate in list.iteritems():
657                data = dstate.get_data()
658                theory_list = dstate.get_theory()
659                if data is not None:
660                    data_name = str(data.name)
661                    data_title = str(data.title)
662                    data_run = str(data.run)
663                    data_class = data.__class__.__name__
664                    path = dstate.get_path()
665                    process_list = data.process
666                    data_id = data.id
667                    s_path = str(path)
668                    if state_id not in self.list_cb_data:
669                        # new state
670                        data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,
671                                                           0, data_name,
672                                                           ct_type=1,
673                                        data=(data_id, data_class, state_id))
674                        data_c.Check(True)
675                        d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info')
676                        d_t_c = self.tree_ctrl.AppendItem(d_i_c,
677                                                          'Title: %s' %
678                                                          data_title)
679                        r_n_c = self.tree_ctrl.AppendItem(d_i_c,
680                                                          'Run: %s' % data_run)
681                        i_c_c = self.tree_ctrl.AppendItem(d_i_c,
682                                                          'Type: %s' %
683                                                          data_class)
684                        p_c_c = self.tree_ctrl.AppendItem(d_i_c,
685                                                          "Path: '%s'" % s_path)
686                        d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process')
687
688                        for process in process_list:
689                            process_str = str(process).replace('\n', ' ')
690                            if len(process_str) > 20:
691                                process_str = process_str[:20] + ' [...]'
692                            self.tree_ctrl.AppendItem(d_p_c, process_str)
693                        theory_child = self.tree_ctrl.AppendItem(data_c,
694                                                                 "THEORIES")
695                        self.list_cb_data[state_id] = [data_c,
696                                                       d_i_c,
697                                                       d_t_c,
698                                                       r_n_c,
699                                                       i_c_c,
700                                                       p_c_c,
701                                                       d_p_c,
702                                                       theory_child]
703                    else:
704                        data_ctrl_list = self.list_cb_data[state_id]
705                        # This state is already display replace it contains
706                        data_c, d_i_c, d_t_c, r_n_c,  i_c_c, p_c_c, d_p_c, _ \
707                                = data_ctrl_list
708                        self.tree_ctrl.SetItemText(data_c, data_name)
709                        temp = (data_id, data_class, state_id)
710                        self.tree_ctrl.SetItemPyData(data_c, temp)
711                        self.tree_ctrl.SetItemText(i_c_c,
712                                                   'Type: %s' % data_class)
713                        self.tree_ctrl.SetItemText(p_c_c,
714                                                   'Path: %s' % s_path)
715                        self.tree_ctrl.DeleteChildren(d_p_c)
716                        for process in process_list:
717                            if not process.is_empty():
718                                _ = self.tree_ctrl.AppendItem(d_p_c,
719                                                    process.single_line_desc())
720                wx.CallAfter(self.append_theory, state_id, theory_list)
721            # Sort by data name
722            if self.tree_ctrl.root:
723                self.tree_ctrl.SortChildren(self.tree_ctrl.root)
724        self.enable_remove()
725        self.enable_import()
726        self.enable_plot()
727        self.enable_freeze()
728        self.enable_selection()
729
730    def _uncheck_all(self):
731        """
732        Uncheck all check boxes
733        """
734        for item in self.list_cb_data.values():
735            data_ctrl, _, _, _, _, _, _, _ = item
736            self.tree_ctrl.CheckItem(data_ctrl, False)
737        self.enable_append()
738        self.enable_freeze()
739        self.enable_plot()
740        self.enable_import()
741        self.enable_remove()
742
743    def append_theory(self, state_id, theory_list):
744        """
745        append theory object under data from a state of id = state_id
746        replace that theory if  already displayed
747        """
748        if not theory_list:
749            return
750        if state_id not in self.list_cb_data.keys():
751            root = self.tree_ctrl_theory.root
752            tree = self.tree_ctrl_theory
753        else:
754            item = self.list_cb_data[state_id]
755            data_c, _, _, _, _, _, _, _ = item
756            root = data_c
757            tree = self.tree_ctrl
758        if root is not None:
759            wx.CallAfter(self.append_theory_helper, tree=tree, root=root,
760                                       state_id=state_id,
761                                       theory_list=theory_list)
762
763    def append_theory_helper(self, tree, root, state_id, theory_list):
764        """
765        Append theory helper
766        """
767        if state_id in self.list_cb_theory.keys():
768            # update current list of theory for this data
769            theory_list_ctrl = self.list_cb_theory[state_id]
770
771            for theory_id, item in theory_list.iteritems():
772                theory_data, _ = item
773                if theory_data is None:
774                    name = "Unknown"
775                    theory_class = "Unknown"
776                    theory_id = "Unknown"
777                    temp = (None, None, None)
778                else:
779                    name = theory_data.name
780                    theory_class = theory_data.__class__.__name__
781                    theory_id = theory_data.id
782                    # if theory_state is not None:
783                    #    name = theory_state.model.name
784                    temp = (theory_id, theory_class, state_id)
785                if theory_id not in theory_list_ctrl:
786                    # add new theory
787                    t_child = tree.AppendItem(root,
788                                                    name, ct_type=1, data=temp)
789                    t_i_c = tree.AppendItem(t_child, 'Info')
790                    i_c_c = tree.AppendItem(t_i_c,
791                                                  'Type: %s' % theory_class)
792                    t_p_c = tree.AppendItem(t_i_c, 'Process')
793
794                    for process in theory_data.process:
795                        tree.AppendItem(t_p_c, process.__str__())
796                    theory_list_ctrl[theory_id] = [t_child,
797                                                   i_c_c,
798                                                   t_p_c]
799                else:
800                    # replace theory
801                    t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id]
802                    tree.SetItemText(t_child, name)
803                    tree.SetItemPyData(t_child, temp)
804                    tree.SetItemText(i_c_c, 'Type: %s' % theory_class)
805                    tree.DeleteChildren(t_p_c)
806                    for process in theory_data.process:
807                        tree.AppendItem(t_p_c, process.__str__())
808
809        else:
810            # data didn't have a theory associated it before
811            theory_list_ctrl = {}
812            for theory_id, item in theory_list.iteritems():
813                theory_data, _ = item
814                if theory_data is not None:
815                    name = theory_data.name
816                    theory_class = theory_data.__class__.__name__
817                    theory_id = theory_data.id
818                    # if theory_state is not None:
819                    #    name = theory_state.model.name
820                    temp = (theory_id, theory_class, state_id)
821                    t_child = tree.AppendItem(root,
822                            name, ct_type=1,
823                            data=(theory_data.id, theory_class, state_id))
824                    t_i_c = tree.AppendItem(t_child, 'Info')
825                    i_c_c = tree.AppendItem(t_i_c,
826                                                  'Type: %s' % theory_class)
827                    t_p_c = tree.AppendItem(t_i_c, 'Process')
828
829                    for process in theory_data.process:
830                        tree.AppendItem(t_p_c, process.__str__())
831
832                    theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c]
833                # self.list_cb_theory[data_id] = theory_list_ctrl
834                self.list_cb_theory[state_id] = theory_list_ctrl
835
836    def set_data_helper(self):
837        """
838        Set data helper
839        """
840        data_to_plot = []
841        state_to_plot = []
842        theory_to_plot = []
843        for value in self.list_cb_data.values():
844            item, _, _, _, _, _, _,  _ = value
845            if item.IsChecked():
846                data_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
847                data_to_plot.append(data_id)
848                if state_id not in state_to_plot:
849                    state_to_plot.append(state_id)
850
851        for theory_dict in self.list_cb_theory.values():
852            for _, value in theory_dict.iteritems():
853                item, _, _ = value
854                if item.IsChecked():
855                    theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item)
856                    theory_to_plot.append(theory_id)
857                    if state_id not in state_to_plot:
858                        state_to_plot.append(state_id)
859        return data_to_plot, theory_to_plot, state_to_plot
860
861    def remove_by_id(self, id):
862        """
863        Remove_dat by id
864        """
865        for item in self.list_cb_data.values():
866            data_c, _, _, _, _, _,  _, _ = item
867            data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c)
868            if id == data_id:
869                self.tree_ctrl.Delete(data_c)
870                del self.list_cb_data[state_id]
871                del self.list_cb_theory[data_id]
872
873    def load_error(self, error=None):
874        """
875        Pop up an error message.
876
877        :param error: details error message to be displayed
878        """
879        if error is not None or str(error).strip() != "":
880            dial = wx.MessageDialog(self.parent, str(error),
881                                    'Error Loading File',
882                                    wx.OK | wx.ICON_EXCLAMATION)
883            dial.ShowModal()
884
885    def _load_data(self, event):
886        """
887        send an event to the parent to trigger load from plugin module
888        """
889        if self.parent is not None:
890            wx.PostEvent(self.parent, NewLoadDataEvent())
891
892    def on_remove(self, event, prompt=True):
893        """
894        Get a list of item checked and remove them from the treectrl
895        Ask the parent to remove reference to this item
896        """
897        if prompt:
898            msg = "This operation will delete the data sets checked "
899            msg += "and all the dependents."
900            msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL)
901            if msg_box.ShowModal() != wx.ID_OK:
902                return
903
904        data_to_remove, theory_to_remove, _ = self.set_data_helper()
905        data_key = []
906        theory_key = []
907        # remove  data from treectrl
908        for d_key, item in self.list_cb_data.iteritems():
909            data_c, _, _, _,  _, _, _, _ = item
910            if data_c.IsChecked():
911                self.tree_ctrl.Delete(data_c)
912                data_key.append(d_key)
913                if d_key in self.list_cb_theory.keys():
914                    theory_list_ctrl = self.list_cb_theory[d_key]
915                    theory_to_remove += theory_list_ctrl.keys()
916        # Remove theory from treectrl
917        for _, theory_dict in self.list_cb_theory.iteritems():
918            for key, value in theory_dict.iteritems():
919                item, _, _ = value
920                if item.IsChecked():
921                    try:
922                        self.tree_ctrl.Delete(item)
923                    except:
924                        pass
925                    theory_key.append(key)
926
927        # Remove data and related theory references
928        for key in data_key:
929            del self.list_cb_data[key]
930            if key in theory_key:
931                del self.list_cb_theory[key]
932        # remove theory  references independently of data
933        for key in theory_key:
934            for _, theory_dict in self.list_cb_theory.iteritems():
935                if key in theory_dict:
936                    for key, value in theory_dict.iteritems():
937                        item, _, _ = value
938                        if item.IsChecked():
939                            try:
940                                self.tree_ctrl_theory.Delete(item)
941                            except:
942                                pass
943                    del theory_dict[key]
944
945        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 is not 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 is not 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 is not 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 is not 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 event: 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 is not 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 is not None:
1177            n_t = self.tree_ctrl.GetCount()
1178        if self.tree_ctrl_theory is not 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 is not None:
1193            n_t = self.tree_ctrl.GetCount()
1194        if self.tree_ctrl_theory is not 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 is not 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 is not None:
1231            n_t = self.tree_ctrl.GetCount()
1232        if self.tree_ctrl_theory is not None:
1233            n_t_t = self.tree_ctrl_theory.GetCount()
1234        if n_t + n_t_t > 0 and self.selection_cbox is not 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
1258WIDTH = 400
1259HEIGHT = 300
1260
1261
1262class DataDialog(wx.Dialog):
1263    """
1264    Allow file selection at loading time
1265    """
1266    def __init__(self, data_list, parent=None, text='', *args, **kwds):
1267        wx.Dialog.__init__(self, parent, *args, **kwds)
1268        self.SetTitle("Data Selection")
1269        self.SetSize((WIDTH, HEIGHT))
1270        self.list_of_ctrl = []
1271        if not data_list:
1272            return
1273        self._sizer_main = wx.BoxSizer(wx.VERTICAL)
1274        self._sizer_txt = wx.BoxSizer(wx.VERTICAL)
1275        self._sizer_button = wx.BoxSizer(wx.HORIZONTAL)
1276        self.sizer = wx.GridBagSizer(5, 5)
1277        self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER,
1278                               size=(WIDTH-20, HEIGHT-50))
1279        self._panel.SetupScrolling()
1280        self.__do_layout(data_list, text=text)
1281
1282    def __do_layout(self, data_list, text=''):
1283        """
1284        layout the dialog
1285        """
1286        if not data_list or len(data_list) <= 1:
1287            return
1288        # add text
1289
1290        text = "Deleting these file reset some panels.\n"
1291        text += "Do you want to proceed?\n"
1292        text_ctrl = wx.StaticText(self, -1, str(text))
1293        self._sizer_txt.Add(text_ctrl)
1294        iy = 0
1295        ix = 0
1296        # data_count = 0
1297        for (data_name, in_use, sub_menu) in range(len(data_list)):
1298            if in_use:
1299                ctrl_name = wx.StaticBox(self, -1, str(data_name))
1300                ctrl_in_use = wx.StaticBox(self, -1, " is used by ")
1301                plug_name = str(sub_menu) + "\n"
1302                # ctrl_sub_menu = wx.StaticBox(self, -1, plug_name)
1303                self.sizer.Add(ctrl_name, (iy, ix),
1304                           (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
1305                ix += 1
1306                self._sizer_button.Add(ctrl_in_use, 1,
1307                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1308                ix += 1
1309                self._sizer_button.Add(plug_name, 1,
1310                                        wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1311            iy += 1
1312        self._panel.SetSizer(self.sizer)
1313        # add sizer
1314        self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1315        button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
1316        self._sizer_button.Add(button_cancel, 0,
1317                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1318        button_OK = wx.Button(self, wx.ID_OK, "Ok")
1319        button_OK.SetFocus()
1320        self._sizer_button.Add(button_OK, 0,
1321                                wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
1322        static_line = wx.StaticLine(self, -1)
1323
1324        self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
1325        self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10)
1326        #self._sizer_main.Add(self._data_text_ctrl, 0,
1327        #                     wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
1328        self._sizer_main.Add(static_line, 0, wx.EXPAND, 0)
1329        self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10)
1330        self.SetSizer(self._sizer_main)
1331        self.Layout()
1332
1333    def get_data(self):
1334        """
1335        return the selected data
1336        """
1337        temp = []
1338        for item in self.list_of_ctrl:
1339            cb, data = item
1340            if cb.GetValue():
1341                temp.append(data)
1342        return temp
1343
1344class DataFrame(wx.Frame):
1345    """
1346    Data Frame
1347    """
1348    ## Internal name for the AUI manager
1349    window_name = "Data Panel"
1350    ## Title to appear on top of the window
1351    window_caption = "Data Panel"
1352    ## Flag to tell the GUI manager that this panel is not
1353    #  tied to any perspective
1354    ALWAYS_ON = True
1355
1356    def __init__(self, parent=None, owner=None, manager=None, size=(300, 800),
1357                         list_of_perspective=[], list=[], *args, **kwds):
1358        kwds['size'] = size
1359        kwds['id'] = -1
1360        kwds['title'] = "Loaded Data"
1361        wx.Frame.__init__(self, parent=parent, *args, **kwds)
1362        self.parent = parent
1363        self.owner = owner
1364        self._manager = manager
1365        self.panel = DataPanel(parent=self,
1366                               manager=manager,
1367                               list_of_perspective=list_of_perspective)
1368
1369    def load_data_list(self, list=[]):
1370        """
1371        Fill the list inside its panel
1372        """
1373        self.panel.load_data_list(list=list)
1374
1375
1376from sas.sasgui.guiframe.dataFitting import Theory1D
1377from sas.sasgui.guiframe.data_state import DataState
1378
1379
1380class State():
1381    """
1382    DataPanel State
1383    """
1384    def __init__(self):
1385        self.msg = ""
1386    def __str__(self):
1387        self.msg = "model mane : model1\n"
1388        self.msg += "params : \n"
1389        self.msg += "name  value\n"
1390        return self.msg
1391
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.