Hello all
I'm new to wxPython programming and my native language is not english, so please forgive me if this is a silly question.
I'm trying to make my controls data-aware using the wxPyValidator class.
I have successfully set up a dialog with a wxMaskedTextCtrl field and a validator that fills in the data from a instance variable. My control (named ctrl_username) is initialized as follows (in the dialog's __init__ method):
self.username='test'
self.ctrl_username = wxFindWindowByName('ctrl_username',self) # field name in wxDesigner
self.ctrl_username.SetFormatcodes('F>')
self.ctrl_username.SetMask('X{30}')
self.ctrl_username.SetValidRegex('^\w\S{1,12}')
self.ctrl_validator=TxtValidator(obj=self, attrName='username') # will become the 'database record/field object' when everything else works...
self.ctrl_username.SetValidator(self.ctrl_validator)
Here is my TransferTo/FromWindow method for the validator:
def TransferToWindow(self):
if self.obj and self.attrName: # stored at __init__ time from parameters
hwnd=self.GetWindow()
val = getattr(self.obj, self.attrName)
dbg("hwnd.__class__=%s" % hwnd.__class__, "val='%s'" % val)
hwnd.SetValue(val)
return True
def TransferFromWindow(self):
if self.obj and self.attrName:
hwnd=self.GetWindow()
text = hwnd.GetValue()
setattr(self.obj, self.attrName, string.atof(text))
return True
the dbg code correctly puts out wxMaskedTextCtrl as class name and the proper value.
Now here is my problem:
The value is correcty transferred to the control, however, the cursor is positioned at the right end, as if the value was filled with spaces. But this is not the case.
What's the correct way to put the insert cursor at the end of the string?
Also, I have a problem with the TransferFromWindow not being called at all. A small example, e.g. in the wxPyWiki, would help me a lot. I already learned most wxWindows tricks from the demos, but for these data transfer tricks I did not find one.
Thanks for any help.
Regards
--Marcel