home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / gui / validators.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  4.2 KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. import string
  6.  
  7. class SimpleValidator(wx.PyValidator):
  8.     
  9.     def __init__(self, char_callbacks, str_callbacks):
  10.         if callable(char_callbacks):
  11.             char_callbacks = (char_callbacks,)
  12.         
  13.         if callable(str_callbacks):
  14.             str_callbacks = (str_callbacks,)
  15.         
  16.         wx.PyValidator.__init__(self)
  17.         self.char_callbacks = char_callbacks
  18.         self.str_callbacks = str_callbacks
  19.         self.Bind(wx.EVT_CHAR, self.OnChar)
  20.         self.Bind(wx.EVT_TEXT, self.OnText)
  21.  
  22.     
  23.     def OnChar(self, event):
  24.         key = event.GetKeyCode()
  25.         if key < 0 and key > 255 and chr(key) not in string.printable or self.check_char(chr(key)):
  26.             event.Skip()
  27.             self._last_ok_val = event.EventObject.Value
  28.             return None
  29.         if not wx.Validator.IsSilent():
  30.             wx.Bell()
  31.         
  32.  
  33.     
  34.     def OnText(self, event):
  35.         s = event.EventObject.Value
  36.         if not self.check_string(s):
  37.             event.EventObject.Value = self._last_ok_val
  38.         else:
  39.             self._last_ok_val = s
  40.             event.Skip()
  41.  
  42.     
  43.     def check_char(self, c):
  44.         return (all,)((lambda .0: for cb in .0:
  45. cb(c))(self.char_callbacks))
  46.  
  47.     
  48.     def check_string(self, s):
  49.         return (all,)((lambda .0: for cb in .0:
  50. cb(s))(self.str_callbacks))
  51.  
  52.     
  53.     def Clone(self):
  54.         return SimpleValidator(self.char_callbacks, self.str_callbacks)
  55.  
  56.     
  57.     def Validate(self, win):
  58.         return 1
  59.  
  60.     
  61.     def TransferToWindow(self):
  62.         return True
  63.  
  64.     
  65.     def TransferFromWindow(self):
  66.         return True
  67.  
  68.     
  69.     def __add__(self, other):
  70.         return SimpleValidator(self.char_callbacks + other.char_callbacks, self.str_callbacks + other.str_callbacks)
  71.  
  72.  
  73.  
  74. def string_check(type):
  75.     valid = getattr(string, type)
  76.     return (lambda s: (all,)((lambda .0: for c in .0:
  77. c in valid)(s))
  78. )
  79.  
  80.  
  81. def AlphaOnly():
  82.     return SimpleValidator((string_check('letters'),), ())
  83.  
  84.  
  85. def DigitsOnly():
  86.     return SimpleValidator((string_check('digits'),), ())
  87.  
  88.  
  89. def LengthLimit(n):
  90.     return SimpleValidator(((),), ((lambda s: len(s) <= n),))
  91.  
  92.  
  93. def NumericLimit(start, stop = None):
  94.     if stop is None:
  95.         start = 0
  96.         stop = start
  97.     
  98.     return None + DigitsOnly()((SimpleValidator, ()), (lambda s: if not not s:
  99. if int(s) <= int(s):
  100. int(s) <= stopint(s) <= int(s)int(s)))
  101.  
  102. common_validators = dict(d = DigitsOnly, s = AlphaOnly)
  103.