Changeset 1881
- Timestamp:
- Jun 5, 2015 5:28:49 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIctrls.py
r1866 r1881 313 313 self.evaluated = False # set to True when the validator recognizes an expression 314 314 val = loc[key] 315 if 'style' in kw: # add a "Process Enter" to style 316 kw['style'] += kw['style'] | wx.TE_PROCESS_ENTER 317 else: 318 kw['style'] = wx.TE_PROCESS_ENTER 315 319 if isinstance(val,int) or typeHint is int: 316 320 self.type = int … … 365 369 # When the mouse is moved away or the widget loses focus, 366 370 # display the last saved value, if an expression 367 #self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow)371 self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeaveWindow) 368 372 self.Bind(wx.EVT_TEXT_ENTER, self._onLoseFocus) 369 373 self.Bind(wx.EVT_KILL_FOCUS, self._onLoseFocus) … … 379 383 self._setValue(val) 380 384 381 def _setValue(self,val): 385 def _setValue(self,val,show=True): 386 '''Check the validity of an int or float value and convert to a str. 387 Possibly format it. If show is True, display the formatted value in 388 the Text widget. 389 ''' 382 390 self.invalid = False 383 391 if self.type is int: … … 392 400 else: 393 401 self.invalid = True 394 wx.TextCtrl.SetValue(self,str(val))402 if show: wx.TextCtrl.SetValue(self,str(val)) 395 403 elif self.type is float: 396 404 try: … … 401 409 else: 402 410 self.invalid = True 403 if self.nDig :411 if self.nDig and show: 404 412 wx.TextCtrl.SetValue(self,str(G2py3.FormatValue(val,self.nDig))) 405 el se:413 elif show: 406 414 wx.TextCtrl.SetValue(self,str(G2py3.FormatSigFigs(val)).rstrip('0')) 407 415 else: 408 wx.TextCtrl.SetValue(self,str(val))416 if show: wx.TextCtrl.SetValue(self,str(val)) 409 417 self.ShowStringValidity() # test if valid input 410 418 return … … 419 427 if key in [wx.WXK_BACK, wx.WXK_DELETE]: 420 428 if self.Validator: wx.CallAfter(self.Validator.TestValid,self) 421 if key == wx.WXK_RETURN :429 if key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: 422 430 self._onLoseFocus(None) 423 431 event.Skip() … … 483 491 log.LogVarChange(self.result,self.key) 484 492 493 def _onLeaveWindow(self,event): 494 '''If the mouse leaves the text box, save the result, if valid, 495 but (unlike _onLoseFocus) don't update the textbox contents. 496 ''' 497 if self.evaluated and not self.invalid: # deal with computed expressions 498 self.evaluated = False # expression has been recast as value, reset flag 499 if self.invalid: # don't update an invalid expression 500 if event: event.Skip() 501 return 502 self._setValue(self.result[self.key],show=False) # save value quietly 503 if self.OnLeave: self.OnLeave(invalid=self.invalid, 504 value=self.result[self.key], 505 tc=self, 506 **self.OnLeaveArgs) 507 if event: event.Skip() 508 485 509 def _onLoseFocus(self,event): 486 if self.evaluated: 487 self.EvaluateExpression() 510 '''Enter has been pressed or focus transferred to another control, 511 Evaluate and update the current control contents 512 ''' 513 if self.evaluated: # deal with computed expressions 514 if self.invalid: # don't substitute for an invalid expression 515 if event: event.Skip() 516 return 517 self.evaluated = False # expression has been recast as value, reset flag 518 self._setValue(self.result[self.key]) 488 519 elif self.result is not None: # show formatted result, as Bob wants 489 520 self._setValue(self.result[self.key]) … … 494 525 if event: event.Skip() 495 526 496 def EvaluateExpression(self):497 '''Show the computed value when an expression is entered to the TextCtrl498 Make sure that the number fits by truncating decimal places and switching499 to scientific notation, as needed.500 Called on loss of focus, enter, etc..501 '''502 if self.invalid: return # don't substitute for an invalid expression503 if not self.evaluated: return # true when an expression is evaluated504 if self.result is not None: # retrieve the stored result505 self._setValue(self.result[self.key])506 self.evaluated = False # expression has been recast as value, reset flag507 508 527 class NumberValidator(wx.PyValidator): 509 528 '''A validator to be used with a TextCtrl to prevent … … 676 695 key = event.GetKeyCode() 677 696 tc = self.GetWindow() 678 if key == wx.WXK_RETURN :697 if key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: 679 698 if tc.invalid: 680 699 self.CheckInput(True) 681 700 else: 682 701 self.CheckInput(False) 702 event.Skip() 683 703 return 684 704 if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: # control characters get processed … … 750 770 key = event.GetKeyCode() 751 771 tc = self.GetWindow() 752 if key == wx.WXK_RETURN :772 if key == wx.WXK_RETURN or key == wx.WXK_NUMPAD_ENTER: 753 773 self.TestValid(tc) 774 event.Skip() 754 775 return 755 776 if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: # control characters get processed -
trunk/GSASIIpwdGUI.py
r1880 r1881 1106 1106 return good 1107 1107 1108 def inst2data(inst,ref,data): 1108 def updateData(inst,ref): 1109 data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, 1110 G2frame.PatternId,'Instrument Parameters'))[0] 1109 1111 for item in data: 1110 1112 try: 1111 1113 data[item] = [data[item][0],inst[item],ref[item]] 1112 1114 except KeyError: 1113 pass #skip 'Polariz.' for N-data 1114 return data 1115 1116 def updateData(inst,ref): 1117 return inst2data(inst,ref,G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame, 1118 G2frame.PatternId,'Instrument Parameters'))[0]) 1115 try: 1116 data[item] = [data[item][0],inst[item]] 1117 except KeyError: 1118 pass #skip 'Polariz.' for N-data 1119 1119 1120 1120 def RefreshInstrumentGrid(event,doAnyway=False):
Note: See TracChangeset
for help on using the changeset viewer.