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