Werner F. Bruhin wrote:
Hi Marcel,
Marcel Gsteiger wrote:
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.
[...]
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?What you see here is that wxMaskedTextCtrl fills your control with
spaces (they are expected to be Fixed Width). I therefore use the
formatcode "S" to select all text when one moves to the control, but
this might not work for you.Looking through some older mail exchanges I had with Will Sadkin, I
think that the hints I got from him at the time might work for you
too.ip = len(self.GetValue().rstrip()*)*
wxCallAfter(self._SetInsertionPoint, ip)
wxCallAfter(self._SetSelection, ip, ip)
(Not a silly question at all!)
Werner is right; the SetValue() function for wxMaskedTextCtrl sets
the cursor to the end of the entire control when its called.
There was reason behind this decision; it was difficult to
determine exactly where to put the cursor for all masked controls.
Part of the reason for this is that SetValue is "smart", in that
the value set need not contain the mask chars themselves, so long
as the "significant" bits align properly. This is easiest to
explain by example. Suppose you have the following mask:
'(###) ###-#### x##'
And you call ctl.SetValue('201555123'). The resulting string would
be '(201) 555-123 x '
(This allows you to store your values without the visual sugar.)
But the above example results in a partially filled mask.
If you did the above trick that Werner describes, the cursor
would end up after the x, but what you really want is to place
the cursor after the last character placed into the input field,
ie after the 3.
Based on this and my previous conversation with Werner, I'm
contemplating a change to the controls to keep track of the final
position of the last character pasted into the control as part of
the "set", and then using that as the position to place the cursor,
rather than just arbitrarily setting it at the end. This seems
reasonable, and arguably more reasonable than the current
behavior. Perhaps I can find the time to make this change in time
for the upcoming 2.5.2 release.
However, given the nature of your particular mask, ie. X{30},
The trick Werner describes should work for you.
Note: as wxMaskedTextCtrl() makes heavy use of wxCallAfter()
in its processing, you will also need to use it if you need to
modify the cursor after the set, in order to get the order of
operations right.
Regards,
/Will
ยทยทยท
--
Will Sadkin
Parlance Corporation
www.nameconnector.com