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