Changeset 3901e7c in sasview for src/sas/sasgui/perspectives
- Timestamp:
- Jul 11, 2016 4:36:55 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.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- e02d8f6
- Parents:
- 2196f102
- git-author:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/04/16 11:35:57)
- git-committer:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/16 04:36:55)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r3ec4b8f r3901e7c 2 2 import sys 3 3 from wx.lib.scrolledpanel import ScrolledPanel 4 from sas.sasgui.guiframe.events import PlotQrangeEvent 5 from sas.sasgui.guiframe.events import StatusEvent 4 6 from sas.sasgui.guiframe.panel_base import PanelBase 7 from sas.sasgui.guiframe.utils import check_float 5 8 from sas.sasgui.perspectives.invariant.invariant_widgets import OutputTextCtrl 6 9 from sas.sasgui.perspectives.invariant.invariant_widgets import InvTextCtrl 10 from sas.sasgui.perspectives.fitting.basepage import ModelTextCtrl 7 11 8 12 if sys.platform.count("win32") > 0: … … 32 36 self._data = data # The data to be analysed 33 37 self._data_name_box = None # Text box to show name of file 38 self._qmin_input = None 39 self._qmax1_input = None 40 self._qmax2_input = None 41 self._qmin = 0 42 self._qmax = (0, 0) 34 43 # Dictionary for saving IDs of text boxes used to display output data 35 44 self._output_ids = None … … 37 46 self.set_state() 38 47 self._do_layout() 48 self._qmin_input.Bind(wx.EVT_TEXT, self._on_enter_qrange) 49 self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_qrange) 50 self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_qrange) 39 51 40 52 def set_state(self, state=None, data=None): … … 42 54 return False 43 55 56 def onSetFocus(self, evt): 57 if evt is not None: 58 evt.Skip() 59 self._validate_qrange() 60 44 61 def _set_data(self, data=None): 45 62 """ … … 49 66 """ 50 67 self._data_name_box.SetValue(str(data.name)) 68 self._data = data 51 69 if self._manager is not None: 52 70 self._manager.show_data(data=data, reset=True) 53 # TODO: Set values of lower and upper q appropriately when data is 54 # loaded in 55 71 lower = data.x[-1]*0.05 72 upper1 = data.x[-1] - lower*5 73 upper2 = data.x[-1] 74 self.set_qmin(lower) 75 self.set_qmax((upper1, upper2)) 76 77 78 def _on_enter_qrange(self, event): 79 """ 80 Read values from input boxes and save to memory. 81 """ 82 event.Skip() 83 if not self._validate_qrange(): 84 return 85 new_qmin = float(self._qmin_input.GetValue()) 86 new_qmax1 = float(self._qmax1_input.GetValue()) 87 new_qmax2 = float(self._qmax2_input.GetValue()) 88 self.qmin = new_qmin 89 self.qmax = (new_qmax1, new_qmax2) 90 data_id = self._manager.data_id 91 from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA 92 group_id = GROUP_ID_IQ_DATA 93 wx.PostEvent(self._manager.parent, PlotQrangeEvent( 94 ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], 95 active=event.GetEventObject(), id=data_id, group_id=group_id, 96 leftdown=False)) 97 98 def set_qmin(self, qmin): 99 self.qmin = qmin 100 self._qmin_input.SetValue(str(qmin)) 101 102 def set_qmax(self, qmax): 103 self.qmax = qmax 104 self._qmax1_input.SetValue(str(qmax[0])) 105 self._qmax2_input.SetValue(str(qmax[1])) 106 107 def _validate_qrange(self): 108 """ 109 Check that the values for qmin and qmax in the input boxes are valid 110 """ 111 if self._data is None: 112 return False 113 qmin_valid = check_float(self._qmin_input) 114 qmax1_valid = check_float(self._qmax1_input) 115 qmax2_valid = check_float(self._qmax2_input) 116 qmax_valid = qmax1_valid and qmax2_valid 117 if not (qmin_valid and qmax_valid): 118 if not qmin_valid: 119 self._qmin_input.SetBackgroundColour('pink') 120 self._qmin_input.Refresh() 121 if not qmax1_valid: 122 self._qmax1_input.SetBackgroundColour('pink') 123 self._qmax1_input.Refresh() 124 if not qmax2_valid: 125 self._qmax2_input.SetBackgroundColour('pink') 126 self._qmax2_input.Refresh() 127 return False 128 qmin = float(self._qmin_input.GetValue()) 129 qmax1 = float(self._qmax1_input.GetValue()) 130 qmax2 = float(self._qmax2_input.GetValue()) 131 msg = "" 132 if not qmin > self._data.x.min(): 133 msg = "qmin must be greater than the lowest q value" 134 qmin_valid = False 135 elif qmax2 < qmax1: 136 "qmax1 must be less than qmax2" 137 qmax_valid = False 138 elif qmin > qmax1: 139 "qmin must be less than qmax" 140 qmin_valid = False 141 # import pdb; pdb.set_trace() 142 if not (qmin_valid and qmax_valid): 143 if not qmin_valid: 144 self._qmin_input.SetBackgroundColour('pink') 145 if not qmax_valid: 146 self._qmax1_input.SetBackgroundColour('pink') 147 self._qmax2_input.SetBackgroundColour('pink') 148 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 149 else: 150 self._qmin_input.SetBackgroundColour(wx.WHITE) 151 self._qmax1_input.SetBackgroundColour(wx.WHITE) 152 self._qmax2_input.SetBackgroundColour(wx.WHITE) 153 self._qmin_input.Refresh() 154 self._qmax1_input.Refresh() 155 self._qmax2_input.Refresh() 156 return (qmin_valid and qmax_valid) 56 157 57 158 def _do_layout(self): … … 108 209 109 210 qmin_lower = OutputTextCtrl(self, -1, size=(50, 20), value="0.0") 110 qmin_input = InvTextCtrl(self, -1, size=(50, 20), 111 style=wx.TE_PROCESS_ENTER, name='qmin_input') 112 qmin_input.SetToolTipString(("Values with q < qmin will be used for " 113 "Guinier back extrapolation")) 211 self._qmin_input = ModelTextCtrl(self, -1, size=(50, 20), 212 style=wx.TE_PROCESS_ENTER, name='qmin_input', 213 text_enter_callback=self._on_enter_qrange) 214 self._qmin_input.SetToolTipString(("Values with q < qmin will be used " 215 "for Guinier back extrapolation")) 114 216 115 217 q_sizer.Add(qmin_label, (2, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 116 218 q_sizer.Add(qmin_lower, (2, 1), (1, 1), wx.LEFT, 5) 117 219 q_sizer.Add(qmin_dash_label, (2, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) 118 q_sizer.Add( qmin_input, (2, 3), (1, 1), wx.LEFT, 5)220 q_sizer.Add(self._qmin_input, (2, 3), (1, 1), wx.LEFT, 5) 119 221 120 222 # Upper Q range … … 126 228 style=wx.ALIGN_CENTER_HORIZONTAL) 127 229 128 qmax1_input = InvTextCtrl(self, -1, size=(50, 20), 129 style=wx.TE_PROCESS_ENTER, name="qmax1_input") 130 qmax1_input.SetToolTipString(qmax_tooltip) 131 qmax2_input = InvTextCtrl(self, -1, size=(50, 20), 132 style=wx.TE_PROCESS_ENTER, name="qmax2_input") 133 qmax2_input.SetToolTipString(qmax_tooltip) 230 self._qmax1_input = ModelTextCtrl(self, -1, size=(50, 20), 231 style=wx.TE_PROCESS_ENTER, name="qmax1_input", 232 text_enter_callback=self._on_enter_qrange) 233 self._qmax1_input.SetToolTipString(qmax_tooltip) 234 self._qmax2_input = ModelTextCtrl(self, -1, size=(50, 20), 235 style=wx.TE_PROCESS_ENTER, name="qmax2_input", 236 text_enter_callback=self._on_enter_qrange) 237 self._qmax2_input.SetToolTipString(qmax_tooltip) 134 238 135 239 q_sizer.Add(qmax_label, (3, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 136 q_sizer.Add( qmax1_input, (3, 1), (1, 1), wx.LEFT, 5)240 q_sizer.Add(self._qmax1_input, (3, 1), (1, 1), wx.LEFT, 5) 137 241 q_sizer.Add(qmax_dash_label, (3, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) 138 q_sizer.Add( qmax2_input, (3,3), (1, 1), wx.LEFT, 5)242 q_sizer.Add(self._qmax2_input, (3,3), (1, 1), wx.LEFT, 5) 139 243 140 244 qbox_sizer.Add(q_sizer, wx.TOP, 0)
Note: See TracChangeset
for help on using the changeset viewer.