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