Ejemplo n.º 1
0
    def __init__(self, roots=[]):
        BaseTreeModel.__init__(self, roots)

        self.fades = set()

        # TODO: move to treeviewer
        # init default columns
        self.append_column(
            TreeModelColumn("icon",
                            gdk.Pixbuf,
                            get=lambda node: get_node_icon(
                                node, False, node in self.fades)))
        self.append_column(
            TreeModelColumn("icon_open",
                            gdk.Pixbuf,
                            get=lambda node: get_node_icon(
                                node, True, node in self.fades)))
        self.append_column(
            TreeModelColumn("title", str, get=lambda node: node.get_title()))
        self.append_column(
            TreeModelColumn("title_sort",
                            str,
                            attr="title",
                            get=lambda node: node.get_title().lower()))
        self.append_column(
            TreeModelColumn(
                "created_time",
                str,
                get=lambda node: self.get_time_text(node, "created_time")))
        self.append_column(
            TreeModelColumn("created_time_sort",
                            int,
                            attr="created_time",
                            get=lambda node: node.get_attr("created_time", 0)))
        self.append_column(
            TreeModelColumn(
                "modified_time",
                str,
                get=lambda node: self.get_time_text(node, "modified_time")))
        self.append_column(
            TreeModelColumn(
                "modified_time_sort",
                int,
                attr="modified_time",
                get=lambda node: node.get_attr("modified_time", 0)))
        self.append_column(
            TreeModelColumn("order",
                            int,
                            attr="order",
                            get=lambda node: node.get_attr("order")))
        self.append_column(
            TreeModelColumn("node", object, get=lambda node: node))

        self.set_node_column(self.get_column_by_name("node"))
Ejemplo n.º 2
0
    def on_tab_current_node(self, viewer, node):
        """Callback for when a viewer wants to set its title"""

        # get node title
        if node is None:
            if viewer.get_notebook():
                title = viewer.get_notebook().get_attr("title")
                icon = None
            else:
                title = _("(Untitled)")
                icon = None
        else:
            title = node.get_attr("title")
            icon = get_node_icon(node, expand=False)

        # truncate title
        MAX_TITLE = 20
        if len(title) > MAX_TITLE - 3:
            title = title[:MAX_TITLE - 3] + "..."

        # set tab label with node title
        tab = self._tabs.get_tab_label(viewer)
        if self._tab_names[viewer] is None:
            # only update tab title if it does not have a name already
            tab.set_text(title)
        tab.set_icon(icon)

        # propogate current-node signal
        self.emit("current-node", node)
Ejemplo n.º 3
0
    def on_tab_current_node(self, viewer, node):
        """Callback for when a viewer wants to set its title"""
        
        # get node title
        if node is None:
            if viewer.get_notebook():
                title = viewer.get_notebook().get_attr("title")
                icon = None
            else:
                title = _("(Untitled)")
                icon = None
        else:
            title = node.get_attr("title")
            icon = get_node_icon(node, expand=False)

        # truncate title
        MAX_TITLE = 20
        if len(title) > MAX_TITLE - 3:
            title = title[:MAX_TITLE-3] + "..."

        # set tab label with node title
        tab = self._tabs.get_tab_label(viewer)
        if self._tab_names[viewer] is None:
            # only update tab title if it does not have a name already
            tab.set_text(title)
        tab.set_icon(icon)
                
        # propogate current-node signal
        self.emit("current-node", node)
Ejemplo n.º 4
0
    def __init__(self, roots=[]):
        BaseTreeModel.__init__(self, roots)

        self.fades = set()


        # TODO: move to treeviewer
        # init default columns
        self.append_column(TreeModelColumn("icon", gdk.Pixbuf,
                            get=lambda node: get_node_icon(node, False,
                                                           node in self.fades)))
        self.append_column(
            TreeModelColumn("icon_open", gdk.Pixbuf,
                            get=lambda node: get_node_icon(node, True,
                                                           node in self.fades)))
        self.append_column(
            TreeModelColumn("title", str, get=lambda node: node.get_title()))
        self.append_column(
            TreeModelColumn("title_sort", str,
                            attr="title",
                            get=lambda node: node.get_title().lower()))
        self.append_column(
            TreeModelColumn("created_time", str,
                            get=lambda node: self.get_time_text(node,
                                                            "created_time")))
        self.append_column(
            TreeModelColumn("created_time_sort", int,
                            attr="created_time",
                            get=lambda node: node.get_attr("created_time", 0)))
        self.append_column(
            TreeModelColumn("modified_time", str,
                            get=lambda node: self.get_time_text(node,
                                                         "modified_time")))
        self.append_column(
            TreeModelColumn("modified_time_sort", int,
                            attr="modified_time",
                            get=lambda node: node.get_attr("modified_time", 0)))
        self.append_column(
            TreeModelColumn("order", int,
                            attr="order",
                            get=lambda node: node.get_attr("order")))
        self.append_column(TreeModelColumn("node", object,
                                           get=lambda node: node))


        self.set_node_column(self.get_column_by_name("node"))
