Changeset 1177
- Timestamp:
- Dec 19, 2013 1:34:54 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r1172 r1177 175 175 type of int, float, str or unicode; the TextCrtl will be initialized 176 176 from this value. 177 178 :param list [nDig,nPlc]: number of digits & places after decimal to use 179 for display of float (default=[10,2]) 177 180 178 181 :param bool notBlank: if True (default) blank values are invalid … … 223 226 224 227 ''' 225 def __init__(self,parent,loc,key,n otBlank=True,min=None,max=None,228 def __init__(self,parent,loc,key,nDig=[10,2],notBlank=True,min=None,max=None, 226 229 OKcontrol=None,OnLeave=None,typeHint=None, 227 230 CIFinput=False, **kw): … … 229 232 self.result = loc 230 233 self.key = key 234 self.nDig = nDig 231 235 self.OKcontrol=OKcontrol 232 236 self.OnLeave = OnLeave … … 314 318 else: 315 319 self.invalid = True 316 wx.TextCtrl.SetValue(self,str(G2py3.FormatValue(val )))320 wx.TextCtrl.SetValue(self,str(G2py3.FormatValue(val,self.nDig))) 317 321 else: 318 322 wx.TextCtrl.SetValue(self,str(val)) -
trunk/GSASIIpwdGUI.py
r1175 r1177 1317 1317 1318 1318 parms = [] 1319 parms.append(['Scale','Histogram scale factor: ' ])1320 parms.append(['Gonio. radius','Goniometer radius (mm): ' ])1319 parms.append(['Scale','Histogram scale factor: ',[10,4]]) 1320 parms.append(['Gonio. radius','Goniometer radius (mm): ',[10,3]]) 1321 1321 if data['Type'] == 'Debye-Scherrer': 1322 parms += [['DisplaceX',u'Sample X displ. perp. to beam (\xb5m): ' ],1323 ['DisplaceY',u'Sample Y displ. || to beam (\xb5m): ' ],1324 ['Absorption',u'Sample absorption (\xb5\xb7r): ' ],]1322 parms += [['DisplaceX',u'Sample X displ. perp. to beam (\xb5m): ',[10,3]], 1323 ['DisplaceY',u'Sample Y displ. || to beam (\xb5m): ',[10,3]], 1324 ['Absorption',u'Sample absorption (\xb5\xb7r): ',[10,4]],] 1325 1325 elif data['Type'] == 'Bragg-Brentano': 1326 parms += [['Shift',u'Sample displacement(\xb5m): ' ],1327 ['Transparency',u'Sample transparency(1/\xb5eff, cm): ' ],1328 ['SurfRoughA','Surface roughness A: ' ],1329 ['SurfRoughB','Surface roughness B: ' ],]1330 parms.append(['Omega','Goniometer omega:', ])1331 parms.append(['Chi','Goniometer chi:', ])1332 parms.append(['Phi','Goniometer phi:', ])1333 parms.append(['Temperature','Sample temperature (K): ', ])1334 parms.append(['Pressure','Sample pressure (MPa): ', ])1326 parms += [['Shift',u'Sample displacement(\xb5m): ',[10,4]], 1327 ['Transparency',u'Sample transparency(1/\xb5eff, cm): ',[10,3]], 1328 ['SurfRoughA','Surface roughness A: ',[10,4]], 1329 ['SurfRoughB','Surface roughness B: ',[10,4]]] 1330 parms.append(['Omega','Goniometer omega:',[10,3]]) 1331 parms.append(['Chi','Goniometer chi:',[10,3]]) 1332 parms.append(['Phi','Goniometer phi:',[10,3]]) 1333 parms.append(['Temperature','Sample temperature (K): ',[10,3]]) 1334 parms.append(['Pressure','Sample pressure (MPa): ',[10,3]]) 1335 1335 1336 1336 mainSizer = wx.BoxSizer(wx.VERTICAL) … … 1363 1363 1364 1364 parmSizer = wx.FlexGridSizer(10,2,5,0) 1365 for key,lbl in parms:1365 for key,lbl,nDig in parms: 1366 1366 if 'list' in str(type(data[key])): 1367 1367 parmRef = G2gd.G2CheckBox(G2frame.dataDisplay,' '+lbl,data[key],1) 1368 1368 parmSizer.Add(parmRef,0,wx.ALIGN_CENTER_VERTICAL|wx.EXPAND) 1369 parmVal = G2gd.ValidatedTxtCtrl(G2frame.dataDisplay,data[key],0, typeHint=float)1369 parmVal = G2gd.ValidatedTxtCtrl(G2frame.dataDisplay,data[key],0,nDig=nDig,typeHint=float) 1370 1370 else: 1371 1371 parmSizer.Add(wx.StaticText(G2frame.dataDisplay,label=' '+lbl), -
trunk/GSASIIpy3.py
r1077 r1177 39 39 return val 40 40 41 def FormatValue(val,maxdigits=10): 42 '''Format a float to fit in ``maxdigits`` spaces, showing as much 43 precision as possible, more or less. 41 def FormatValue(val,maxdigits=[10,2]): 42 '''Format a float to fit in ``maxdigits[0]`` spaces with maxdigits[1] after decimal. 44 43 45 44 :param float val: number to be formatted. 46 45 47 :param int maxdigits: the number of digitsto be used for display of the48 number (defaults to 10).46 :param list maxdigits: the number of digits & places after decimal to be used for display of the 47 number (defaults to [10,2]). 49 48 50 49 :returns: a string with <= maxdigits characters (I hope). … … 52 51 # does the standard str() conversion fit? 53 52 string = str(val) 54 if len(string) <= maxdigits : return string.strip()53 if len(string) <= maxdigits[0]: return string.strip() 55 54 # negative numbers, leave room for a sign 56 if val < 0: maxdigits -= 157 decimals = maxdigits - 255 if val < 0: maxdigits[0] -= 1 56 decimals = maxdigits[0] - maxdigits[1] 58 57 if abs(val) < 1e-99 or abs(val) > 1e99: 59 decimals = m axdigits - 660 fmt = "{" + (":{:d}.{:d}g".format(maxdigits ,decimals))+"}" # create format string58 decimals = min(maxdigits[0]-6,maxdigits[1]) 59 fmt = "{" + (":{:d}.{:d}g".format(maxdigits[0],decimals))+"}" # create format string 61 60 elif abs(val) < 1e-9 or abs(val) > 1e9: 62 decimals = m axdigits - 563 fmt = "{" + (":{:d}.{:d}g".format(maxdigits ,decimals))+"}"61 decimals = min(maxdigits[0]-5,maxdigits[1]) 62 fmt = "{" + (":{:d}.{:d}g".format(maxdigits[0],decimals))+"}" 64 63 elif abs(val) < 10**(4-decimals): # make sure at least 4 decimals show 65 decimals = m axdigits - 566 fmt = "{" + (":{:d}.{:d}g".format(maxdigits ,decimals))+"}"64 decimals = min(maxdigits[0]-5,maxdigits[1]) 65 fmt = "{" + (":{:d}.{:d}g".format(maxdigits[0],decimals))+"}" 67 66 elif abs(val) >= 10**decimals: # deal with large numbers in smaller spaces 68 decimals = m axdigits - 569 fmt = "{" + (":{:d}.{:d}g".format(maxdigits ,decimals))+"}"67 decimals = min(maxdigits[0]-5,maxdigits[1]) 68 fmt = "{" + (":{:d}.{:d}g".format(maxdigits[0],decimals))+"}" 70 69 elif abs(val) < 1: # use f format for small numbers 71 decimals = m axdigits - 272 fmt = "{" + (":{:d}.{:d}f".format(maxdigits ,decimals))+"}"70 decimals = min(maxdigits[0]-3,maxdigits[1]) 71 fmt = "{" + (":{:d}.{:d}f".format(maxdigits[0],decimals))+"}" 73 72 else: # in range where g formatting should do what I want 74 decimals = maxdigits - 1 75 fmt = "{" + (":{:d}.{:d}g".format(maxdigits,decimals))+"}" 73 decimals = maxdigits[0] - 1 74 fmt = "{" + (":{:d}.{:d}g".format(maxdigits[0],decimals))+"}" 75 print fmt,val 76 76 return fmt.format(val).strip()
Note: See TracChangeset
for help on using the changeset viewer.