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