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