示例#1
0
文件: widgets.py 项目: Lorquas/rhsm
    def _update_cell_based_on_data(self, column, cell_renderer, tree_model, tree_iter, Data=None):
        # Clear the cell if we are a parent row.
        if tree_model.iter_n_children(tree_iter) > 0:
            cell_renderer.set_property("text", "")

        # Disable editor if not multi-entitled.
        is_multi_entitled = tree_model.get_value(tree_iter, self.is_multi_entitled_store_idx)
        cell_renderer.set_property("editable", is_multi_entitled)

        if is_multi_entitled:
            quantity = tree_model.get_value(tree_iter, self.quantity_store_idx)
            cell_renderer.set_property("text", "%s *" % quantity)

        if self.available_store_idx is not None:
            available = tree_model.get_value(tree_iter, self.available_store_idx)

            if self.quantity_increment_idx is not None:
                increment = tree_model.get_value(tree_iter, self.quantity_increment_idx)
            else:
                increment = 1

            if available:
                if available != -1:
                    cell_renderer.set_property("adjustment",
                        ga_Gtk.Adjustment(lower=int(increment), upper=int(available), step_incr=int(increment)))
                else:
                    cell_renderer.set_property("adjustment",
                        ga_Gtk.Adjustment(lower=int(increment), upper=100, step_incr=int(increment)))
示例#2
0
    def __init__(self,
                 column_title,
                 tree_model,
                 quantity_store_idx,
                 is_multi_entitled_store_idx,
                 available_store_idx=None,
                 quantity_increment_idx=None,
                 editable=True):
        self.quantity_store_idx = quantity_store_idx
        self.is_multi_entitled_store_idx = is_multi_entitled_store_idx
        self.available_store_idx = available_store_idx
        self.quantity_increment_idx = quantity_increment_idx

        self.quantity_renderer = ga_Gtk.CellRendererSpin()
        self.quantity_renderer.set_property("xalign", 0)
        self.quantity_renderer.set_property(
            "adjustment", ga_Gtk.Adjustment(lower=1, upper=100, step_incr=1))
        self.quantity_renderer.set_property("editable", editable)
        self.quantity_renderer.connect("edited", self._on_edit, tree_model)
        self.quantity_renderer.connect("editing-started", self._setup_editor)

        super(QuantitySelectionColumn,
              self).__init__(column_title,
                             self.quantity_renderer,
                             text=self.quantity_store_idx)
        self.set_cell_data_func(self.quantity_renderer,
                                self._update_cell_based_on_data)

        self.set_max_width(100)
        self.set_min_width(100)
示例#3
0
    def _run_filter_value_test(self,
                               test_input_value,
                               is_allowed,
                               upper=15,
                               lower=1,
                               step_incr=1):
        column, tree_model, tree_iter = self._setup_column(1, True)

        adjustment = ga_Gtk.Adjustment(upper=upper,
                                       lower=lower,
                                       value=7.0,
                                       step_incr=step_incr)
        # Simulate the editable created by the CellRendererSpin object.
        editable = ga_Gtk.SpinButton()
        editable.set_property("adjustment", adjustment)

        self.stopped = False

        def ensure_stopped(name):
            self.stopped = True

        editable.emit_stop_by_name = ensure_stopped

        column._filter_spinner_value("test-event", editable, test_input_value)

        self.assertEquals(not is_allowed, self.stopped)