From: Alex T. <al...@tw...> - 2005-02-28 14:25:55
|
Brian Debuire wrote: > 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 Unnecessary (at least in the code shown here) - every path through on_txtText_keyPress sets it before using it. Is it used elsewhere ? > > 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. I may be missing some subtlety - but why not simply > def on_txtText_keyPress(self, event): > if len(self.components.txtText.text) < 10 or event.keyCode in > [8,316,317,318,319,127,314,315]: > event.Skip() btw - I don't think this will be significantly more efficient - but I find it easier to read -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 266.5.1 - Release Date: 27/02/2005 |