Changeset 3f75203 in sasview
- Timestamp:
- Apr 10, 2017 7:43:20 AM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 37d461c
- Parents:
- 82ce1d0
- git-author:
- Jeff Krzywon <krzywon@…> (04/10/17 07:43:20)
- git-committer:
- krzywon <krzywon@…> (04/10/17 07:43:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py
r82ce1d0 r3f75203 1 1 2 2 3 import os 3 4 import wx 4 5 import wx.lib.newevent … … 7 8 from sas.sasgui.guiframe.utils import format_number 8 9 from sas.sasgui.guiframe.events import EVT_SLICER 9 from sas.sasgui.guiframe.events import SlicerParameterEvent , SlicerEvent10 from sas.sasgui.guiframe.events import SlicerParameterEvent 10 11 from Plotter2D import ModelPanel2D 11 12 apply_params, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 12 auto_save, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent()13 save_files, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent() 13 14 14 15 FIT_OPTIONS = ["No fitting", "Fitting", "Batch Fitting"] … … 18 19 "BoxInteractorY": "SlabY"} 19 20 21 20 22 class SlicerParameterPanel(wx.Dialog): 21 23 """ 22 Panel class to show the slicer parameters 24 Panel for dynamically changing slicer parameters and apply the same slicer 25 to multiple 2D plot panels 23 26 """ 24 # TODO: show units25 # TODO: order parameters properly26 27 27 28 def __init__(self, parent, *args, **kwargs): … … 34 35 self.iter = 0 35 36 self.parent = parent 37 self.main_window = parent.parent 38 self.data_panel = self.main_window._data_panel 36 39 self.type = None 37 40 self.listeners = [] … … 43 46 self.fitting_options = None 44 47 self.type_list = [] 48 self.loaded_data = [] 49 self.always_on = None 45 50 self.type_select = None 46 51 self.append_name = None 47 52 self.data_list = None 53 self.default_value = "" 54 self.batch_slicer_button = None 48 55 label = "Right-click on 2D plot for slicer options" 49 56 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) … … 51 58 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 52 59 # Bindings 53 self.parent.Bind(EVT_SLICER, self.on EVT_SLICER)54 self.Bind(EVT_SLICER_PARS, self.on ParamChange)60 self.parent.Bind(EVT_SLICER, self.on_evt_slicer) 61 self.Bind(EVT_SLICER_PARS, self.on_param_change) 55 62 self.Bind(EVT_APPLY_PARAMS, self.apply_params_list_and_process) 56 63 self.Bind(EVT_AUTO_SAVE, self.save_files) 57 64 58 def on EVT_SLICER(self, event):65 def on_evt_slicer(self, event): 59 66 """ 60 67 Process EVT_SLICER events … … 94 101 iy += 1 95 102 ix = 0 96 if not itemin ["count", "errors"]:103 if item not in ["count", "errors"]: 97 104 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 98 105 self.bck.Add(text, (iy, ix), (1, 1), … … 105 112 ix = 1 106 113 ctl.SetValue(format_number(str(params[item]))) 107 self.Bind(wx.EVT_TEXT_ENTER, self.on TextEnter)114 self.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter) 108 115 self.parameters.append([item, ctl]) 109 116 self.bck.Add(ctl, (iy, ix), (1, 1), … … 131 138 self.bck.Add(text, (iy, ix), (1, 1), 132 139 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 133 self.type_list = ["SectorInteractor", "AnnulusInteractor", 134 "BoxInteractorX", "BoxInteractorY"] 140 self.type_list = CONVERT_DICT.keys() 135 141 self.type_select = wx.ComboBox(parent=self, choices=self.type_list) 136 self.type_select.Bind(wx.EVT_COMBOBOX, self.on ChangeSlicer)142 self.type_select.Bind(wx.EVT_COMBOBOX, self.on_change_slicer) 137 143 index = self.type_select.FindString(type) 138 144 self.type_select.SetSelection(index) … … 158 164 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 159 165 160 # Checkbox for autosaving data166 # Checkbox to enable saving and fitting options 161 167 iy += 1 162 168 self.auto_save = wx.CheckBox(parent=self, id=wx.NewId(), … … 169 175 save_to = "Save files to:" 170 176 save = wx.StaticText(self, -1, save_to, style=wx.ALIGN_LEFT) 171 self.path = wx.DirPickerCtrl(self, id=wx.NewId(), path="", 177 path = os.getcwd() 178 self.path = wx.DirPickerCtrl(self, id=wx.NewId(), path=path, 172 179 message=save_to) 173 180 self.path.Enable(False) … … 178 185 # Append to file 179 186 iy += 1 180 default_value = "" 181 for key in params: 182 default_value += "_{0}".format(key).split(" [")[0] 183 default_value += "-{:.5f}".format(params[key]) 187 self.update_file_append(params) 184 188 append_text = "Append to file name:" 185 189 append = wx.StaticText(self, -1, append_text, style=wx.ALIGN_LEFT) 186 190 self.append_name = wx.TextCtrl(parent=self, id=wx.NewId(), 187 191 name="Append to file name:") 188 self.append_name.SetValue(default_value) 192 append_tool_tip = "Files will be saved as <SlicerType><FileName>" 193 append_tool_tip += "<AppendToText>.xml" 194 self.append_name.SetToolTipString(append_tool_tip) 195 self.append_name.SetValue(self.default_value) 189 196 self.append_name.Enable(False) 190 197 self.bck.Add(append, (iy, ix), (1, 1), … … 196 203 iy += 1 197 204 fit_text = "Fitting Options:" 198 fit_text_item = wx.StaticText(self, -1, fit_text, style=wx.ALIGN_LEFT) 205 fit_text_item = wx.StaticText(self, -1, fit_text, 206 style=wx.ALIGN_LEFT) 199 207 self.bck.Add(fit_text_item, (iy, ix), (1, 1), 200 208 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) … … 221 229 self.parent.GetSizer().Layout() 222 230 223 def on ParamChange(self, evt):231 def on_param_change(self, evt): 224 232 """ 225 233 receive an event end reset value text fields … … 233 241 item[1].Refresh() 234 242 235 def on TextEnter(self, evt):243 def on_text_enter(self, evt): 236 244 """ 237 245 Parameters have changed … … 253 261 # Post parameter event 254 262 # parent here is plotter2D 263 self.update_file_append(params) 264 self.append_name.SetValue(self.default_value) 265 self.append_name.Refresh() 255 266 event = SlicerParameterEvent(type=self.type, params=params) 256 267 wx.PostEvent(self.parent, event) … … 258 269 def on_batch_slicer(self, evt=None): 259 270 """ 260 Method invoked when batch slicing button is pressed261 :param evt: Event triggering hide/show of the batch slicer parameters271 Event triggered when batch slicing button is pressed 272 :param evt: Event triggering the batch slicing 262 273 """ 263 274 apply_to_list = [] 264 275 spp = self.parent.parent 265 276 params = self.parent.slicer.get_params() 266 type = self.type_select.GetStringSelection()277 slicer_type = self.type_select.GetStringSelection() 267 278 save = self.auto_save.IsChecked() 268 279 append = self.append_name.GetValue() … … 277 288 # Apply slicer type to selected panels 278 289 for item in apply_to_list: 279 self._apply_slicer_to_plot(item, type)290 self._apply_slicer_to_plot(item, slicer_type) 280 291 281 292 # Post an event to apply appropriate slicer params to each slicer 293 # Pass all variables, including class variables 282 294 event_params = apply_params(params=params, apply_to_list=apply_to_list, 283 auto_save=save, append=append, fit=fit,284 path=path, type=type)295 auto_save=save, append=append, fit=fit, 296 path=path, type=slicer_type) 285 297 wx.PostEvent(self, event_params) 286 298 287 def on ChangeSlicer(self, evt):299 def on_change_slicer(self, evt): 288 300 """ 289 301 Event driven slicer change when self.type_select changes … … 292 304 self._apply_slicer_to_plot(self.parent) 293 305 294 def _apply_slicer_to_plot(self, plot, type=None):306 def _apply_slicer_to_plot(self, plot, slicer_type=None): 295 307 """ 296 308 Apply a slicer to *any* plot window, not just parent window 297 309 :param plot: 2D plot panel to apply a slicer to 298 :param type: The type of slicer to apply to the panel299 """ 300 # Skip redrawing the current plot if no change 301 if self.parent == plot and self.type == type:310 :param slicer_type: The type of slicer to apply to the panel 311 """ 312 # Skip redrawing the current plot if no change in slicer type 313 if self.parent == plot and self.type == slicer_type: 302 314 return 303 315 # Do not draw a slicer on a 1D plot 304 316 if not isinstance(plot, ModelPanel2D): 305 317 return 306 if type is None:307 type = self.type_select.GetStringSelection()308 if type == "SectorInteractor":318 if slicer_type is None: 319 slicer_type = self.type_select.GetStringSelection() 320 if slicer_type == self.type_list[0]: 309 321 plot.onSectorQ(None) 310 elif type == "AnnulusInteractor":322 elif slicer_type == self.type_list[1]: 311 323 plot.onSectorPhi(None) 312 elif type == "BoxInteractorX":324 elif slicer_type == self.type_list[2]: 313 325 plot.onBoxavgX(None) 314 elif type == "BoxInteractorY":326 elif slicer_type == self.type_list[3]: 315 327 plot.onBoxavgY(None) 316 328 … … 319 331 Populate the check list from the currently plotted 2D data 320 332 """ 321 self.checkme = None322 main_window = self.parent.parent323 self.loaded_data = []324 id = wx.NewId()325 333 # Iterate over the loaded plots and find all 2D panels 326 for key, value in main_window.plot_panels.iteritems():334 for key, value in self.main_window.plot_panels.iteritems(): 327 335 if isinstance(value, ModelPanel2D): 328 336 self.loaded_data.append(value.data2D.name) 329 337 if value.data2D.id == self.parent.data2D.id: 330 338 # Set current plot panel as uncheckable 331 self. checkme= self.loaded_data.index(value.data2D.name)332 self.data_list = wx.CheckListBox(parent=self, id= id,339 self.always_on = self.loaded_data.index(value.data2D.name) 340 self.data_list = wx.CheckListBox(parent=self, id=wx.NewId(), 333 341 choices=self.loaded_data, 334 342 name="Apply Slicer to 2D Plots:") … … 341 349 """ 342 350 Prevent a checkbox item from being unchecked 343 :param e : Event triggered when a checkbox list item is checked351 :param evt: Event triggered when a checkbox list item is checked 344 352 """ 345 353 if evt is None: 346 354 return 347 355 index = evt.GetSelection() 348 if index == self. checkme:356 if index == self.always_on: 349 357 self.data_list.Check(index) 350 358 … … 355 363 evt should have attrs plot_list and params 356 364 """ 365 if evt is None: 366 return 357 367 # Apply parameter list to each plot as desired 358 368 for item in evt.apply_to_list: … … 361 371 # Post an event to save each data set to file 362 372 if evt.auto_save: 363 event = auto_save(append_to_name=evt.append, path=evt.path,364 type=evt.type, file_list=evt.apply_to_list,365 fit=evt.fit)373 event = save_files(append_to_name=evt.append, path=evt.path, 374 type=evt.type, file_list=evt.apply_to_list, 375 fit=evt.fit) 366 376 wx.PostEvent(self, event) 367 377 … … 372 382 """ 373 383 374 # Send the event to the end of the wx event queue 384 # Events triggered after this event pass other events to wx that are 385 # necessary before this event is called. If this is the first time 386 # reaching this event, send it to the end of the wx event queue 375 387 if self.iter == 0: 376 388 clone = evt.Clone() … … 383 395 # Start definitions 384 396 writer = Reader() 385 main_window = self.parent.parent386 397 data_dic = {} 387 398 append = evt.append_to_name … … 395 406 396 407 # Find the correct plots to save 397 for key, plot in main_window.plot_panels.iteritems():408 for key, plot in self.main_window.plot_panels.iteritems(): 398 409 if not hasattr(plot, "data2D"): 399 410 for item in plot.plots: … … 404 415 # Save files as XML 405 416 for item, data1d in data_dic.iteritems(): 406 base = ('.').join(item.split('.')[:-1])417 base = '.'.join(item.split('.')[:-1]) 407 418 file_name = base + append + ".xml" 408 419 save_to = evt.path + "\\" + file_name … … 413 424 # Load files into GUI 414 425 for item in f_path_list: 415 main_window.load_data(item)426 self.main_window.load_data(item) 416 427 417 428 # Send to fitting … … 425 436 """ 426 437 if fit != FIT_OPTIONS[0] and file_list is not None: 427 # Method variable definitions428 main_window = self.parent.parent429 datapanel = main_window._data_panel430 438 # Set perspective to fitting 431 int = datapanel.perspective_cbox.FindString("Fitting")432 datapanel.perspective_cbox.SetSelection(int)433 datapanel._on_perspective_selection(None)439 int = self.data_panel.perspective_cbox.FindString("Fitting") 440 self.data_panel.perspective_cbox.SetSelection(int) 441 self.data_panel._on_perspective_selection(None) 434 442 # Unselect all loaded data 435 datapanel.selection_cbox.SetValue('Unselect all Data')436 datapanel._on_selection_type(None)443 self.data_panel.selection_cbox.SetValue('Unselect all Data') 444 self.data_panel._on_selection_type(None) 437 445 # Click each sliced data file 438 446 for f_name in file_list: 439 447 num = len(f_name) 440 data_list = datapanel.list_cb_data448 data_list = self.data_panel.list_cb_data 441 449 for key in data_list: 442 450 loaded_key = (key[:num]) if len(key) > num else key … … 446 454 self.check_item_and_children(data_ctrl=data_ctrl, 447 455 check_value=True) 448 # TODO: Batch fitting449 456 # Switch to batch mode if selected 450 457 if fit == FIT_OPTIONS[2]: 451 datapanel.rb_single_mode.SetValue(False)452 datapanel.rb_batch_mode.SetValue(True)453 datapanel.on_batch_mode(None)458 self.data_panel.rb_single_mode.SetValue(False) 459 self.data_panel.rb_batch_mode.SetValue(True) 460 self.data_panel.on_batch_mode(None) 454 461 else: 455 datapanel.rb_single_mode.SetValue(True)456 datapanel.rb_batch_mode.SetValue(False)457 datapanel.on_single_mode(None)462 self.data_panel.rb_single_mode.SetValue(True) 463 self.data_panel.rb_batch_mode.SetValue(False) 464 self.data_panel.on_single_mode(None) 458 465 459 466 # Post button click event to send data to fitting 460 467 evt = wx.PyCommandEvent(wx.EVT_BUTTON.typeId, 461 datapanel.bt_import.GetId())462 wx.PostEvent( datapanel, evt)468 self.data_panel.bt_import.GetId()) 469 wx.PostEvent(self.data_panel, evt) 463 470 464 471 def on_auto_save_checked(self, evt=None): … … 472 479 473 480 def check_item_and_children(self, data_ctrl, check_value=True): 474 self.parent.parent._data_panel.tree_ctrl.CheckItem(data_ctrl, 475 check_value) 481 self.data_panel.tree_ctrl.CheckItem(data_ctrl, check_value) 476 482 if data_ctrl.HasChildren(): 477 483 if check_value and not data_ctrl.IsExpanded(): 478 # Only select children if control is expanded479 # Always deselect children, regardless (see ticket #259)480 484 return 481 485 for child_ctrl in data_ctrl.GetChildren(): 482 self.tree_ctrl.CheckItem(child_ctrl, check_value) 486 self.data_panel.CheckItem(child_ctrl, check_value) 487 488 def update_file_append(self, params=None): 489 """ 490 Update default_value when any parameters are changed 491 :param params: dictionary of parameters 492 """ 493 self.default_value = "" 494 if params is None: 495 params = self.params 496 for key in params: 497 self.default_value += "_{0}".format(key).split(" [")[0] 498 self.default_value += "-{:.2f}".format(params[key])
Note: See TracChangeset
for help on using the changeset viewer.