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