source: sasview/src/sas/guiframe/data_panel.py @ b699768

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b699768 was b699768, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Initial commit of the refactored SasCalc? module.

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