/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to branchview/treemodel.py

  • Committer: Curtis Hovey
  • Date: 2011-09-03 13:19:58 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110903131958-dvlxud881arul00m
Small performance improvement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
"""
5
5
 
6
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
 
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
 
8
 
 
9
 
 
10
from gi.repository import Gtk
 
11
from gi.repository import GObject
14
12
from xml.sax.saxutils import escape
 
13
 
 
14
from bzrlib.config import parse_username
15
15
from bzrlib.revision import NULL_REVISION
16
16
 
17
 
from time import (strftime, localtime)
 
17
from time import (
 
18
    strftime,
 
19
    localtime,
 
20
    )
18
21
 
19
22
REVID = 0
20
23
NODE = 1
29
32
PARENTS = 10
30
33
CHILDREN = 11
31
34
TAGS = 12
32
 
 
33
 
class TreeModel(gtk.GenericTreeModel):
34
 
 
35
 
    
36
 
    def __init__ (self, branch, line_graph_data):
37
 
        gtk.GenericTreeModel.__init__(self)
38
 
        self.revisions = {}
39
 
        self.branch = branch
40
 
        self.repository = branch.repository
41
 
        self.line_graph_data = line_graph_data
42
 
 
43
 
        if self.branch.supports_tags():
 
35
AUTHORS = 13
 
36
 
 
37
 
 
38
class BranchTreeModel(Gtk.TreeStore):
 
39
    """A model of branch's merge history."""
 
40
 
 
41
    def __init__(self, branch, line_graph_data):
 
42
        super(BranchTreeModel, self).__init__(
 
43
            GObject.TYPE_STRING,
 
44
            GObject.TYPE_PYOBJECT,
 
45
            GObject.TYPE_PYOBJECT,
 
46
            GObject.TYPE_PYOBJECT,
 
47
            GObject.TYPE_STRING,
 
48
            GObject.TYPE_STRING,
 
49
            GObject.TYPE_STRING,
 
50
            GObject.TYPE_STRING,
 
51
            GObject.TYPE_STRING,
 
52
            GObject.TYPE_PYOBJECT,
 
53
            GObject.TYPE_PYOBJECT,
 
54
            GObject.TYPE_PYOBJECT,
 
55
            GObject.TYPE_PYOBJECT,
 
56
            GObject.TYPE_STRING)
 
57
        self.revisions = {}
 
58
        self.branch = branch
 
59
        self.repository = branch.repository
 
60
        if self.branch.supports_tags():
 
61
            self.tags = self.branch.tags.get_reverse_tag_dict()
 
62
        else:
 
63
            self.tags = {}
 
64
        self.set_line_graph_data(line_graph_data)
 
65
 
 
66
    def add_tag(self, tag, revid):
 
67
        self.branch.tags.set_tag(tag, revid)
 
68
        try:
 
69
            self.tags[revid].append(tag)
 
70
        except KeyError:
 
71
            self.tags[revid] = [tag]
 
72
 
 
73
    def set_line_graph_data(self, line_graph_data):
 
74
        self.clear()
 
75
        self.line_graph_data = line_graph_data
 
76
        # (None, (0, 0), (), (), (), ())
 
77
        for rowref, data in enumerate(self.line_graph_data):
 
78
            revid, node, lines, parents, children, revno_sequence = data
 
79
            if rowref > 0:
 
80
                last_lines = self.line_graph_data[rowref - 1][2]
 
81
            else:
 
82
                last_lines = []
 
83
            revno = ".".join(["%d" % (revno) for revno in revno_sequence])
 
84
            tags = self.tags.get(revid, [])
 
85
            if not revid or revid == NULL_REVISION:
 
86
                revision = None
 
87
            elif revid not in self.revisions:
 
88
                revision = self.repository.get_revisions([revid])[0]
 
89
                self.revisions[revid] = revision
 
90
            else:
 
91
                revision = self.revisions[revid]
 
92
            if revision is None:
 
93
                summary = message = committer = timestamp = authors = None
 
94
            else:
 
95
                summary = escape(revision.get_summary())
 
96
                message = escape(revision.message)
 
97
                committer = parse_username(revision.committer)[0]
 
