I have a wx.Panel class with a number of data entry fields that have a tab order assigned at the end of the init method:
# set tab order self.taborder = (self.idField, self.dateField, self.runFromField, self.runToField,self.recoveredField, self.lithologyField, self.alterationField, self.strengthField, self.fracturesField, self.jcrField, self.solidField, self.rubbleField, self.gougeField, self.rqdField, self.runCommentField, self.featuregrid) **for** i **in** xrange(len(self.taborder)-1): self.taborder[i+1].MoveAfterInTabOrder(self.taborder[i])
That portion works as advertised.
However, two of the fields are dependent on the values of one or two others – if the value equals some given number, then the other fields are zero’d out and the cursor jumps to the “rqd” field:
**def** ZeroFaultFields(self, event): """Zeros out the rubble and gouge fields if the solid field equals the total recovery""" recovered = float(self.recoveredField.GetValue()) solid = float(self.solidField.GetValue()) rubble = float(self.rubbleField.GetValue()) gouge = float(self.gougeField.GetValue()) **if** solid == recovered: self.rubbleField.SetValue("0.0") self.gougeField.SetValue("0.0") self.rqdField.SetFocus() self.rqdField.SelectAll() self.taborder[13].MoveAfterInTabOrder(self.taborder[10]) **elif** solid + rubble == recovered: self.gougeField.SetValue("0.0") self.rqdField.SetFocus() self.rqdField.SetSelection(0,3) **elif** solid and rubble: gouge = recovered - (solid + rubble) **if** gouge > 0: self.gougeField.SetValue(str(gouge))
As you can see, I’ve tried several commands to have the contents of the rqd field (initialized to ‘0.0’) be selected:
self.rqdField.SetFocus()
self.rqdField.SelectAll()
self.rqdField.SetSelection(0,3)
self.taborder[13].MoveAfterInTabOrder(self.taborder[10])
I also tried self.rqdField.SetSelection(-1,-1)
I’ve tried them individually and in combination, as shown above. None of them have any effect. The cursor will jump to the proper field, but the selection remains with the next field in the initial tab order, until the user manually selects the rqd field. This leads to data entry errors, since the “0.0” string ends up in front of any number entered unless the user is paying more attention to the screen than her keypad. And it’s disconcerting to see the selection and the cursor in different fields.
How do I set the selection to the chosen field?