/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: Jelmer Vernooij
  • Date: 2008-03-28 19:26:53 UTC
  • mto: (450.1.13 trunk)
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20080328192653-trzptkwahx1tulz9
Add module for preferences code.

Show diffs side-by-side

added added

removed removed

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