コード例 #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, ))))
コード例 #2
0
    def _setup_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True)
        tv.set_model(model)

        # Add Atom name, default z, calculated z and #:
        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=False,
                    text_col=colnr,
                )
            )

        add_text_col("Atom name", model.c_name, is_float=False)
        add_text_col("Def. Z (nm)", model.c_default_z)
        add_text_col("Calc. Z (nm)", model.c_z, editable=False)
        add_text_col("#", model.c_pn)

        # Add atom type column (combo box with atom types from pyxrd.project level):
        def atom_type_renderer(column, cell, model, itr, col=None):
            try:
                name = model.get_user_data_from_path(model.get_path(itr)).atom_type.name
            except:
                name = "#NA#"
            cell.set_property("text", name)
            return

        def adjust_combo(cell, editable, path, data=None):
            editable.set_wrap_width(10)

        tv.append_column(
            new_combo_column(
                "Element",
                data_func=(atom_type_renderer, (3,)),
                changed_callback=self.on_atom_type_changed,
                edited_callback=(self.on_atom_type_edited, (model,)),
                editing_started_callback=adjust_combo,
                model=self.atom_types_treemodel,
                text_column=self.atom_types_treemodel.c_name,
                editable=True,
                has_entry=True,
            )
        )
コード例 #3
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, ))))
コード例 #4
0
    def _setup_treeview(self, tv, model):
        setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True)
        tv.set_model(model)

        # Add Atom name, default z, calculated z and #:
        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=False,
                    text_col=colnr))

        add_text_col('Atom name', model.c_name, is_float=False)
        add_text_col('Def. Z (nm)', model.c_default_z)
        add_text_col('Calc. Z (nm)', model.c_z, editable=False)
        add_text_col('#', model.c_pn)

        # Add atom type column (combo box with atom types from pyxrd.project level):
        def atom_type_renderer(column, cell, model, itr, col=None):
            try:
                name = model.get_user_data_from_path(
                    model.get_path(itr)).atom_type.name
            except:
                name = '#NA#'
            cell.set_property('text', name)
            return

        def adjust_combo(cell, editable, path, data=None):
            editable.set_wrap_width(10)

        tv.append_column(
            new_combo_column("Element",
                             data_func=(atom_type_renderer, (3, )),
                             changed_callback=self.on_atom_type_changed,
                             edited_callback=(self.on_atom_type_edited,
                                              (model, )),
                             editing_started_callback=adjust_combo,
                             model=self.atom_types_treemodel,
                             text_column=self.atom_types_treemodel.c_name,
                             editable=True,
                             has_entry=True))