Qiangning Hong wrote:
Will Sadkin wrote:
Qiangning Hong wrote:
I want to make a TextCtrl automatically convert inputted lowercases
to uppercases, so I use a EVT_CHAR:class UpperCaseTextCtrl(wx.TextCtrl):
def __init__(self, *a, **kw):
...
wx.EVT_CHAR(self, self.on_char)def on_char(self, evt):
keycode = evt.KeyCode()
if chr(keycode) in string.lowercase:
newkeycode = asc(chr(keycode).upper())
WHAT_TO_DO_NOW() ???How can I tell TextCtrl to use the newkeycode instead of keycode?
wx.KeyEvent seems has no SetKeyCode() alike method.No, but it does have a "public" member, m_keyCode, that I believe
you can assign before calling event.Skip().Assign newkeycode to evt.m_keyCode and evt.Skip() doesn't work. The
lowercase letters still appear as normal.
Hmmm.... it would appear that the TextCtrl uses the information stored
stored in the C++ object, there seems to be no way of modifying it and
propagating it back to the underlying C++ data structure.
I've tried experimenting, including trying to create a new KeyEvent to
then call .Skip() on, but nothing I've tried works.
I even tried intercepting the uncooked input, using EVT_KEY_DOWN, but
this yields 65 for a lowercase a, with shiftDown of 0; when I try to
transform the event at this stage, and Skip() it, it doesn't take;
the flag is reset and the raw keycode is transformed to 97... There
seems to be no way to modify the original event, nor, it seems can you
create a new one that will "do the right thing."
So, until Robin or some other guru comes up with the necessary magic, you
may be forced to do what I do in the masked controls, which is to record
the insertion point, do a .GetText(), then insert the modified character
into the string at the insertion point, then do .SetText() with the new
value, then move the insertion point to where it should go next
(as .SetText() resets it.)
Or, you could use a masked.TextCtrl() of sufficient mask length to
accomodate your input, say, a mask of 'C{100}', and a formatcode of !,
without the F format to force the entire control to be displayed. This
would basically do what you want...
Hope this helps...
/Will