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