def OnChar(self, event): key = event.KeyCode if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return textCtrl = self.GetWindow() startPos, endPos = textCtrl.GetSelection() length = textCtrl.GetLastPosition() - (endPos - startPos) if length >= self.maxLength: if not wx.Validator_IsSilent(): wx.Bell() return if (self.allowRaw and textCtrl.GetInsertionPoint() == 0 and chr(key).upper() == "R"): textCtrl.WriteText("R") return if chr(key) in hexdigits: textCtrl.WriteText(chr(key).upper()) return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling event.Skip eats the event before it # gets to the text control return
def Validate(self, parent): """Validate the content of the filter property dialog This method takes a single argument: parent the dialog that is validated and it returns True if the range of wavelengths is correctly defined or False otherwise.""" # Verify that to_wavelength is larger that from_wavelength. from_wavelength = float(parent.from_wavelength_box.GetValue()) to_wavelength = float(parent.to_wavelength_box.GetValue()) if to_wavelength < from_wavelength: if not wx.Validator_IsSilent(): wx.Bell() parent.to_wavelength_box.SetFocus() parent.to_wavelength_box.SetSelection(0, 1000) parent.Refresh() return False # Verify that by_wavelength is smaller than the difference between # from_wavelength and to_wavelength. by_wavelength = float(parent.by_wavelength_box.GetValue()) if by_wavelength >= (to_wavelength - from_wavelength): if not wx.Validator_IsSilent(): wx.Bell() parent.by_wavelength_box.SetFocus() parent.by_wavelength_box.SetSelection(0, 1000) parent.Refresh() return False return True
def OnChar(self, event): txtCtrl = self.GetWindow() key = event.GetKeyCode() isDigit = False if key < 256: isDigit = chr(key).isdigit() if key in (wx.WXK_RETURN, wx.WXK_DELETE, wx.WXK_BACK) or \ key > 255 or isDigit: if isDigit: # Check if in range val = txtCtrl.GetValue() digit = chr(key) pos = txtCtrl.GetInsertionPoint() if pos == len(val): val += digit else: val = val[:pos] + digit + val[pos:] val = int(val) if val < self._min or val > self._max: if not wx.Validator_IsSilent(): wx.Bell() return event.Skip() return if not wx.Validator_IsSilent(): # Beep to warn about invalid input wx.Bell() return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if self.data_type in ['integer', 'bigint']: if chr(key) in '-' + string.digits: event.Skip() return elif self.data_type in ['float', 'money']: if chr(key) in ',.' + string.digits: event.Skip() return else: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling event.Skip eats the event before it # gets to the text control return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if chr(key) in string.digits: event.Skip() return if chr(key) == '-' and '-' not in self.GetWindow().GetValue(): self.GetWindow().SetInsertionPoint(0) self.GetWindow().WriteText("-") self.GetWindow().SetInsertionPointEnd() return if chr(key) in [',', '.'] and "." not in self.GetWindow().GetValue(): self.GetWindow().WriteText(".") return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def OnChar( self, event ): key = event.GetKeyCode() char = chr( key ) okKeys = [ wx.WXK_DELETE, wx.WXK_NUMPAD_ENTER, wx.WXK_RETURN, wx.WXK_TAB, wx.WXK_NUMPAD_SUBTRACT, wx.WXK_SUBTRACT ] if key < wx.WXK_SPACE or key in okKeys or key > 255 or char == '-': event.Skip() return # Allow the key stroke if is is a number or if this is the first # decimal point we have encountered. val = self.GetWindow().GetValue() if char in string.digits or ( char == '.' and '.' not in val ): event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if self.flag == 0: tc = self.GetWindow() var = tc.GetValue() if self.ifHouse(var, key): event.Skip() return elif self.flag == 1: tc = self.GetWindow() var = tc.GetValue() if self.ifMid(var, key): event.Skip() return elif self.flag == 2: tc = self.GetWindow() var = tc.GetValue() if self.ifCid(var, key): event.Skip() return elif self.flag == 3: tc = self.GetWindow() var = tc.GetValue() if self.ifMidPlus(var, key): event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() return
def Validate(self, parent): """Validate the formula This method takes a single argument: parent the control that is validated and it returns True if the content of the control is an appropriate stack formula or False otherwise.""" # If the condition for testing is not filled, the test is not # performed. if self.condition and not self.condition(): return True window = self.GetWindow() answer = window.GetValue() # Try to interpret the stack formula. try: analyse_stack_formula(answer) except stack_error, error: if not wx.Validator_IsSilent(): wx.Bell() window.SetFocus() window.SetSelection(error.get_position(), error.get_position()+1) return False
def OnChar(self, event): """Verify that the caracters entered in the control are digits""" key = event.GetKeyCode() # Accept delete and special caracters. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return window = self.GetWindow() answer = window.GetValue() selection_span = window.GetSelection() # Accept the digits, except before a dash. if chr(key) in string.digits: if selection_span[1] == len(answer) or answer[selection_span[1]] != "-": event.Skip() return # Accept a dash, if the minimum is negative, it is the first # character and there is no other dash. elif chr(key) == "-": if self.minimum is not None and self.minimum < 0.0: if selection_span[0] == 0 and "-" not in answer[selection_span[1]:]: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell()
def OnChar(self, event): key = event.GetKeyCode() # control chars if (key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255 or event.AltDown() or event.CmdDown() or event.ControlDown() or event.MetaDown()): event.Skip() return try: char = chr(key) textcontrol = self.GetWindow() pos = textcontrol.GetInsertionPoint() val = textcontrol.GetValue() newval = val[0:pos] + char + val[pos:len(val)] if self.CheckText(newval, immediate=True): event.Skip() return except UnicodeDecodeError: pass # should we bell? if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def Validate(self, parent): """Validate the formula This method takes a single argument: parent the dialog that is validated and it returns True if the content of the dialog is an appropriate stack formula or False otherwise.""" formula = parent.formula_box.GetValue() # Build a list of used symbols (those in the formula). used_symbols = [] for char in formula: if char in string.ascii_letters: if not char in used_symbols: used_symbols += char # Get a list of all defined symbols. defined_symbols = parent.get_symbols() # Verify that all symbols are defined. for symbol in used_symbols: if not symbol in defined_symbols: position = formula.index(symbol) if not wx.Validator_IsSilent(): wx.Bell() parent.formula_box.SetFocus() parent.formula_box.SetSelection(position, position+1) return False return True
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if self.flag == HEX_ONLY and chr(key) in self.hexs: event.Skip() return if self.flag == ALPHA_ONLY and chr(key) in string.letters: event.Skip() return if self.flag == DIGIT_ONLY and chr(key) in string.digits: event.Skip() return if self.flag == DIGIT_ONLY and chr(key) in '-': event.Skip() return if self.flag == DIGIT_ONLY and chr(key) in '.': event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def Validate(self, parent): """Validate the symbol This method takes a single argument: parent the control that is validated and it returns True if the content of the control is an appropriate stack formula symbol or False otherwise.""" # If the condition for testing is not filled, the test is not # performed. if self.condition and not self.condition(): return True # Get the value. window = self.GetWindow() answer = window.GetValue() # The symbol must be only one caracter long. if len(answer) > 1: if not wx.Validator_IsSilent(): wx.Bell() window.SetFocus() window.SetSelection(0, len(answer)) return False return True
def OnKillFocus(self, event): """Validate the formula when the control looses focus This method takes a single argument: event the event.""" # Get the value. window = self.GetWindow() answer = window.GetValue() # Replace line changes by 1 or 2 spaces depending on the platform # in order for the selection position to work correctly. if sys.platform == "win32": answer = answer.replace("\n", " ") else: answer = answer.replace("\n", " ") # If there is no value, this is an error. By not calling # event.Skip(), the event is not passed to the next control. if len(answer) == 0: return # Try to interpret the stack formula. try: analyse_stack_formula(answer) except stack_error, error: if not wx.Validator_IsSilent(): wx.Bell() window.SetFocus() window.SetSelection(error.get_position(), error.get_position()+1) return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if self.flag == VALIDATE_ALPHA and chr(key) in string.letters: event.Skip() return if self.flag == VALIDATE_INT and chr(key) in string.digits: event.Skip() return if self.flag == VALIDATE_FLOAT and chr(key) in string.digits + ".": event.Skip() return if self.flag == None: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def ProcessKey(self, event): key = event.GetKeyCode() if key in self.codelist or chr(key) in self.charlist: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell()
def OnChar(self, event): """Verify that a caracter is appropriate for a symbol This method takes a single argument: event the event.""" key = event.GetKeyCode() # Accept delete and special caracters. if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return char = chr(key) # Accept only lowercase and uppercase. if char not in string.ascii_letters: if not wx.Validator_IsSilent(): wx.Bell() return # Get the value. window = self.GetWindow() answer = window.GetValue() selection = window.GetSelection() # The symbol must be only one caracter long, therefore there must # be nothing in the box to enter a new caracter or what is already # there must be selected. if len(answer) - (selection[1]-selection[0]) + 1 > 1: if not wx.Validator_IsSilent(): wx.Bell() return # The symbol must not be used in other boxes. (Calling get_symbols # at this point won't return the content of the presently edited # window since the value has not been passed yet). if char in window.GetParent().get_symbols(): if not wx.Validator_IsSilent(): wx.Bell() return event.Skip() return
def OnChar(self, event): key = event.KeyCode() ctrl = event.GetEventObject() value = ctrl.get_value() textval = wx.TextCtrl.GetValue(ctrl) pos = ctrl.GetInsertionPoint() sel_start, sel_to = ctrl.GetSelection() select_len = sel_to - sel_start # Predict resulting value and validate it. if key in (wx.WXK_DELETE, wx.WXK_BACK): if select_len > 0: new_text = textval[:sel_start] + textval[sel_to:] elif key == wx.WXK_DELETE and pos < len(textval): new_text = textval[:pos] + textval[pos + 1:] elif key == wx.WXK_BACK and pos > 0: new_text = textval[:pos - 1] + textval[pos:] else: new_text = textval if self.__is_valid(new_text): event.Skip() return else: # Text box is empty, so fill it with "0.0" or the minimum # allowed value and select it for quick replacing by the # user if desired. # The selection must be done after the TextCtrl responses to # this event, so use CallAfter function. if self.__is_valid('0.0'): new_text = '0.0' else: new_text = str(self.min) wx.CallAfter(ctrl.SetValue, new_text) wx.CallAfter(ctrl.SetInsertionPoint, 0) wx.CallAfter(ctrl.SetSelection, 0, len(new_text)) event.Skip() elif key < wx.WXK_SPACE or key > 255: event.Skip() return elif chr(key) in (string.digits + '-.'): new_text = textval[:sel_start] + chr(key) + textval[sel_to:] if self.__is_valid(new_text): event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def OnChar(self, evt): key = evt.KeyCode() if key < wx.WXK_SPACE or key==wx.WXK_DELETE or key>255: evt.Skip() return if self.filter(chr(key)): evt.Skip() return elif not wx.Validator_IsSilent(): wx.Bell() return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if chr(key) in CHARS: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() return
def is_validator_silent(): """ Checks whether the wx.Validator is currently silent. See also: - wxp4 : wx.Validator#IsSilent() - older: wx.Validator_IsSilent() """ if IS_WXP4: return wx.Validator.IsSilent() else: return wx.Validator_IsSilent()
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() #放过合适该数据 if self.Validate(self.GetWindow() ): event.Skip()
def OnChar(self, event): key = event.KeyCode if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if chr(key) in self.floatchars: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() return
def OnChar(self, event): key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255 or chr( key) in string.letters + string.digits + ".-_": event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() # Returning without calling even.Skip eats the event before it # gets to the text control return
def Validate(self, parent): """Validate the content of the control This method takes a single argument: parent the control that is validated and it returns True if the content of the control is an integer within the imposed limits or False otherwise.""" # If the condition for testing is not filled, the test is not # performed. if self.condition and not self.condition(): return True error = False window = self.GetWindow() answer = window.GetValue() # First try to convert the value to a int. try: value = int(answer) except ValueError: error = True # Then verify that the value fits in acceptable values. if not error: if self.minimum is not None: if callable(self.minimum): minimum = self.minimum() else: minimum = self.minimum if value < minimum: error = True if self.maximum is not None: if callable(self.maximum): maximum = self.maximum() else: maximum = self.maximum if value > maximum: error = True if error: if not wx.Validator_IsSilent(): wx.Bell() window.SetFocus() window.SetSelection(0, len(answer)) window.Refresh() return False return True
def OnChar(self, event): """Process values as they are entered into the control @param event: event that called this handler """ key = event.GetKeyCode() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or \ key > 255 or chr(key) in '0123456789': event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() return
def OnChar(self, event): txtCtrl = self.GetWindow() key = event.GetKeyCode() isDigit = False if key < 256: isValid = chr(key) in self.allow_chars if key in (wx.WXK_RETURN, wx.WXK_DELETE, wx.WXK_BACK) or key > 255 or isValid: event.Skip() return if not wx.Validator_IsSilent(): # Beep to warn about invalid input wx.Bell() return
def _on_char(self, event): # Filter text input to ensure value is always a valid float. key = event.GetKeyCode() char = chr(key) current_value = self.GetWindow().GetValue() if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if ((char in string.digits) or (char == '.' and char not in current_value)): event.Skip() return if not wx.Validator_IsSilent(): wx.Bell() return
def OnChar(self, event): """ :param event: :return: """ txtCtrl = self.GetWindow() key = event.GetKeyCode() isDigit = False if key < 256: isDigit = chr(key).isdigit() if key in self.allow_keys or key > 255 or isDigit: # if key in self.allow_keys or isDigit: # if isDigit: # # Check if in range # val = txtCtrl.get_value(key) # # value, src = parse_number(self.fmt, val) # val = int(val) # if val < self._min or val > self._max: # if not wx.Validator_IsSilent(): # wx.Bell() # return # if key == ord('-'): # val = txtCtrl.get_value(key) # # values, src = parse_number(val, self.fmt) # # if len(values) != 1 and val != '-' and val != '+': # if not wx.Validator_IsSilent(): # wx.Bell() # txtCtrl.set_format_error_color() # # return event.Skip() return if not wx.Validator_IsSilent(): # Beep to warn about invalid input wx.Bell() return
def OnChar(self, event): # FIXME: something is wrong with this code, KeyCode # behavior has been changed in wxPython 2.8.1? #print event, type(event), event.KeyCode key = event.KeyCode if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: event.Skip() return if chr(key) in string.digits: event.Skip() return if not wx.Validator_IsSilent(): wx.Bell()