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