def __init__(self, widget=None): ProxyWidgetMixin.__init__(self) # Inicial valid state is unkown (None), so that when _set_valid_state is # called for the first time, the signal gets emitted self._valid = None self._fade = FadeOut(self) self._fade.connect('color-changed', self._on_fadeout__color_changed) self.connect('notify::mandatory', self._on_notify__mandatory) self.connect('notify::sensitive', self._on_notify__sensitive) self.connect('notify::visible', self._on_notify__visible)
def __init__(self, widget=None): ProxyWidgetMixin.__init__(self) # Inicial valid state is unkown (None), so that when _set_valid_state is # called for the first time, the signal gets emitted self._valid = None self._fade = FadeOut(self) self._fade.connect('color-changed', self._on_fadeout__color_changed) self.connect('notify::mandatory', self._on_notify__mandatory)
class ValidatableProxyWidgetMixin(ProxyWidgetMixin): """Class used by some Kiwi Widgets that need to support mandatory input and validation features such as custom validation and data-type validation. Mandatory support provides a way to warn the user when input is necessary. The validatation feature provides a way to check the data entered and to display information about what is wrong. """ implements(IValidatableProxyWidget) def __init__(self, widget=None): ProxyWidgetMixin.__init__(self) # Inicial valid state is unkown (None), so that when _set_valid_state is # called for the first time, the signal gets emitted self._valid = None self._fade = FadeOut(self) self._fade.connect('color-changed', self._on_fadeout__color_changed) self.connect('notify::mandatory', self._on_notify__mandatory) self.connect('notify::sensitive', self._on_notify__sensitive) self.connect('notify::visible', self._on_notify__visible) # Override in subclass def update_background(self, color): "Implement in subclass" def get_background(self): "Implement in subclass" def set_pixbuf(self, pixbuf): "Implement in subclass" def set_tooltip(self, text): "Implement in subclass" # Public API def is_valid(self): """ Verify the widget state. :returns: True if the widget is in validated state """ return self._valid def validate(self, force=False): """Checks if the data is valid. Validates data-type and custom validation. :param force: if True, force validation :returns: validated data or ValueUnset if it failed """ # If we're not visible or sensitive return a blank value, except # when forcing the validation if not force and (not self.get_property('visible') or not self.get_property('sensitive')): self._set_pixbuf(None) return ValueUnset try: data = self.read() log.debug('Read %r for %s' % (data, self.model_attribute)) self.validate_value(data) # check if we should draw the mandatory icon # this need to be done before any data conversion because we # we don't want to end drawing two icons if self.mandatory and (data is None or data == '' or data == ValueUnset): self.set_blank() return ValueUnset else: # The widgets themselves have now valid the data # Next step is to call the application specificed # checks, which are found in the view. if data is not None and data is not ValueUnset: # this signal calls the on_widgetname__validate method # of the view class and gets the exception (if any). error = self.emit("validate", data) if error: raise error self.set_valid() return data except ValidationError, e: self.set_invalid(str(e)) return ValueUnset
def __init__(self, widget=None): ProxyWidgetMixin.__init__(self) self._valid = True self._fade = FadeOut(self) self._fade.connect('color-changed', self._on_fadeout__color_changed)
class ValidatableProxyWidgetMixin(ProxyWidgetMixin): """Class used by some Kiwi Widgets that need to support mandatory input and validation features such as custom validation and data-type validation. Mandatory support provides a way to warn the user when input is necessary. The validatation feature provides a way to check the data entered and to display information about what is wrong. """ implements(IValidatableProxyWidget) gproperty('mandatory', bool, default=False) def __init__(self, widget=None): ProxyWidgetMixin.__init__(self) self._valid = True self._fade = FadeOut(self) self._fade.connect('color-changed', self._on_fadeout__color_changed) # Override in subclass def update_background(self, color): "Implement in subclass" def get_background(self): "Implement in subclass" def set_pixbuf(self, pixbuf): "Implement in subclass" def get_icon_window(self): "Implement in subclass" def set_tooltip(self, text): "Implement in subclass" # Public API def is_valid(self): """ Verify the widget state. @returns: True if the widget is in validated state """ return self._valid def validate(self, force=False): """Checks if the data is valid. Validates data-type and custom validation. @param force: if True, force validation @returns: validated data or ValueUnset if it failed """ # If we're not visible or sensitive return a blank value, except # when forcing the validation if not force and (not self.get_property('visible') or not self.get_property('sensitive')): return ValueUnset try: data = self.read() log.debug('Read %r for %s' % (data, self.model_attribute)) # check if we should draw the mandatory icon # this need to be done before any data conversion because we # we don't want to end drawing two icons if self.mandatory and (data == None or data == '' or data == ValueUnset): self.set_blank() return ValueUnset else: # The widgets themselves have now valid the data # Next step is to call the application specificed # checks, which are found in the view. if data is not None and data is not ValueUnset: # this signal calls the on_widgetname__validate method # of the view class and gets the exception (if any). error = self.emit("validate", data) if error: raise error self.set_valid() return data except ValidationError, e: self.set_invalid(str(e)) return ValueUnset