/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/treemodel.py

  • Committer: Mikkel Kamstrup Erlandsen
  • Date: 2011-09-28 07:45:39 UTC
  • mto: This revision was merged to the branch mainline in revision 740.
  • Revision ID: mikkel.kamstrup@gmail.com-20110928074539-qxl1yn1bkjel6ir0
Add X-GNOME-Autostart-Delay=30 to bzr-notify.desktop

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: UTF-8 -*-
2
 
"""BranchTreeModel."""
 
2
"""Tree model.
 
3
 
 
4
"""
3
5
 
4
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
5
 
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
6
 
 
7
 
 
8
 
from gi.repository import Gtk
9
 
from gi.repository import GObject
 
7
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
 
8
 
 
9
 
 
10
import gtk
 
11
import gobject
10
12
from xml.sax.saxutils import escape
11
13
 
12
14
from bzrlib.config import parse_username
17
19
    localtime,
18
20
    )
19
21
 
20
 
 
21
22
REVID = 0
22
23
NODE = 1
23
24
LINES = 2
33
34
TAGS = 12
34
35
AUTHORS = 13
35
36
 
36
 
 
37
 
class BranchTreeModel(Gtk.ListStore):
38
 
    """A model of branch's merge history."""
39
 
 
40
 
    def __init__(self, branch, line_graph_data):
41
 
        super(BranchTreeModel, self).__init__(
42
 
            GObject.TYPE_STRING,
43
 
            GObject.TYPE_PYOBJECT,
44
 
            GObject.TYPE_PYOBJECT,
45
 
            GObject.TYPE_PYOBJECT,
46
 
            GObject.TYPE_STRING,
47
 
            GObject.TYPE_STRING,
48
 
            GObject.TYPE_STRING,
49
 
            GObject.TYPE_STRING,
50
 
            GObject.TYPE_STRING,
51
 
            GObject.TYPE_PYOBJECT,
52
 
            GObject.TYPE_PYOBJECT,
53
 
            GObject.TYPE_PYOBJECT,
54
 
            GObject.TYPE_PYOBJECT,
55
 
            GObject.TYPE_STRING)
 
37
class TreeModel(gtk.GenericTreeModel):
 
38
 
 
39
    def __init__ (self, branch, line_graph_data):
 
40
        gtk.GenericTreeModel.__init__(self)
56
41
        self.revisions = {}
57
42
        self.branch = branch
58
43
        self.repository = branch.repository
 
44
        self.line_graph_data = line_graph_data
 
45
 
59
46
        if self.branch.supports_tags():
60
47
            self.tags = self.branch.tags.get_reverse_tag_dict()
61
48
        else:
62
49
            self.tags = {}
63
 
        self.set_line_graph_data(line_graph_data)
64
50
 
65
51
    def add_tag(self, tag, revid):
66
52
        self.branch.tags.set_tag(tag, revid)
69
55
        except KeyError:
70
56
            self.tags[revid] = [tag]
71
57
 
72
 
    def _line_graph_item_to_model_row(self, rowref, data):
73
 
        revid, node, lines, parents, children, revno_sequence = data
74
 
        if rowref > 0:
75
 
            last_lines = self.line_graph_data[rowref - 1][2]
 
58
    def on_get_flags(self):
 
59
        return gtk.TREE_MODEL_LIST_ONLY
 
60
 
 
61
    def on_get_n_columns(self):
 
62
        return 14
 
63
 
 
64
    def on_get_column_type(self, index):
 
65
        if index == REVID: return gobject.TYPE_STRING
 
66
        if index == NODE: return gobject.TYPE_PYOBJECT
 
67
        if index == LINES: return gobject.TYPE_PYOBJECT
 
68
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
 
69
        if index == REVNO: return gobject.TYPE_STRING
 
70
        if index == SUMMARY: return gobject.TYPE_STRING
 
71
        if index == MESSAGE: return gobject.TYPE_STRING
 
72
        if index == COMMITTER: return gobject.TYPE_STRING
 
73
        if index == TIMESTAMP: return gobject.TYPE_STRING
 
74
        if index == REVISION: return gobject.TYPE_PYOBJECT
 
