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