Masked Controls that go to the next "field" automatically

Jorge Godoy wrote:

Hi,

I've defined a wx.lib.masked.TextCtrl to handle some input with a mask
of "#{3}:#{2}" (it is "HOURS:MINUTES", where I can have up to 999:59
as a valid value).

I've been playing with the formatcodes option and reading the
wx.lib.masked.maskededit documentation but I haven't found some mean
to change from Field[0] (the hours part) to Field[1] (the minutes
part) automatically when the user press "," or "." or even the ":"
defined in the mask.

Are there means to do that?

Hi Jorge,

Yes, there is mechanism for you to do this, but it will require a
class derivation from the BaseMaskedTextCtrl class. Take a look
at lib.masked.ipaddrctrl; it is a very thin wrapper around the
base class, that sets up a function called OnDot for handling typing
of '.' in IP addresses, to make data entry into the control natural.
There's a function called _AddNavKey() in the base class (actually the
mixin)
that allows you to bind other keystrokes as "navigation keys."
What exactly is done after this is not obvious from the masked edit
internal documentation, but the IpAddrCtrl's OnDot() is a reasonably
good example. The key part is that if you want to have the keystroke
result in advancing to the next field, the handler should call
self._OnChangeField(event)

(The IpAddrCtrl is actually also using the current cursor position
to discard everything to the right of it within the current field
when the . is typed, so that the resulting "filled" field only
contains whatever was typed before the . -- and then only if the
. is not shifted, as the IpAddrCtrl actually will treat shift-.
(>) as "move to the *preceding* field.)

There is a bunch o' documentation for those wishing to derive new
classes in the *2nd* doc string inside maskededit.py. It contains
some of the rationales behind some of the more complicated bits
around the derivation, such as how to hide the more "generic"
attributes of the base classes when building more specific ones,
and the details behind what derivations must do re: event handling.

Also, the numctrl, ipaddrctrl, and timectrl classes are all good
references on what can be done and how.

Good luck, and let me know if there are problems!
/Will Sadkin