75
        if index == PARENTS: return gobject.TYPE_PYOBJECT
 
76
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
 
77
        if index == TAGS: return gobject.TYPE_PYOBJECT
 
78
        if index == AUTHORS: return gobject.TYPE_STRING
 
79
 
 
80
    def on_get_iter(self, path):
 
81
        return path[0]
 
82
 
 
83
    def on_get_path(self, rowref):
 
84
        return rowref
 
85
 
 
86
    def on_get_value(self, rowref, column):
 
87
        if len(self.line_graph_data) > 0:
 
88
            (revid, node, lines, parents,
 
89
             children, revno_sequence) = self.line_graph_data[rowref]
76
90
        else:
77
 
            last_lines = []
78
 
        revno = ".".join(["%d" % (revno) for revno in revno_sequence])
79
 
        tags = self.tags.get(revid, [])
 
91
            (revid, node, lines, parents,
 
92
             children, revno_sequence) = (None, (0, 0), (), (),
 
93
                                          (), ())
 
94
        if column == REVID: return revid
 
95
        if column == NODE: return node
 
96
        if column == LINES: return lines
 
97
        if column == PARENTS: return parents
 
98
        if column == CHILDREN: return children
 
99
        if column == LAST_LINES:
 
100
            if rowref>0:
 
101
                return self.line_graph_data[rowref-1][2]
 
102
            return []
 
103
        if column == REVNO: return ".".join(["%d" % (revno)
 
104
                                      for revno in revno_sequence])
 
105
 
 
106
        if column == TAGS: return self.tags.get(revid, [])
 
107
 
80
108
        if not revid or revid == NULL_REVISION:
81
 
            revision = None
82
 
        elif revid not in self.revisions:
 
109
            return None
 
110
        if revid not in self.revisions:
83
111
            revision = self.repository.get_revisions([revid])[0]
84
112
            self.revisions[revid] = revision
85
113
        else:
86
114
            revision = self.revisions[revid]
87
 
        if revision is None:
88
 
            summary = message = committer = timestamp = authors = None
89
 
        else:
90
 
            summary = escape(revision.get_summary())
91
 
            message = escape(revision.message)
92
 
            committer = parse_username(revision.committer)[0]
93
 
            timestamp = strftime(
94
 
                "%Y-%m-%d %H:%M", localtime(revision.timestamp))
95
 
            authors = ", ".join([
96
 
                parse_username(author)[0]
97
 
                for author in revision.get_apparent_authors()])
98
 
        return (revid, node, lines, last_lines, revno, summary, message,
99
 
                committer, timestamp, revision, parents, children, tags,
100
 
                authors)
101
 
 
102
 
    def set_line_graph_data(self, line_graph_data):
103
 
        self.clear()
104
 
        self.line_graph_data = line_graph_data
105
 
        for rowref, data in enumerate(self.line_graph_data):
106
 
            row = self._line_graph_item_to_model_row(rowref, data)
107
 
            self.append(row)
 
115
 
 
116
        if column == REVISION: return revision
 
117
        if column == SUMMARY: return escape(revision.get_summary())
 
118
        if column == MESSAGE: return escape(revision.message)
 
119
        if column == COMMITTER: return parse_username(revision.committer)[0]
 
120
        if column == TIMESTAMP:
 
121
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
122
        if column == AUTHORS:
 
123
            return ", ".join([
 
124
                parse_username(author)[0] for author in revision.get_apparent_authors()])
 
125
 
 
126
    def on_iter_next(self, rowref):
 
127
        if rowref < len(self.line_graph_data) - 1:
 
128
            return rowref+1
 
129
        return None
 
130
 
 
131
    def on_iter_children(self, parent):
 
132
        if parent is None: return 0
 
133
        return None
 
134
 
 
135
    def on_iter_has_child(self, rowref):
 
136
        return False
 
137
 
 
138
    def on_iter_n_children(self, rowref):
 
139
        if rowref is None: return len(self.line_graph_data)
 
140
        return 0
 
141
 
 
142
    def on_iter_nth_child(self, parent, n):
 
143
        if parent is None: return n
 
144
        return None
 
145
 
 
146
    def on_iter_parent(self, child):
 
147
        return None