/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
292.1.1 by Daniel Schierbeck
Removed email address from committer column in the revision history window.
12
import re
413 by Daniel Schierbeck
Made the treeview escape XML in the revision messages.
13
from xml.sax.saxutils import escape
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
14
15
from bzrlib.config import parse_username
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
16
from bzrlib.revision import NULL_REVISION
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
17
359 by Daniel Schierbeck
Simplified date format.
18
from time import (strftime, localtime)
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
19
423.4.6 by Daniel Schierbeck
Removed unnecessary spaces.
20
REVID = 0
21
NODE = 1
22
LINES = 2
23
LAST_LINES = 3
24
REVNO = 4
25
SUMMARY = 5
26
MESSAGE = 6
27
COMMITTER = 7
28
TIMESTAMP = 8
29
REVISION = 9
423.4.5 by Daniel Schierbeck
Fixed indendation issues.
30
PARENTS = 10
31
CHILDREN = 11
423.5.10 by Daniel Schierbeck
Merged with trunk.
32
TAGS = 12
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
33
AUTHORS = 13
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
34
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
35
class TreeModel(gtk.GenericTreeModel):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
36
423.5.1 by Ali Sabil
Added tags visualization in the graph
37
    def __init__ (self, branch, line_graph_data):
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
38
        gtk.GenericTreeModel.__init__(self)
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
39
        self.revisions = {}
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
40
        self.branch = branch
423.5.1 by Ali Sabil
Added tags visualization in the graph
41
        self.repository = branch.repository
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
42
        self.line_graph_data = line_graph_data
423.5.10 by Daniel Schierbeck
Merged with trunk.
43
713 by Jelmer Vernooij
Remove some unused imports, fix some formatting.
44
        if self.branch.supports_tags():
423.5.10 by Daniel Schierbeck
Merged with trunk.
45
            self.tags = self.branch.tags.get_reverse_tag_dict()
46
        else:
47
            self.tags = {}
423.7.6 by Daniel Schierbeck
Merged with trunk.
48
49
    def add_tag(self, tag, revid):
50
        self.branch.tags.set_tag(tag, revid)
51
        try:
52
            self.tags[revid].append(tag)
53
        except KeyError:
54
            self.tags[revid] = [tag]
55
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
56
    def on_get_flags(self):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
57
        return gtk.TREE_MODEL_LIST_ONLY
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
58
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
59
    def on_get_n_columns(self):
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
60
        return 14
61
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
62
    def on_get_column_type(self, index):
423.4.5 by Daniel Schierbeck
Fixed indendation issues.
63
        if index == REVID: return gobject.TYPE_STRING
64
        if index == NODE: return gobject.TYPE_PYOBJECT
65
        if index == LINES: return gobject.TYPE_PYOBJECT
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
66
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
423.4.5 by Daniel Schierbeck
Fixed indendation issues.
67
        if index == REVNO: return gobject.TYPE_STRING
68
        if index == SUMMARY: return gobject.TYPE_STRING
69
        if index == MESSAGE: return gobject.TYPE_STRING
70
        if index == COMMITTER: return gobject.TYPE_STRING
71
        if index == TIMESTAMP: return gobject.TYPE_STRING
72
        if index == REVISION: return gobject.TYPE_PYOBJECT
73
        if index == PARENTS: return gobject.TYPE_PYOBJECT
74
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
423.5.1 by Ali Sabil
Added tags visualization in the graph
75
        if index == TAGS: return gobject.TYPE_PYOBJECT
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
76
        if index == AUTHORS: return gobject.TYPE_STRING
77
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
78
    def on_get_iter(self, path):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
79
        return path[0]
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
80
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
81
    def on_get_path(self, rowref):
82
        return rowref
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_value(self, rowref, column):
421.1.1 by Gary van der Merwe
Make viz not throw errors when there are 0 commits.
85
        if len(self.line_graph_data) > 0:
86
            (revid, node, lines, parents,
87
             children, revno_sequence) = self.line_graph_data[rowref]
88
        else:
89
            (revid, node, lines, parents,
90
             children, revno_sequence) = (None, (0, 0), (), (),
91
                                          (), ())
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
92
        if column == REVID: return revid
93
        if column == NODE: return node
94
        if column == LINES: return lines
95
        if column == PARENTS: return parents
96
        if column == CHILDREN: return children
97
        if column == LAST_LINES:
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
98
            if rowref>0:
99
                return self.line_graph_data[rowref-1][2]
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
100
            return []
101
        if column == REVNO: return ".".join(["%d" % (revno)
102
                                      for revno in revno_sequence])
423.7.6 by Daniel Schierbeck
Merged with trunk.
103
423.5.10 by Daniel Schierbeck
Merged with trunk.
104
        if column == TAGS: return self.tags.get(revid, [])
423.5.1 by Ali Sabil
Added tags visualization in the graph
105
464.2.1 by Adrian Wilkins
Detect the reserved null: revision in appropriate places.
106
        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.
107
            return None
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
108
        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.
109
            revision = self.repository.get_revisions([revid])[0]
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
110
            self.revisions[revid] = revision
111
        else:
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
112
            revision = self.revisions[revid]
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
113
256.2.41 by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation.
114
        if column == REVISION: return revision
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
115
        if column == SUMMARY: return escape(revision.get_summary())
423.4.2 by Daniel Schierbeck
Added a MESSAGE column to the tree model.
116
        if column == MESSAGE: return escape(revision.message)
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
117
        if column == COMMITTER: return parse_username(revision.committer)[0]
118
        if column == TIMESTAMP:
359 by Daniel Schierbeck
Simplified date format.
119
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
120
        if column == AUTHORS:
121
            return ", ".join([
122
                parse_username(author)[0] for author in revision.get_apparent_authors()])
359 by Daniel Schierbeck
Simplified date format.
123
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
124
    def on_iter_next(self, rowref):
125
        if rowref < len(self.line_graph_data) - 1:
126
            return rowref+1
127
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
128
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
129
    def on_iter_children(self, parent):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
130
        if parent is None: return 0
131
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
132
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
133
    def on_iter_has_child(self, rowref):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
134
        return False
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_n_children(self, rowref):
137
        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.
138
        return 0
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
139
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
140
    def on_iter_nth_child(self, parent, n):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
141
        if parent is None: return n
142
        return None
713.1.1 by Jelmer Vernooij
'bzr viz' now shows authors instead of committers.
143
256.2.36 by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node
144
    def on_iter_parent(self, child):
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
145
        return None