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 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
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): |
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
40 |
gtk.GenericTreeModel.__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): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
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): |
423.4.5
by Daniel Schierbeck
Fixed indendation issues. |
65 |
if index == REVID: return gobject.TYPE_STRING |
66 |
if index == NODE: return gobject.TYPE_PYOBJECT |
|
67 |
if index == LINES: return gobject.TYPE_PYOBJECT |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
68 |
if index == LAST_LINES: return gobject.TYPE_PYOBJECT |
423.4.5
by Daniel Schierbeck
Fixed indendation issues. |
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 |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
77 |
if index == TAGS: return gobject.TYPE_PYOBJECT |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
78 |
if index == AUTHORS: return gobject.TYPE_STRING |
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): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
81 |
return path[0] |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
82 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
83 |
def on_get_path(self, rowref): |
84 |
return rowref |
|
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
85 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
86 |
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. |
87 |
if len(self.line_graph_data) > 0: |
88 |
(revid, node, lines, parents, |
|
89 |
children, revno_sequence) = self.line_graph_data[rowref] |
|
90 |
else: |
|
91 |
(revid, node, lines, parents, |
|
92 |
children, revno_sequence) = (None, (0, 0), (), (), |
|
93 |
(), ()) |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
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: |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
100 |
if rowref>0: |
101 |
return self.line_graph_data[rowref-1][2] |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
102 |
return [] |
103 |
if column == REVNO: return ".".join(["%d" % (revno) |
|
104 |
for revno in revno_sequence]) |
|
423.7.6
by Daniel Schierbeck
Merged with trunk. |
105 |
|
423.5.10
by Daniel Schierbeck
Merged with trunk. |
106 |
if column == TAGS: return self.tags.get(revid, []) |
423.5.1
by Ali Sabil
Added tags visualization in the graph |
107 |
|
464.2.1
by Adrian Wilkins
Detect the reserved null: revision in appropriate places. |
108 |
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. |
109 |
return None |
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
110 |
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. |
111 |
revision = self.repository.get_revisions([revid])[0] |
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
112 |
self.revisions[revid] = revision |
113 |
else: |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
114 |
revision = self.revisions[revid] |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
115 |
|
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
116 |
if column == REVISION: return revision |
423.4.1
by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY. |
117 |
if column == SUMMARY: return escape(revision.get_summary()) |
423.4.2
by Daniel Schierbeck
Added a MESSAGE column to the tree model. |
118 |
if column == MESSAGE: return escape(revision.message) |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
119 |
if column == COMMITTER: return parse_username(revision.committer)[0] |
120 |
if column == TIMESTAMP: |
|
359
by Daniel Schierbeck
Simplified date format. |
121 |
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp)) |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
122 |
if column == AUTHORS: |
123 |
return ", ".join([ |
|
124 |
parse_username(author)[0] for author in revision.get_apparent_authors()]) |
|
359
by Daniel Schierbeck
Simplified date format. |
125 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
126 |
def on_iter_next(self, rowref): |
127 |
if rowref < len(self.line_graph_data) - 1: |
|
128 |
return rowref+1 |
|
129 |
return None |
|
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
130 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
131 |
def on_iter_children(self, parent): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
132 |
if parent is None: return 0 |
133 |
return None |
|
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
134 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
135 |
def on_iter_has_child(self, rowref): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
136 |
return False |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
137 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
138 |
def on_iter_n_children(self, rowref): |
139 |
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. |
140 |
return 0 |
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
141 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
142 |
def on_iter_nth_child(self, parent, n): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
143 |
if parent is None: return n |
144 |
return None |
|
713.1.1
by Jelmer Vernooij
'bzr viz' now shows authors instead of committers. |
145 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
146 |
def on_iter_parent(self, child): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
147 |
return None |