bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
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 |
|
13 |
import re |
|
14 |
from xml.sax.saxutils import escape |
|
15 |
||
16 |
from time import (strftime, localtime) |
|
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 |
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
29 |
TAGS = 11 |
30 |
||
31 |
class TreeModel(gtk.GenericTreeModel): |
|
32 |
||
33 |
||
34 |
def __init__ (self, branch, line_graph_data): |
|
35 |
gtk.GenericTreeModel.__init__(self) |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
36 |
self.revisions = {} |
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
37 |
self.branch = branch |
38 |
self.repository = branch.repository |
|
39 |
self.line_graph_data = line_graph_data |
|
423.7.2
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 = {} |
|
423.7.3
by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel. |
45 |
|
46 |
def add_tag(self, tag, revid): |
|
47 |
self.branch.tags.set_tag(tag, revid) |
|
48 |
try: |
|
49 |
self.tags[revid].append(tag) |
|
50 |
except KeyError: |
|
51 |
self.tags[revid] = [tag] |
|
52 |
||
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
53 |
def on_get_flags(self): |
54 |
return gtk.TREE_MODEL_LIST_ONLY |
|
55 |
||
56 |
def on_get_n_columns(self): |
|
57 |
return 12 |
|
58 |
||
59 |
def on_get_column_type(self, index): |
|
60 |
if index == REVID: return gobject.TYPE_STRING |
|
61 |
if index == NODE: return gobject.TYPE_PYOBJECT |
|
62 |
if index == LINES: return gobject.TYPE_PYOBJECT |
|
63 |
if index == LAST_LINES: return gobject.TYPE_PYOBJECT |
|
64 |
if index == REVNO: return gobject.TYPE_STRING |
|
65 |
if index == MESSAGE: return gobject.TYPE_STRING |
|
66 |
if index == COMMITER: return gobject.TYPE_STRING |
|
67 |
if index == TIMESTAMP: return gobject.TYPE_STRING |
|
68 |
if index == REVISION: return gobject.TYPE_PYOBJECT |
|
69 |
if index == PARENTS: return gobject.TYPE_PYOBJECT |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
70 |
if index == CHILDREN: return gobject.TYPE_PYOBJECT |
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
71 |
if index == TAGS: return gobject.TYPE_PYOBJECT |
72 |
||
73 |
def on_get_iter(self, path): |
|
74 |
return path[0] |
|
75 |
||
76 |
def on_get_path(self, rowref): |
|
77 |
return rowref |
|
78 |
||
79 |
def on_get_value(self, rowref, column): |
|
80 |
if len(self.line_graph_data) > 0: |
|
81 |
(revid, node, lines, parents, |
|
82 |
children, revno_sequence) = self.line_graph_data[rowref] |
|
83 |
else: |
|
84 |
(revid, node, lines, parents, |
|
85 |
children, revno_sequence) = (None, (0, 0), (), (), |
|
86 |
(), ()) |
|
87 |
if column == REVID: return revid |
|
88 |
if column == NODE: return node |
|
89 |
if column == LINES: return lines |
|
90 |
if column == PARENTS: return parents |
|
91 |
if column == CHILDREN: return children |
|
92 |
if column == LAST_LINES: |
|
93 |
if rowref>0: |
|
94 |
return self.line_graph_data[rowref-1][2] |
|
95 |
return [] |
|
96 |
if column == REVNO: return ".".join(["%d" % (revno) |
|
97 |
for revno in revno_sequence]) |
|
423.5.1
by Ali Sabil
Added tags visualization in the graph |
98 |
|
423.7.2
by Daniel Schierbeck
Improved tag handling in branchview model. |
99 |
if column == TAGS: return self.tags.get(revid, []) |
423.7.1
by Daniel Schierbeck
Removed end-of-line markers. |
100 |
|
101 |
if revid is None: |
|
102 |
return None |
|
103 |
if revid not in self.revisions: |
|
104 |
revision = self.repository.get_revisions([revid])[0] |
|
105 |
self.revisions[revid] = revision |
|
106 |
else: |
|
107 |
revision = self.revisions[revid] |
|
108 |
||
109 |
if column == REVISION: return revision |
|
110 |
if column == MESSAGE: return escape(revision.get_summary()) |
|
111 |
if column == COMMITER: return re.sub('<.*@.*>', '', |
|
112 |
revision.committer).strip(' ') |
|
113 |
if column == TIMESTAMP: |
|
114 |
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp)) |
|
115 |
||
116 |
def on_iter_next(self, rowref): |
|
117 |
if rowref < len(self.line_graph_data) - 1: |
|
118 |
return rowref+1 |
|
119 |
return None |
|
120 |
||
121 |
def on_iter_children(self, parent): |
|
122 |
if parent is None: return 0 |
|
123 |
return None |
|
124 |
||
125 |
def on_iter_has_child(self, rowref): |
|
126 |
return False |
|
127 |
||
128 |
def on_iter_n_children(self, rowref): |
|
129 |
if rowref is None: return len(self.line_graph_data) |
|
130 |
return 0 |
|
131 |
||
132 |
def on_iter_nth_child(self, parent, n): |
|
133 |
if parent is None: return n |
|
134 |
return None |
|
135 |
||
136 |
def on_iter_parent(self, child): |
|
137 |
return None |