Exemplo n.º 1
0
class ContentsListController(InlineObjectListStoreController):
    """ 
        Controller for the atom contents ListStore
    """
    new_val = None
    auto_adapt = False  # FIXME

    treemodel_class_type = AtomContentObject

    def _reset_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True)
        tv.set_model(model)

        # Atom column:
        def atom_renderer(column, cell, model, itr, (obj_col, lbl_col)):
            obj = model.get_value(itr, obj_col)
            if lbl_col is not None:
                lbl = model.get_value(itr, lbl_col)
                if callable(lbl): lbl = lbl(obj)
                cell.set_property("text", lbl)
            else:
                if hasattr(obj, "name"):
                    cell.set_property('text', obj.name)
                else:
                    cell.set_property('text', '#NA#')

        def adjust_combo(cell, editable, path, data=None):
            if editable is not None:
                rend = gtk.CellRendererText()
                editable.clear()
                editable.pack_start(rend)
                editable.set_cell_data_func(rend, atom_renderer, (0, 2))

        tv.append_column(
            new_combo_column("Atoms",
                             changed_callback=self.on_atom_changed,
                             edited_callback=self.on_atom_edited,
                             editing_started_callback=adjust_combo,
                             xalign=0.0,
                             model=self.model.create_prop_store(),
                             data_func=(atom_renderer, (0, None)),
                             text_column=0,
                             editable=True))

        # Content column:
        def on_float_edited(rend, path, new_text, col):
            itr = model.get_iter(path)
            try:
                model.set_value(itr, col, float(new_text))
            except ValueError:
                logger.exception("Invalid value entered ('%s')!" % new_text)
            return True

        tv.append_column(
            new_text_column('Default contents',
                            text_col=2,
                            xalign=0.0,
                            editable=True,
                            data_func=create_float_data_func(),
                            edited_callback=(on_float_edited, (2, ))))
Exemplo n.º 2
0
 def add_text_col(title, colnr, is_float=True, editable=True):
     tv.append_column(new_text_column(
         title,
         data_func=create_float_data_func() if is_float else None,
         editable=editable,
         edited_callback=(self.on_item_cell_edited, (model, colnr)) if editable else None,
         resizable=True,
         text_col=colnr))
Exemplo n.º 3
0
    def _reset_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode='MULTIPLE', reset=True)
        tv.set_model(model)

        # Name column:
        def text_renderer(column, cell, model, itr, args=None):
            driven_by_other = model.get_value(itr, model.c_driven_by_other)
            cell.set_property('editable', not driven_by_other)
            cell.set_property(
                'style',
                Pango.Style.ITALIC if driven_by_other else Pango.Style.NORMAL)

        col = new_text_column('Name',
                              data_func=text_renderer,
                              editable=True,
                              edited_callback=(self.on_item_cell_edited,
                                               (model, model.c_name)),
                              resizable=False,
                              text_col=model.c_name)
        setattr(col, "col_descr", 'Name')
        tv.append_column(col)

        # Value of the relation:
        float_rend = create_float_data_func()

        def data_renderer(column, cell, model, itr, args=None):
            text_renderer(column, cell, model, itr, args)
            float_rend(column, cell, model, itr, args)

        col = new_text_column('Value',
                              data_func=data_renderer,
                              editable=True,
                              edited_callback=(self.on_item_cell_edited,
                                               (model, model.c_value)),
                              resizable=False,
                              text_col=model.c_value)
        setattr(col, "col_descr", 'Value')
        tv.append_column(col)

        # Up, down and edit arrows:
        def setup_image_button(image, colnr):
            col = new_pb_column(" ",
                                resizable=False,
                                expand=False,
                                stock_id=image)
            setattr(col, "col_descr", colnr)
            tv.append_column(col)

        setup_image_button("213-up-arrow", "Up")
        setup_image_button("212-down-arrow", "Down")
        setup_image_button("030-pencil", "Edit")
Exemplo n.º 4
0
    def _reset_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode='MULTIPLE', reset=True)
        tv.set_model(model)

        # Atom column:
        self.combo_model = self.model.create_prop_store()
        self.combo_model2 = Gtk.ListStore(str)
        for row in self.combo_model:
            self.combo_model2.append(row[2:3])

        def atom_renderer(column, cell, model, itr, *args):
            obj = model.get_value(itr, 0)
            if hasattr(obj, "name"):
                cell.set_property('text', obj.name)
            else:
                cell.set_property('text', '#NA#')

        tv.append_column(
            new_combo_column("Atoms",
                             data_func=atom_renderer,
                             changed_callback=self.on_atom_changed,
                             edited_callback=self.on_atom_edited,
                             xalign=0.0,
                             expand=False,
                             has_entry=False,
                             model=self.combo_model2,
                             text_column=0,
                             editable=True))

        # Content column:
        def on_float_edited(rend, path, new_text, col):
            itr = model.get_iter(path)
            try:
                model.set_value(itr, col, float(new_text))
            except ValueError:
                logger.exception("Invalid value entered ('%s')!" % new_text)
            return True

        tv.append_column(
            new_text_column('Default contents',
                            text_col=2,
                            xalign=0.0,
                            editable=True,
                            data_func=create_float_data_func(),
                            edited_callback=(on_float_edited, (2, ))))
    def _reset_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True)
        tv.set_model(model)

        # Name column:
        def text_renderer(column, cell, model, itr, args=None):
            driven_by_other = model.get_value(itr, model.c_driven_by_other)
            cell.set_property('editable', not driven_by_other)
            cell.set_property('style', pango.STYLE_ITALIC if driven_by_other else pango.STYLE_NORMAL)
        col = new_text_column(
            'Name',
            data_func=text_renderer,
            editable=True,
            edited_callback=(self.on_item_cell_edited, (model, model.c_name)),
            resizable=False,
            text_col=model.c_name)
        col.set_data("col_descr", 'Name')
        tv.append_column(col)

        # Value of the relation:
        float_rend = create_float_data_func()
        def data_renderer(column, cell, model, itr, args=None):
            text_renderer(column, cell, model, itr, args)
            float_rend(column, cell, model, itr, args)
        col = new_text_column(
            'Value',
            data_func=data_renderer,
            editable=True,
            edited_callback=(self.on_item_cell_edited, (model, model.c_value)),
            resizable=False,
            text_col=model.c_value)
        col.set_data("col_descr", 'Value')
        tv.append_column(col)

        # Up, down and edit arrows:
        def setup_image_button(image, colnr):
            col = new_pb_column(" ", resizable=False, expand=False, stock_id=image)
            col.set_data("col_descr", colnr)
            tv.append_column(col)
        setup_image_button("213-up-arrow", "Up")
        setup_image_button("212-down-arrow", "Down")
        setup_image_button("030-pencil", "Edit")