98
                timestamp = strftime(
 
99
                    "%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
100
                authors = ", ".join([
 
101
                    parse_username(author)[0]
 
102
                    for author in revision.get_apparent_authors()])
 
103
            self.append(
 
104
                None,
 
105
                (revid, node, lines, last_lines, revno, summary, message,
 
106
                committer, timestamp, revision, parents, children, tags,
 
107
                authors))
 
108
 
 
109
 
 
110
class TreeModel(Gtk.TreeStore):
 
111
 
 
112
    def __init__(self, branch, line_graph_data):
 
113
        Gtk.TreeStore.__init__(self)
 
114
        self.revisions = {}
 
115
        self.branch = branch
 
116
        self.repository = branch.repository
 
117
        self.line_graph_data = line_graph_data
 
118
 
 
119
        if self.branch.supports_tags():
44
120
            self.tags = self.branch.tags.get_reverse_tag_dict()
45
121
        else:
46
122
            self.tags = {}
53
129
            self.tags[revid] = [tag]
54
130
 
55
131
    def on_get_flags(self):
56
 
        return gtk.TREE_MODEL_LIST_ONLY
57
 
    
 
132
        return Gtk.TREE_MODEL_LIST_ONLY
 
133
 
58
134
    def on_get_n_columns(self):
59
 
        return 13
60
 
    
 
135
        return 14
 
136
 
61
137
    def on_get_column_type(self, index):
62
 
        if index == REVID: return gobject.TYPE_STRING
63
 
        if index == NODE: return gobject.TYPE_PYOBJECT
64
 
        if index == LINES: return gobject.TYPE_PYOBJECT
65
 
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
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
74
 
        if index == TAGS: return gobject.TYPE_PYOBJECT
75
 
        
 
138
        if index == REVID: return GObject.TYPE_STRING
 
139
        if index == NODE: return GObject.TYPE_PYOBJECT
 
140
        if index == LINES: return GObject.TYPE_PYOBJECT
 
141
        if index == LAST_LINES: return GObject.TYPE_PYOBJECT
 
142
        if index == REVNO: return GObject.TYPE_STRING
 
143
        if index == SUMMARY: return GObject.TYPE_STRING
 
144
        if index == MESSAGE: return GObject.TYPE_STRING
 
145
        if index == COMMITTER: return GObject.TYPE_STRING
 
146
        if index == TIMESTAMP: return GObject.TYPE_STRING
 
147
        if index == REVISION: return GObject.TYPE_PYOBJECT
 
148
        if index == PARENTS: return GObject.TYPE_PYOBJECT
 
149
        if index == CHILDREN: return GObject.TYPE_PYOBJECT
 
150
        if index == TAGS: return GObject.TYPE_PYOBJECT
 
151
        if index == AUTHORS: return GObject.TYPE_STRING
 
152
 
76
153
    def on_get_iter(self, path):
 
154
        # XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
77
155
        return path[0]
78
 
    
 
156
 
79
157
    def on_get_path(self, rowref):
80
158
        return rowref
81
 
    
 
159
 
82
160
    def on_get_value(self, rowref, column):
83
161
        if len(self.line_graph_data) > 0:
84
162
            (revid, node, lines, parents,
108
186
            self.revisions[revid] = revision
109
187
        else:
110
188
            revision = self.revisions[revid]
111
 
        
 
189
 
112
190
        if column == REVISION: return revision
113
191
        if column == SUMMARY: return escape(revision.get_summary())
114
192
        if column == MESSAGE: return escape(revision.message)
115
 
        if column == COMMITTER: return re.sub('<.*@.*>', '', 
116
 
                                             revision.committer).strip(' ')
117
 
        if column == TIMESTAMP: 
 
193
        if column == COMMITTER: return parse_username(revision.committer)[0]
 
194
        if column == TIMESTAMP:
118
195
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
196
        if column == AUTHORS:
 
197
            return ", ".join([
 
198
                parse_username(author)[0] for author in revision.get_apparent_authors()])
119
199
 
120
200
    def on_iter_next(self, rowref):
121
201
        if rowref < len(self.line_graph_data) - 1:
122
202
            return rowref+1
123
203
        return None
124
 
    
 
204
 
125
205
    def on_iter_children(self, parent):
126
206
        if parent is None: return 0
127
207
        return None
128
 
    
 
208
 
129
209
    def on_iter_has_child(self, rowref):
130
210
        return False
131
 
    
 
211
 
132
212
    def on_iter_n_children(self, rowref):
133
213
        if rowref is None: return len(self.line_graph_data)
134
214
        return 0
135
 
    
 
215
 
136
216
    def on_iter_nth_child(self, parent, n):
137
217
        if parent is None: return n
138
218
        return None
139
 
    
 
219
 
140
220
    def on_iter_parent(self, child):
141
221
        return None