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