/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: Curtis Hovey
  • Date: 2011-09-03 01:29:14 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110903012914-f36lv9j6ydblvbin
A quick spike to verify that subclassing TreeStore is easier than
implementing a TreeIter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
 
6
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
7
 
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
 
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
8
8
 
9
9
 
10
10
from gi.repository import Gtk
34
34
TAGS = 12
35
35
AUTHORS = 13
36
36
 
 
37
 
 
38
class BranchTreeModel(Gtk.TreeStore):
 
39
    """A model of branch's merge history."""
 
40
 
 
41
    def __init__(self, branch, line_graph_data):
 
42
        super(BranchTreeModel, self).__init__()
 
43
        self.revisions = {}
 
44
        self.branch = branch
 
45
        self.repository = branch.repository
 
46
        self.line_graph_data = line_graph_data
 
47
 
 
48
        if self.branch.supports_tags():
 
49
            self.tags = self.branch.tags.get_reverse_tag_dict()
 
50
        else:
 
51
            self.tags = {}
 
52
        self.set_column_types(
 
53
            (GObject.TYPE_STRING,
 
54
             GObject.TYPE_PYOBJECT,
 
55
             GObject.TYPE_PYOBJECT,
 
56
             GObject.TYPE_PYOBJECT,
 
57
             GObject.TYPE_STRING,
 
58
             GObject.TYPE_STRING,
 
59
             GObject.TYPE_STRING,
 
60
             GObject.TYPE_STRING,
 
61
             GObject.TYPE_STRING,
 
62
             GObject.TYPE_PYOBJECT,
 
63
             GObject.TYPE_PYOBJECT,
 
64
             GObject.TYPE_PYOBJECT,
 
65
             GObject.TYPE_PYOBJECT,
 
66
             GObject.TYPE_STRING))
 
67
 
 
68
    def add_tag(self, tag, revid):
 
69
        self.branch.tags.set_tag(tag, revid)
 
70
        try:
 
71
            self.tags[revid].append(tag)
 
72
        except KeyError:
 
73
            self.tags[revid] = [tag]
 
74
 
 
75
    def set_line_graph_data(self, line_graph_data):
 
76
        self.clear()
 
77
        self.line_graph_data = line_graph_data
 
78
        # (None, (0, 0), (), (), (), ())
 
79
        for rowref, data in enumerate(self.line_graph_data):
 
80
            revid, node, lines, parents, children, revno_sequence = data
 
81
            if rowref > 0:
 
82
                last_lines = self.line_graph_data[rowref - 1][2]
 
83
            else:
 
84
                last_lines = []
 
85
            revno = ".".join(["%d" % (revno) for revno in revno_sequence])
 
86
            tags = self.tags.get(revid, [])
 
87
            if not revid or revid == NULL_REVISION:
 
88
                revision = None
 
89
            elif revid not in self.revisions:
 
90
                revision = self.repository.get_revisions([revid])[0]
 
91
                self.revisions[revid] = revision
 
92
            else:
 
93
                revision = self.revisions[revid]
 
94
            if revision is None:
 
95
                summary = message = committer = timestamp = authors = None
 
96
            else:
 
97
                summary = escape(revision.get_summary())
 
98
                message = escape(revision.message)
 
99
                committer = parse_username(revision.committer)[0]
 
100
                timestamp = strftime(
 
101
                    "%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
102
                authors = ", ".join([
 
103
                    parse_username(author)[0]
 
104
                    for author in revision.get_apparent_authors()])
 
105
            self.append(
 
106
                None,
 
107
                (revid, node, lines, last_lines, revno, summary, message,
 
108
                committer, timestamp, revision, parents, children, tags,
 
109
                authors))
 
110
 
 
111
 
37
112
class TreeModel(Gtk.TreeStore):
38
113
 
39
 
    def __init__ (self, branch, line_graph_data):
 
114
    def __init__(self, branch, line_graph_data):
40
115
        Gtk.TreeStore.__init__(self)
41
116
        self.revisions = {}
42
117
        self.branch = branch