/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
1
# -*- coding: UTF-8 -*-
2
"""Tree model.
3
4
"""
5
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
8
9
10
import gtk
11
import gobject
413 by Daniel Schierbeck
Made the treeview escape XML in the revision messages.
12
from xml.sax.saxutils import escape
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
13
14
from bzrlib.config import parse_username
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
15
from bzrlib.revision import NULL_REVISION
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
16
724 by Jelmer Vernooij
Fix formatting, imports.
17
from time import (
18
    strftime,
19
    localtime,
20
    )
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
21
423.4.6 by Daniel Schierbeck
Removed unnecessary spaces.
22
REVID = 0
23
NODE = 1
24
LINES = 2
25
LAST_LINES = 3
26
REVNO = 4
27
SUMMARY = 5
28
MESSAGE = 6
29
COMMITTER = 7
30
TIMESTAMP = 8
31
REVISION = 9
423.4.5 by Daniel Schierbeck
Fixed indendation issues.
32
PARENTS = 10
33
CHILDREN = 11
423.5.10 by Daniel Schierbeck
Merged with trunk.
34
TAGS = 12
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
35
AUTHORS = 13
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
36
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
37
class TreeModel(Gtk.GenericTreeModel):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
38
423.5.1 by Ali Sabil
Added tags visualization in the graph
39
    def __init__ (self, branch, line_graph_data):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
40
        GObject.GObject.__init__(self)
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
41
        self.revisions = {}
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
42
        self.branch = branch
423.5.1 by Ali Sabil
Added tags visualization in the graph
43
        self.repository = branch.repository
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
44
        self.line_graph_data = line_graph_data
423.5.10 by Daniel Schierbeck
Merged with trunk.
45
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
46
        if self.branch.supports_tags():
423.5.10 by Daniel Schierbeck
Merged with trunk.
47
            self.tags = self.branch.tags.get_reverse_tag_dict()
48
        else:
49
            self.tags = {}
423.7.6 by Daniel Schierbeck
Merged with trunk.
50
51
    def add_tag(self, tag, revid):
52
        self.branch.tags.set_tag(tag, revid)
53
        try:
54
            self.tags[revid].append(tag)
55
        except KeyError:
56
            self.tags[revid] = [tag]
57
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
58
    def on_get_flags(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
59
        return Gtk.TREE_MODEL_LIST_ONLY
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
60
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
61
    def on_get_n_columns(self):
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
62
        return 14
63
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
64
    def on_get_column_type(self, index):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
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
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
79
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
80
    def on_get_iter(self, path):
734.1.12 by Curtis Hovey
Fixed row/path issues in gannoate.
81
        # XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
82
        return path[0]
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
83
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
84
    def on_get_path(self, rowref):
85
        return rowref
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
86
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
87
    def on_get_value(self, rowref, column):
421.1.1 by Gary van der Merwe
Make viz not throw errors when there are 0 commits.
88
        if len(self.line_graph_data) > 0:
89
            (revid, node, lines, parents,
90
             children, revno_sequence) = self.line_graph_data[rowref]
91
        else:
92
            (revid, node, lines, parents,
93
             children, revno_sequence) = (None, (0, 0), (), (),
94
                                          (), ())
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
95
        if column == REVID: return revid
96
        if column == NODE: return node
97
        if column == LINES: return lines
98
        if column == PARENTS: return parents
99
        if column == CHILDREN: return children
100
        if column == LAST_LINES:
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
101
            if rowref>0:
102
                return self.line_graph_data[rowref-1][2]
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
103
            return []
104
        if column == REVNO: return ".".join(["%d" % (revno)
105
                                      for revno in revno_sequence])
423.7.6 by Daniel Schierbeck
Merged with trunk.
106
423.5.10 by Daniel Schierbeck
Merged with trunk.
107
        if column == TAGS: return self.tags.get(revid, [])
423.5.1 by Ali Sabil
Added tags visualization in the graph
108
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
109
        if not revid or revid == NULL_REVISION:
421.1.1 by Gary van der Merwe
Make viz not throw errors when there are 0 commits.
110
            return None
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
111
        if revid not in self.revisions:
328 by Jelmer Vernooij
Use repository instead of branch in more places, to make it easier to support multiple branches in viz.
112
            revision = self.repository.get_revisions([revid])[0]
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
113
            self.revisions[revid] = revision
114
        else:
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
115
            revision = self.revisions[revid]
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
116
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
117
        if column == REVISION: return revision
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
118
        if column == SUMMARY: return escape(revision.get_summary())
423.4.2 by Daniel Schierbeck
Added a MESSAGE column to the tree model.
119
        if column == MESSAGE: return escape(revision.message)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
120
        if column == COMMITTER: return parse_username(revision.committer)[0]
121
        if column == TIMESTAMP:
359 by Daniel Schierbeck
Simplified date format.
122
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
123
        if column == AUTHORS:
124
            return ", ".join([
125
                parse_username(author)[0] for author in revision.get_apparent_authors()])
359 by Daniel Schierbeck
Simplified date format.
126
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
127
    def on_iter_next(self, rowref):
128
        if rowref < len(self.line_graph_data) - 1:
129
            return rowref+1
130
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
131
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
132
    def on_iter_children(self, parent):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
133
        if parent is None: return 0
134
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
135
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
136
    def on_iter_has_child(self, rowref):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
137
        return False
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
138
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
139
    def on_iter_n_children(self, rowref):
140
        if rowref is None: return len(self.line_graph_data)
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
141
        return 0
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
142
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
143
    def on_iter_nth_child(self, parent, n):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
144
        if parent is None: return n
145
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
146
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
147
    def on_iter_parent(self, child):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
148
        return None