clear TextCtrl after GetKeyCode()

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

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

···

On 07/01/13 08:07, Leon wrote:

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

  --

  To unsubscribe, send email to

or visit


Steve Gadget Barnes

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

great! That was it :slight_smile:
Thank you very much!