Changeset 5198 for trunk/GSASIIctrlGUI.py
- Timestamp:
- Mar 3, 2022 9:09:34 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIctrlGUI.py ¶
r5197 r5198 33 33 choice is selected 34 34 :class:`G2SliderWidget` A customized combination of a wx.Slider and a validated 35 wx.TextCtrl (see :class:`ValidatedTxtCtrl`). 36 :class:`G2SpinWidget` A customized combination of a wx.SpinButton and a validated 35 37 wx.TextCtrl (see :class:`ValidatedTxtCtrl`). 36 38 :class:`G2ColumnIDDialog` A dialog for matching column data to desired items; some … … 1117 1119 xmin=xmin,xmax=xmax,typeHint=float) 1118 1120 hSizer.Add(vEntry,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL,5) 1121 return hSizer 1122 1123 def G2SpinWidget(parent,loc,key,label,xmin=None,xmax=None, 1124 onChange=None,onChangeArgs=[],hsize=35): 1125 '''A customized combination of a wx.SpinButton and a validated 1126 wx.TextCtrl (see :class:`ValidatedTxtCtrl`) that allows either 1127 a the spin button or text entry to set a value within a range. 1128 1129 :param wx.Panel parent: name of panel or frame that will be 1130 the parent to the TextCtrl. Can be None. 1131 1132 :param dict/list loc: the dict or list with the initial value to be 1133 placed in the TextCtrl. 1134 1135 :param int/str key: the dict key or the list index for the value to be 1136 edited by the TextCtrl. The ``loc[key]`` element must exist and should 1137 have a float or int value. It will be forced to an integer initial value 1138 between xmin and xmax. 1139 1140 :param str label: A label to be placed to the left of the entry widget. 1141 1142 :param int xmin: the minimum allowed valid value. If None it is ignored. 1143 1144 :param int xmax: the maximum allowed valid value. If None it is ignored. 1145 1146 :param callable onChange: function to call when value is changed. 1147 Default is None where nothing will be called. 1148 1149 :param list onChangeArgs: arguments to be passed to onChange function 1150 when called. 1151 1152 :param int hsize: length of TextCtrl in pixels. Defaults to 35. 1153 1154 :returns: returns a wx.BoxSizer containing the widgets 1155 ''' 1156 1157 def _onSpin(event): 1158 Obj = event.GetEventObject() 1159 loc[key] += Obj.GetValue() # +1 or -1 1160 if xmin is not None and loc[key] < xmin: 1161 loc[key] = xmin 1162 if xmax is not None and loc[key] > xmax: 1163 loc[key] = xmax 1164 wx.TextCtrl.SetValue(vEntry,str(loc[key])) # will not trigger onValSet 1165 Obj.SetValue(0) 1166 if onChange: onChange(*onChangeArgs) 1167 def _onValSet(*args,**kwargs): 1168 if onChange: onChange(*onChangeArgs) 1169 if xmin is not None: 1170 loc[key] = max(xmin,loc[key]) 1171 if xmax is not None: 1172 loc[key] = min(xmax,loc[key]) 1173 hSizer = wx.BoxSizer(wx.HORIZONTAL) 1174 if label: 1175 hSizer.Add(wx.StaticText(parent,wx.ID_ANY,label),0, 1176 wx.ALL|wx.ALIGN_CENTER_VERTICAL) 1177 spin = wx.SpinButton(parent,style=wx.SP_VERTICAL,size=wx.Size(20,20)) 1178 spin.SetRange(-1,1) 1179 spin.Bind(wx.EVT_SPIN, _onSpin) 1180 loc[key] = int(loc[key]+0.5) 1181 vEntry = ValidatedTxtCtrl(parent,loc,key,OnLeave=_onValSet, 1182 xmin=xmin,xmax=xmax,typeHint=int,size=(hsize,-1)) 1183 hSizer.Add(vEntry,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL,5) 1184 hSizer.Add(spin,0,wx.ALL|wx.ALIGN_CENTER_VERTICAL) 1119 1185 return hSizer 1120 1186
Note: See TracChangeset
for help on using the changeset viewer.