/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: 2012-02-05 05:14:11 UTC
  • mto: This revision was merged to the branch mainline in revision 775.
  • Revision ID: sinzui.is@verizon.net-20120205051411-y9ra08wae1wsfv52
Remove unneeded gtksourceview1 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: UTF-8 -*-
2
 
"""Tree model.
3
 
 
4
 
"""
 
2
"""BranchTreeModel."""
5
3
 
6
4
__copyright__ = "Copyright � 2005 Canonical Ltd."
7
 
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
8
 
 
9
 
 
10
 
import gtk
11
 
import gobject
12
 
import re
 
5
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
 
6
 
 
7
 
 
8
from gi.repository import Gtk
 
9
from gi.repository import GObject
13
10
from xml.sax.saxutils import escape
14
11
 
15
12
from bzrlib.config import parse_username
16
13
from bzrlib.revision import NULL_REVISION
17
14
 
18
 
from time import (strftime, localtime)
 
15
from time import (
 
16
    strftime,
 
17
    localtime,
 
18
    )
 
19
 
19
20
 
20
21
REVID = 0
21
22
NODE = 1
32
33
TAGS = 12
33
34
AUTHORS = 13
34
35
 
35
 
class TreeModel(gtk.GenericTreeModel):
36
 
 
37
 
    def __init__ (self, branch, line_graph_data):
38
 
        gtk.GenericTreeModel.__init__(self)
 
36
 
 
37
class BranchTreeModel(Gtk.ListStore):
 
38
    """A model of branch's merge history."""
 
39
 
 
40
    def __init__(self, branch, line_graph_data):
 
41
        super(BranchTreeModel, self).__init__(
 
42
            GObject.TYPE_STRING,
 
43
            GObject.TYPE_PYOBJECT,
 
44
            GObject.TYPE_PYOBJECT,
 
45
            GObject.TYPE_PYOBJECT,
 
46
            GObject.TYPE_STRING,
 
47
            GObject.TYPE_STRING,
 
48
            GObject.TYPE_STRING,
 
49
            GObject.TYPE_STRING,
 
50
            GObject.TYPE_STRING,
 
51
            GObject.TYPE_PYOBJECT,
 
52
            GObject.TYPE_PYOBJECT,
 
53
            GObject.TYPE_PYOBJECT,
 
54
            GObject.TYPE_PYOBJECT,
 
55
            GObject.TYPE_STRING)
39
56
        self.revisions = {}
40
57
        self.branch = branch
41
58
        self.repository = branch.repository
42
 
        self.line_graph_data = line_graph_data
43
 
 
44
59
        if self.branch.supports_tags():
45
60
            self.tags = self.branch.tags.get_reverse_tag_dict()
46
61
        else:
47
62
            self.tags = {}
 
63
        self.set_line_graph_data(line_graph_data)
48
64
 
49
65
    def add_tag(self, tag, revid):
50
66
        self.branch.tags.set_tag(tag, revid)
53
69
        except KeyError:
54
70
            self.tags[revid] = [tag]
55
71
 
56
 
    def on_get_flags(self):
57
 
        return gtk.TREE_MODEL_LIST_ONLY
58
 
 
59
 
    def on_get_n_columns(self):
60
 
        return 14
61
 
 
62
 
    def on_get_column_type(self, index):
63
 
        if index == REVID: return gobject.TYPE_STRING
64
 
        if index == NODE: return gobject.TYPE_PYOBJECT
65
 
        if index == LINES: return gobject.TYPE_PYOBJECT
66
 
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
67
 
        if index == REVNO: return gobject.TYPE_STRING
68
 
        if index == SUMMARY: return gobject.TYPE_STRING
69
 
        if index == MESSAGE: return gobject.TYPE_STRING
70
 
        if index == COMMITTER: return gobject.TYPE_STRING
71
 
        if index == TIMESTAMP: return gobject.TYPE_STRING
72
 
        if index == REVISION: return gobject.TYPE_PYOBJECT
73
 
        if index == PARENTS: return gobject.TYPE_PYOBJECT
74
 
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
75
 
        if index == TAGS: return gobject.TYPE_PYOBJECT
