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