[wxPython] how to erase the text?

I am changing it accordingly now. Thank you.

Jenny

···

From: Raul Cota <cota@ucalgary.ca>
Reply-To: wxpython-users@lists.wxwindows.org
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] how to erase the text?
Date: Tue, 26 Jun 2001 16:27:19 -0600

Jenny

Sorry, just one more thing... I was thinking about it and there is a
bug with the code I gave you... if the user uses copy and paste to set
the value to text ctrl, then the EVT_CHAR event won't be triggered. So
maybe you still want to re-check the length of the line in the EVT_TEXT
event and handle it accordingly... perhaps...

self.extension.SetValue("")

or

txt = self.extension.GetValue()
self.extension.SetValue(txt[:4]) #Write only the first 4 characters

Raul

qun liu wrote:
>
> Yes, it works. Thanks again for your help.
>
> Jenny
>
> >From: Raul Cota <cota@ucalgary.ca>
> >Reply-To: wxpython-users@lists.wxwindows.org
> >To: wxpython-users@lists.wxwindows.org
> >Subject: Re: [wxPython] how to erase the text?
> >Date: Tue, 26 Jun 2001 15:35:50 -0600
> >
> >I'm assuming that all you want is to keep the TextCtrl from getting more
> >than 4 characters.
> >If I'm right.... What I would do is....
> >
> >self.extension = wxTextCtrl(panel, ID_EXTENSION, "")
> >EVT_TEXT(self, ID_EXTENSION, self.check)
> >EVT_CHAR(self.extension, self.EvtChar)
> >
> >def EvtChar(self, event):
> > k = event.GetKeyCode()
> > if self.extension.GetLineLength(0) != 4:
> > event.Skip()
> > else:
> > # 8 = backspace
> > # 13 = enter
> > # 27 = esc
> > if k == 8 or k == 13 or k == 27:
> > event.Skip()
> > else:
> > #If the length is already 4, I don't write the line
> > #event.Skip() and the character is not written
> > print 'error'
> >
> >def check(self, event):
> > #Whatever you want here
> > pass
> >
> >The EVT_CHAR event is ran before the EVT_TEXT event. And if you don't
> >write the line event.Skip(), the EVT_TEXT event is not ran at all, thus
> >the character pressed won't appear on the text control.
> >In this example I aloud the "backspace", "enter", and "esc" keys to be
> >passes to the control even if the length of the control is already 4.
> >That way you can still edit the text.
> >
> >I use this set of events for something different (I give my own behavior
> >to an enter and the arrow keys) but I think it could help you if that's
> >what you are trying to do.
> >
> >qun liu wrote:
> > >
> > > Hi,
> > >
> > > I am trying to repaint the wxTextCtrl when the length of the input text
> >is
> > > more than four, but Refresh() didn't work here. Could somebody give me
> >any
> > > suggestion? Thanks.
> > >
> > > Jenny
> > >
> > > #------------------------------------------------------
> > > self.extension = wxTextCtrl(panel, ID_EXTENSION, "")
> > > EVT_TEXT(self, ID_EXTENSION, self.check)
> > > def check(self, event):
> > > text = self.extension.GetValue()
> > > if (len(text) > 4 ):
> > > print "error"
> > > self.extension.Refresh(true)
> > >
> > > _________________________________________________________________
> > > Get your FREE download of MSN Explorer at http://explorer.msn.com
> > >
> > > _______________________________________________
> > > wxpython-users mailing list
> > > wxpython-users@lists.wxwindows.org
> > > http://lists.wxwindows.org/mailman/listinfo/wxpython-users
> >
> >_______________________________________________
> >wxpython-users mailing list
> >wxpython-users@lists.wxwindows.org
> >http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com