change keycode

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().

Regards,
/Will Sadkin
Parlance Corporation
www.parlancecorp.com

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. :frowning:

···

--
Qiangning Hong

_______________________________________________________
( Time sharing: The use of many people by the computer. )
-------------------------------------------------------
     o
      o
       ("`-' '-/") .___..--' ' "`-._
         ` *_ * ) `-. ( ) .`-.__. `)
         (_Y_.) ' ._ ) `._` ; `` -. .-'
      _.. `--'_..-_/ /--' _ .' ,4
   ( i l ),-'' ( l i),' ( ( ! .-'

Have you looked at wx.TextCtrl.Replace()? Unfortunately this
requires that you keep track of your insertion point, but at least
it is one way to make the change.

Donnal Walter
Arkansas Children's Hospital

···

--- Qiangning Hong <hongqn@gmail.com> 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. :frowning:

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. :frowning:

Finally I get the following solution, using EVT_TEXT.

class UpperTextCtrl(wx.TextCtrl):
    def __init__(self, *a, **kw):
        wx.TextCtrl.__init__(self, *a, **kw)
        wx.EVT_TEXT(self, self.GetId(), self.on_text)

    def on_text(self, evt):
        s = self.GetValue()
        u = s.upper()
        if s != u:
            self.SetValue(u)
        evt.Skip()

It would be a bit slow when have a large mount of text, but it is usable.

···

--
Qiangning Hong

________________________________
< Neutrinos are into physicists. >
--------------------------------
    \
     \
    ^__^ /
    ($$)\_______/ _________
    (__)\ )=( ____|_ \_____
        >>----w | \ \ \_____ |
        >> >> >> >>