Example #1
0
    def _setup_widget(self, widget_name, widget):
        if not IProxyWidget.providedBy(widget):
            raise ProxyError("The widget %s (%r), in view %s is not "
                             "a kiwi widget and cannot be added to a proxy"
                             % (widget_name, widget,
                                self._view.__class__.__name__))

        data_type = _get_widget_data_type(widget)
        if data_type is None:
            raise ProxyError("The kiwi widget %s (%r) in view %s should "
                             "have a data type set" % (
                                 widget_name, widget, self._view.__class__.__name__))

        attribute = widget.get_property('model-attribute')
        if not attribute:
            attribute = widget_name
            widget.set_property('model-attribute', widget_name)

        # Do a isinstance here instead of in the callback,
        # as an optimization, it'll never change in runtime anyway
        connection_id = widget.connect(
            'content-changed',
            self._on_widget__content_changed,
            attribute,
            IValidatableProxyWidget.providedBy(widget))
        widget.set_data('content-changed-id', connection_id)

        if IValidatableProxyWidget.providedBy(widget):
            connection_id = widget.connect(
                'notify::visible',
                self._on_widget__notify)
            widget.set_data('notify-visible-id', connection_id)

            connection_id = widget.connect(
                'notify::sensitive',
                self._on_widget__notify)
            widget.set_data('notify-sensitive-id', connection_id)

            connection_id = widget.connect(
                'validation-changed',
                self._on_widget__validation_changed,
                attribute)
            widget.set_data('validation-changed-id', connection_id)

        model_attributes = self._model_attributes
        # save this widget in our map
        if (attribute in model_attributes and
            # RadioButtons are allowed several times
            not gobject.type_is_a(widget, 'GtkRadioButton')):
            old_widget = model_attributes[attribute]
            raise KeyError("The widget %s (%r) in view %s is already in "
                           "the proxy, defined by widget %s (%r)" % (
                               widget_name, widget, self._view.__class__.__name__,
                               old_widget.name, old_widget))

        model_attributes[attribute] = widget
        self._reset_widget(attribute, widget)
Example #2
0
    def _setup_widget(self, widget_name, widget):
        if not IProxyWidget.providedBy(widget):
            raise ProxyError("The widget %s (%r), in view %s is not "
                             "a kiwi widget and cannot be added to a proxy"
                             % (widget_name, widget,
                                self._view.__class__.__name__))

        data_type = _get_widget_data_type(widget)
        if data_type is None:
            raise ProxyError("The kiwi widget %s (%r) in view %s should "
                             "have a data type set" % (
                                 widget_name, widget, self._view.__class__.__name__))

        attribute = widget.get_property('model-attribute')
        if not attribute:
            attribute = widget_name
            widget.set_property('model-attribute', widget_name)

        # Do a isinstance here instead of in the callback,
        # as an optimization, it'll never change in runtime anyway
        connection_id = widget.connect(
            'content-changed',
            self._on_widget__content_changed,
            attribute,
            IValidatableProxyWidget.providedBy(widget))
        widget.set_data('content-changed-id', connection_id)

        if IValidatableProxyWidget.providedBy(widget):
            connection_id = widget.connect(
                'notify::visible',
                self._on_widget__notify)
            widget.set_data('notify-visible-id', connection_id)

            connection_id = widget.connect(
                'notify::sensitive',
                self._on_widget__notify)
            widget.set_data('notify-sensitive-id', connection_id)

            connection_id = widget.connect(
                'validation-changed',
                self._on_widget__validation_changed,
                attribute)
            widget.set_data('validation-changed-id', connection_id)

        model_attributes = self._model_attributes
        # save this widget in our map
        if (attribute in model_attributes and
            # RadioButtons are allowed several times
            not gobject.type_is_a(widget, 'GtkRadioButton')):
            old_widget = model_attributes[attribute]
            raise KeyError("The widget %s (%r) in view %s is already in "
                           "the proxy, defined by widget %s (%r)" % (
                               widget_name, widget, self._view.__class__.__name__,
                               old_widget.name, old_widget))

        model_attributes[attribute] = widget
        self._reset_widget(attribute, widget)
Example #3
0
 def attach_form(self, form, model_attribute):
     self.label_widget = self.build_label()
     self.widget = self.build_widget()
     if IProxyWidget.providedBy(self.widget):
         if self.widget_data_type is not None:
             self.widget.data_type = self.widget_data_type
         self.widget.mandatory = self.mandatory
         self.widget.model_attribute = model_attribute
         if not self.label_attribute:
             self.label_attribute = model_attribute + "_lbl"
         self.widget.connect("content-changed", self._on_widget__content_changed)
     self.model_attribute = model_attribute
     self.form = form
     self.view = form.view
     self._build_add_button()
     self._build_edit_button()
     self.attach()
     self.label_widget.show()
     self.widget.show()
Example #4
0
 def attach_form(self, form, model_attribute):
     self.label_widget = self.build_label()
     self.widget = self.build_widget()
     if IProxyWidget.providedBy(self.widget):
         if self.widget_data_type is not None:
             self.widget.data_type = self.widget_data_type
         self.widget.mandatory = self.mandatory
         self.widget.model_attribute = model_attribute
         if not self.label_attribute:
             self.label_attribute = model_attribute + '_lbl'
         self.widget.connect(
             'content-changed', self._on_widget__content_changed)
     self.model_attribute = model_attribute
     self.form = form
     self.view = form.view
     self._build_add_button()
     self._build_edit_button()
     self._build_delete_button()
     self.attach()
     if self.label_widget:
         self.label_widget.show()
     self.widget.show()