clear TextCtrl after GetKeyCode()

550 views
Skip to first unread message

Leon

unread,
Jan 7, 2013, 3:07:02 AM1/7/13
to wxpytho...@googlegroups.com
hi!

I have a Text entry field (TextCtrl).
I am waiting for a special character (Barcode scanning) at the end of the text entered.

The TextCtrl should be cleared after the special character "(" is entered.

The problem: the TextCtrl is cleared, but afterwards the special character is entered. So the TextCtrl does not stay empty!

Has anybody got an idea, what I am doing wrong?

Here my code:
        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME2TEXTCTRL1, name='textCtrl1',
              parent=self, pos=wx.Point(32, 32), size=wx.Size(100, 21), style=0,
              value='textCtrl1')
        self.textCtrl1.Bind(wx.EVT_CHAR, self.OnTextCtrl1Char)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnTextCtrl1Char(self, event):
        key_pressed = event.GetKeyCode()
        if key_pressed == 40:
            product_id = self.textCtrl1.GetValue()
            self.textCtrl1.Clear()
            time.sleep(1)      # <------- waiting does not help either
            self.textCtrl1.SetValue('new Text')
        event.Skip()

Steve Barnes

unread,
Jan 7, 2013, 3:20:20 AM1/7/13
to wxpytho...@googlegroups.com
--
To unsubscribe, send email to wxPython-user...@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Try not calling event.Skip if the special char is matched, i.e. put an else in before it.

The problem is that you are processing it, (clear text control), then allowing it to be default processed.

Steve
--
Steve Gadget Barnes

Leon

unread,
Jan 7, 2013, 3:31:54 AM1/7/13
to wxpytho...@googlegroups.com
great! That was it :)
Thank you very much!

Reply all
Reply to author
Forward
0 new messages