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