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 |
|
12 |
import pango |
|
292.1.1
by Daniel Schierbeck
Removed email address from committer column in the revision history window. |
13 |
import re |
413
by Daniel Schierbeck
Made the treeview escape XML in the revision messages. |
14 |
from xml.sax.saxutils import escape |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
15 |
|
359
by Daniel Schierbeck
Simplified date format. |
16 |
from time import (strftime, localtime) |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
17 |
|
18 |
REVID = 0 |
|
19 |
NODE = 1 |
|
20 |
LINES = 2 |
|
21 |
LAST_LINES = 3 |
|
22 |
REVNO = 4 |
|
23 |
MESSAGE = 5 |
|
24 |
COMMITER = 6 |
|
25 |
TIMESTAMP = 7 |
|
26 |
REVISION = 8 |
|
27 |
PARENTS = 9 |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
28 |
CHILDREN = 10 |
29 |
TAGS = 11 |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
30 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
31 |
class TreeModel(gtk.GenericTreeModel): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
32 |
|
33 |
||
423.5.1
by Ali Sabil
Added tags visualization in the graph |
34 |
def __init__ (self, branch, line_graph_data): |
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
35 |
gtk.GenericTreeModel.__init__(self) |
423.5.1
by Ali Sabil
Added tags visualization in the graph |
36 |
self.revisions = {} |
37 |
self.branch = branch |
|
38 |
self.repository = branch.repository |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
39 |
self.line_graph_data = line_graph_data |
423.5.8
by Daniel Schierbeck
Improved tag handling in branchview model. |
40 |
|
41 |
if self.branch.supports_tags(): |
|
42 |
self.tags = self.branch.tags.get_reverse_tag_dict() |
|
43 |
else: |
|
44 |
self.tags = {} |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
45 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
46 |
def on_get_flags(self): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
47 |
return gtk.TREE_MODEL_LIST_ONLY |
48 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
49 |
def on_get_n_columns(self): |
423.5.1
by Ali Sabil
Added tags visualization in the graph |
50 |
return 12 |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
51 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
52 |
def on_get_column_type(self, index): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
53 |
if index == REVID: return gobject.TYPE_STRING |
54 |
if index == NODE: return gobject.TYPE_PYOBJECT |
|
55 |
if index == LINES: return gobject.TYPE_PYOBJECT |
|
56 |
if index == LAST_LINES: return gobject.TYPE_PYOBJECT |
|
57 |
if index == REVNO: return gobject.TYPE_STRING |
|
58 |
if index == MESSAGE: return gobject.TYPE_STRING |
|
59 |
if index == COMMITER: return gobject.TYPE_STRING |
|
60 |
if index == TIMESTAMP: return gobject.TYPE_STRING |
|
61 |
if index == REVISION: return gobject.TYPE_PYOBJECT |
|
62 |
if index == PARENTS: return gobject.TYPE_PYOBJECT |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
63 |
if index == CHILDREN: return gobject.TYPE_PYOBJECT |
64 |
if index == TAGS: return gobject.TYPE_PYOBJECT |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
65 |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
66 |
def on_get_iter(self, path): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
67 |
return path[0] |
68 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
69 |
def on_get_path(self, rowref): |
70 |
return rowref |
|
71 |
||
72 |
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. |
73 |
if len(self.line_graph_data) > 0: |
74 |
(revid, node, lines, parents, |
|
75 |
children, revno_sequence) = self.line_graph_data[rowref] |
|
76 |
else: |
|
77 |
(revid, node, lines, parents, |
|
78 |
children, revno_sequence) = (None, (0, 0), (), (), |
|
79 |
(), ()) |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
80 |
if column == REVID: return revid |
81 |
if column == NODE: return node |
|
82 |
if column == LINES: return lines |
|
83 |
if column == PARENTS: return parents |
|
84 |
if column == CHILDREN: return children |
|
85 |
if column == LAST_LINES: |
|
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
86 |
if rowref>0: |
87 |
return self.line_graph_data[rowref-1][2] |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
88 |
return [] |
89 |
if column == REVNO: return ".".join(["%d" % (revno) |
|
90 |
for revno in revno_sequence]) |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
91 |
|
423.5.8
by Daniel Schierbeck
Improved tag handling in branchview model. |
92 |
if column == TAGS: return self.tags.get(revid, []) |
423.5.1
by Ali Sabil
Added tags visualization in the graph |
93 |
|
421.1.1
by Gary van der Merwe
Make viz not throw errors when there are 0 commits. |
94 |
if revid is None: |
95 |
return None |
|
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
96 |
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. |
97 |
revision = self.repository.get_revisions([revid])[0] |
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
98 |
self.revisions[revid] = revision |
99 |
else: |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
100 |
revision = self.revisions[revid] |
256.2.41
by Gary van der Merwe
Revert GTKTreeModel on_ref_node implementation. |
101 |
|
102 |
if column == REVISION: return revision |
|
414
by Daniel Schierbeck
Switched to using Revision.get_summary() to get the first line of a revision's log message instead of home brewn code. |
103 |
if column == MESSAGE: return escape(revision.get_summary()) |
292.1.1
by Daniel Schierbeck
Removed email address from committer column in the revision history window. |
104 |
if column == COMMITER: return re.sub('<.*@.*>', '', |
105 |
revision.committer).strip(' ') |
|
359
by Daniel Schierbeck
Simplified date format. |
106 |
if column == TIMESTAMP: |
107 |
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp)) |
|
108 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
109 |
def on_iter_next(self, rowref): |
110 |
if rowref < len(self.line_graph_data) - 1: |
|
111 |
return rowref+1 |
|
112 |
return None |
|
113 |
||
114 |
def on_iter_children(self, parent): |
|
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
115 |
if parent is None: return 0 |
116 |
return None |
|
117 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
118 |
def on_iter_has_child(self, rowref): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
119 |
return False |
120 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
121 |
def on_iter_n_children(self, rowref): |
122 |
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. |
123 |
return 0 |
124 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
125 |
def on_iter_nth_child(self, parent, n): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
126 |
if parent is None: return n |
127 |
return None |
|
128 |
||
256.2.36
by Gary van der Merwe
Revert back to GenericTreeModel and implement on_ref_node |
129 |
def on_iter_parent(self, child): |
256.2.29
by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly. |
130 |
return None |