Ejemplo n.º 5
0
    def _add_model_column(self, attr, add_sort=True, mapfunc=lambda x: x):
        
        # get attribute definition from notebook
        attr_def = self._notebook.attr_defs.get(attr)

        # get datatype
        if attr_def is not None:
            datatype = attr_def.datatype
            default = attr_def.default
        else:
            datatype = "string"
            default = ""
        

        # value fetching
        get = lambda node: mapfunc(node.get_attr(attr, default))

        # get coltype
        mapfunc_sort = lambda x: x
        if datatype == "string":
            coltype = str
            coltype_sort = str
            mapfunc_sort = lambda x: x.lower()
        elif datatype == "integer":
            coltype = int
            coltype_sort = int
        elif datatype == "float":
            coltype = float
            coltype_sort = float
        elif datatype == "timestamp":
            mapfunc = self.format_timestamp
            coltype = str
            coltype_sort = int
        else:
            coltype = str
            coltype_sort = str
        
        
        # builtin column types
        if attr == self._attr_icon:
            coltype = gdk.Pixbuf
            coltype_sort = None
            get = lambda node: get_node_icon(node, False,
                                             node in self.rich_model.fades)
        elif attr == self._attr_icon_open:
            coltype = gdk.Pixbuf
            coltype_sort = None
            get = lambda node: get_node_icon(node, True,
                                             node in self.rich_model.fades)


        # get/make model column
        col = self.rich_model.get_column_by_name(attr)
        if col is None:
            col = treemodel.TreeModelColumn(attr, coltype, attr=attr, get=get)
            self.rich_model.append_column(col)
        
        # define column sorting
        if add_sort and coltype_sort is not None:
            attr_sort = attr + "_sort"
            col = self.rich_model.get_column_by_name(attr_sort)
            if col is None:
                get_sort = lambda node: mapfunc_sort(
                    node.get_attr(attr, default))
                col = treemodel.TreeModelColumn(
                    attr_sort, coltype_sort, attr=attr, get=get_sort)
                self.rich_model.append_column(col)
Ejemplo n.º 6
0
    def _add_model_column(self, attr, add_sort=True, mapfunc=lambda x: x):

        # get attribute definition from notebook
        attr_def = self._notebook.attr_defs.get(attr)

        # get datatype
        if attr_def is not None:
            datatype = attr_def.datatype
            default = attr_def.default
        else:
            datatype = "string"
            default = ""

        # value fetching
        get = lambda node: mapfunc(node.get_attr(attr, default))

        # get coltype
        mapfunc_sort = lambda x: x
        if datatype == "string":
            coltype = str
            coltype_sort = str
            mapfunc_sort = lambda x: x.lower()
        elif datatype == "integer":
            coltype = int
            coltype_sort = int
        elif datatype == "float":
            coltype = float
            coltype_sort = float
        elif datatype == "timestamp":
            mapfunc = self.format_timestamp
            coltype = str
            coltype_sort = int
        else:
            coltype = str
            coltype_sort = str

        # builtin column types
        if attr == self._attr_icon:
            coltype = gdk.Pixbuf
            coltype_sort = None
            get = lambda node: get_node_icon(node, False,
                                             node in self.rich_model.fades)
        elif attr == self._attr_icon_open:
            coltype = gdk.Pixbuf
            coltype_sort = None
            get = lambda node: get_node_icon(node, True,
                                             node in self.rich_model.fades)

        # get/make model column
        col = self.rich_model.get_column_by_name(attr)
        if col is None:
            col = treemodel.TreeModelColumn(attr, coltype, attr=attr, get=get)
            self.rich_model.append_column(col)

        # define column sorting
        if add_sort and coltype_sort is not None:
            attr_sort = attr + "_sort"
            col = self.rich_model.get_column_by_name(attr_sort)
            if col is None:
                get_sort = lambda node: mapfunc_sort(
                    node.get_attr(attr, default))
                col = treemodel.TreeModelColumn(
                    attr_sort, coltype_sort, attr=attr, get=get_sort)
                self.rich_model.append_column(col)