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