source: sasview/sansguiframe/src/sans/guiframe/data_panel.py @ 0ea247e

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 0ea247e was 7fb69f26, checked in by Jae Cho <jhjcho@…>, 12 years ago

added max/min button in plotpanels

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