>
>
>Hi there,
>
>I was working on my text length limited widget, also I worked on a text
>field that only accepts numbers, and this is my code, hope it helps.
>
>
>def on_initialize(self, event):
> self.type = True
>
>def on_txtText_keyPress(self, event):
> keyCode = event.keyCode
> if keyCode in range(48,58) or keyCode in
>[8,316,317,318,319,127,314,315]:
> event.Skip()
>
>def on_txtText_keyPress(self, event):
> keyCode = event.keyCode
> if len(self.components.txtText.text) == 10:
> if keyCode in [8,316,317,318,319,127,314,315]:
> self.type = True
> else:
> self.type = False
> else:
> self.type = True
> if self.type:
> event.Skip()
> else:
> self.type = True
>
>
>Any suggestions or ideas on how to optmize this code, specially the text
>leght validation, are more than welcome.
>
>Regards,
>
>Brian
>
>_________________________________________________________________
>Express yourself instantly with MSN Messenger! Download today it's FREE!
>http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
>
I've been playing around a little with the wx.lib.masked.numctrl
package. There's a control named NumCtrl that basically does what you're
looking for. I reckon you might want to tinker around with it a little
and see if it works for you. You might have to write your code in a way
that it creates and binds the control to your pythoncard frame at init
(override the __init__ method of the PythonCard.model.Background or
PythonCard.model.PageBackground to load up the control)
eg.
from PythonCard import model,
from wx.lib.masked import numctrl
class myframe(model.Background):
def __init__(self, aParent, aBgRsrc):
model.Background.__init__(self, aParent, aBgRsrc)
self._initControls()
def _initControls(self):
self.txtText = numctrl.NumCtrl(self.panel, value=1234)
self.txtText.SetParameters(groupDigits=False, allowNegative=False,
useFixedWidthFont=False, max=5, limited=True)
Edward
|