76
 
        if index == AUTHORS: return gobject.TYPE_STRING
77
 
 
78
 
    def on_get_iter(self, path):
79
 
        return path[0]
80
 
 
81
 
    def on_get_path(self, rowref):
82
 
        return rowref
83
 
 
84
 
    def on_get_value(self, rowref, column):
85
 
        if len(self.line_graph_data) > 0:
86
 
            (revid, node, lines, parents,
87
 
             children, revno_sequence) = self.line_graph_data[rowref]
 
72
    def _line_graph_item_to_model_row(self, rowref, data):
 
73
        revid, node, lines, parents, children, revno_sequence = data
 
74
        if rowref > 0:
 
75
            last_lines = self.line_graph_data[rowref - 1][2]
88
76
        else:
89
 
            (revid, node, lines, parents,
90
 
             children, revno_sequence) = (None, (0, 0), (), (),
91
 
                                          (), ())
92
 
        if column == REVID: return revid
93
 
        if column == NODE: return node
94
 
        if column == LINES: return lines
95
 
        if column == PARENTS: return parents
96
 
        if column == CHILDREN: return children
97
 
        if column == LAST_LINES:
98
 
            if rowref>0:
99
 
                return self.line_graph_data[rowref-1][2]
100
 
            return []
101
 
        if column == REVNO: return ".".join(["%d" % (revno)
102
 
                                      for revno in revno_sequence])
103
 
 
104
 
        if column == TAGS: return self.tags.get(revid, [])
105
 
 
 
77
            last_lines = []
 
78
        revno = ".".join(["%d" % (revno) for revno in revno_sequence])
 
79
        tags = self.tags.get(revid, [])
106
80
        if not revid or revid == NULL_REVISION:
107
 
            return None
108
 
        if revid not in self.revisions:
 
81
            revision = None
 
82
        elif revid not in self.revisions:
109
83
            revision = self.repository.get_revisions([revid])[0]
110
84
            self.revisions[revid] = revision
111
85
        else:
112
86
            revision = self.revisions[revid]
113
 
 
114
 
        if column == REVISION: return revision
115
 
        if column == SUMMARY: return escape(revision.get_summary())
116
 
        if column == MESSAGE: return escape(revision.message)
117
 
        if column == COMMITTER: return parse_username(revision.committer)[0]
118
 
        if column == TIMESTAMP:
119
 
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
120
 
        if column == AUTHORS:
121
 
            return ", ".join([
122
 
                parse_username(author)[0] for author in revision.get_apparent_authors()])
123
 
 
124
 
    def on_iter_next(self, rowref):
125
 
        if rowref < len(self.line_graph_data) - 1:
126
 
            return rowref+1
127
 
        return None
128
 
 
129
 
    def on_iter_children(self, parent):
130
 
        if parent is None: return 0
131
 
        return None
132
 
 
133
 
    def on_iter_has_child(self, rowref):
134
 
        return False
135
 
 
136
 
    def on_iter_n_children(self, rowref):
137
 
        if rowref is None: return len(self.line_graph_data)
138
 
        return 0
139
 
 
140
 
    def on_iter_nth_child(self, parent, n):
141
 
        if parent is None: return n
142
 
        return None
143
 
 
144
 
    def on_iter_parent(self, child):
145
 
        return None
 
87
        if revision is None:
 
88
            summary = message = committer = timestamp = authors = None
 
89
        else:
 
90
            summary = escape(revision.get_summary())
 
91
            message = escape(revision.message)
 
92
            committer = parse_username(revision.committer)[0]
 
93
            timestamp = strftime(
 
94
                "%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
95
            authors = ", ".join([
 
96
                parse_username(author)[0]
 
97
                for author in revision.get_apparent_authors()])
 
98
        return (revid, node, lines, last_lines, revno, summary, message,
 
99
                committer, timestamp, revision, parents, children, tags,
 
100
                authors)
 
101
 
 
102
    def set_line_graph_data(self, line_graph_data):
 
103
        self.clear()
 
104
        self.line_graph_data = line_graph_data
 
105
        for rowref, data in enumerate(self.line_graph_data):
 
106
            row = self._line_graph_item_to_model_row(rowref, data)
 
107
            self.append(row)