コード例 #1
0
ファイル: test_proxy.py プロジェクト: rcaferraz/kiwi
    def setUp(self):
        self.view = FakeView()
        self.view.add('checkbutton', bool, ProxyCheckButton)
        self.view.add('entry', str, ProxyEntry)
        self.view.add('label', str, ProxyLabel)
        self.view.add('spinbutton', int, ProxySpinButton)
        self.view.add('hscale', float, ProxyHScale)
        self.view.add('vscale', float, ProxyVScale)
        self.view.add('button', str, ProxyButton)
        self.view.add('buttonpixbuf', gdk.Pixbuf, ProxyButton)

        self.view.add('textview', str, ProxyTextView)
        self.radio_first = self.view.add('radiobutton', str, ProxyRadioButton)
        self.radio_first.set_property('data_value', 'first')
        self.radio_second = ProxyRadioButton()
        self.radio_second.set_group(self.radio_first)
        self.radio_second.set_property('data_value', 'second')

        self.view.hscale.get_adjustment().upper = 200
        self.view.vscale.get_adjustment().upper = 250

        self.comboentry = self.view.add('comboentry', str, ProxyComboEntry)
        self.comboentry.prefill(['CE1', 'CE2', 'CE3'])
        self.comboentry.show()

        self.combobox = self.view.add('combobox', str, ProxyComboBox)
        self.combobox.prefill(['CB1', 'CB2', 'CB3'])
        self.combobox.show()

        self.model = Model()
        self.proxy = Proxy(self.view, self.model, self.view.widgets)
コード例 #2
0
    def add_proxy(self, model=None, widgets=None):
        """
        Add a proxy to this view that automatically update a model when
        the view changes. Arguments:

          - model. the object we are proxing. It can be None if we don't have
            a model yet and we want to display the interface and set it up with
            future models.
          - widgets. the list of widgets that contains model attributes to be
            proxied. If it is None (or not specified) it will be the whole list
            of widgets this View has.

        This method return a Proxy object that you may want to use to force
        updates or setting new models. Keep a reference to it since there is
        no way to get that proxy later on. You have been warned (tm)
        """
        log.debug(
            '%s: adding proxy for %s' %
            (self.__class__.__name__, model and model.__class__.__name__))

        widgets = widgets or self.widgets
        proxy_widgets = []

        for widget_name in widgets:
            widget = getattr(self, widget_name, None)
            if widget is None:
                continue

            if not IValidatableProxyWidget.providedBy(widget):
                continue

            try:
                widget.connect('validation-changed',
                               self._on_child__validation_changed, widget_name)
            except TypeError:
                raise AssertionError("%r does not have a validation-changed "
                                     "signal." % widget)

            proxy_widgets.append((widget_name, widget))

        proxy = Proxy(self, model, widgets)
        self._proxies.append(proxy)

        for widget_name, widget in proxy_widgets:
            # Do not store validation value for invisible/insensitive widgets.
            # If they turn visible/sensitive, _on_child__validation_changed
            # will handle that
            if (not widget.get_property('visible')
                    or not widget.get_property('sensitive')):
                continue

            # Proxy.__init__ will call widget.validate(force=True), so we
            # can use rely on widget.is_valid() here
            self._validation[widget_name] = widget.is_valid()
            validation_log.info(
                "%s: %s=%r (initial)" %
                (self.__class__.__name__, widget_name, widget.is_valid()))

        return proxy
コード例 #3
0
ファイル: test_ComboBox.py プロジェクト: rosemberg-al/kiwi
 def setUp(self):
     self.model = Settable(attr=0)
     proxy = Proxy(FakeView(), self.model)
     self.combo = disabledeprecationcall(self.type)
     self.combo.data_type = int
     self.combo.model_attribute = 'attr'
     self.combo.prefill([('foo', 0), ('bar', 1)])
     proxy.add_widget('attr', self.combo)
     self.combo.show()
コード例 #4
0
ファイル: test_ComboBox.py プロジェクト: rosemberg-al/kiwi
    def test_prefill_attr_none(self):
        model = Settable(attr=None)
        proxy = Proxy(FakeView(), model)
        combo = ProxyComboEntry()
        combo.data_type = int
        combo.model_attribute = 'attr'
        combo.prefill([('foo', 10), ('bar', 20)])
        proxy.add_widget('attr', combo)

        self.assertEqual(model.attr, None)
コード例 #5
0
ファイル: test_ComboBox.py プロジェクト: rosemberg-al/kiwi
    def test_prefill_attr_none(self):
        model = Settable(attr=None)
        proxy = Proxy(FakeView(), model)
        combo = ProxyComboBox()
        combo.data_type = int
        combo.model_attribute = 'attr'
        combo.prefill([('foo', 10), ('bar', 20)])
        proxy.add_widget('attr', combo)

        # Even though attr is None, the combo doesn't allow something
        # not prefilled in it to be selected. In this case, it will select
        # the first item (prefill actually does that) instead.
        self.assertEqual(model.attr, 10)
コード例 #6
0
ファイル: views.py プロジェクト: hsavolai/vmlab
    def add_proxy(self, model=None, widgets=None):
        """
        Add a proxy to this view that automatically update a model when
        the view changes. Arguments:

          - model. the object we are proxing. It can be None if we don't have
            a model yet and we want to display the interface and set it up with
            future models.
          - widgets. the list of widgets that contains model attributes to be
            proxied. If it is None (or not specified) it will be the whole list
            of widgets this View has.

        This method return a Proxy object that you may want to use to force
        updates or setting new models. Keep a reference to it since there is
        no way to get that proxy later on. You have been warned (tm)
        """
        log('%s: adding proxy for %s' % (
            self.__class__.__name__,
            model and model.__class__.__name__))

        widgets = widgets or self.widgets

        for widget_name in widgets:
            widget = getattr(self, widget_name, None)
            if widget is None:
                continue

            if not IValidatableProxyWidget.providedBy(widget):
                continue

            try:
                widget.connect('validation-changed',
                               self._on_child__validation_changed,
                               widget_name)
            except TypeError:
                raise AssertionError("%r does not have a validation-changed "
                                     "signal." % widget)

        proxy = Proxy(self, model, widgets)
        self._proxies.append(proxy)
        return proxy