/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 viz/treemodel.py

  • Committer: John Arbash Meinel
  • Date: 2007-10-02 23:08:12 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002230812-h8i6pq8fwvodute4
Start testing with Unicode data.
It seems there is some brokenness with serializing Unicode messages.
But otherwise everything seems to be working.

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
10
 
from xml.sax.saxutils import escape
11
 
 
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
 
 
 
7
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
 
8
 
 
9
 
 
10
import gtk
 
11
import gobject
 
12
import pango
 
13
 
 
14
from bzrlib.osutils import format_date
20
15
 
21
16
REVID = 0
22
17
NODE = 1
23
18
LINES = 2
24
19
LAST_LINES = 3
25
20
REVNO = 4
26
 
SUMMARY = 5
27
 
MESSAGE = 6
28
 
COMMITTER = 7
29
 
TIMESTAMP = 8
30
 
REVISION = 9
31
 
PARENTS = 10
32
 
CHILDREN = 11
33
 
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)
 
21
MESSAGE = 5
 
22
COMMITER = 6
 
23
TIMESTAMP = 7
 
24
REVISION = 8
 
25
PARENTS = 9
 
26
CHILDREN = 10
 
27
 
 
28
class TreeModel(gtk.GenericTreeModel):
 
29
 
 
30
    
 
31
    def __init__ (self, branch, line_graph_data):
 
32
        gtk.GenericTreeModel.__init__(self)
56
33
        self.revisions = {}
57
34
        self.branch = branch
58
 
        self.repository = branch.repository
59
 
        if self.branch.supports_tags():
60
 
            self.tags = self.branch.tags.get_reverse_tag_dict()
61
 
        else:
62
 
            self.tags = {}
63
 
        self.set_line_graph_data(line_graph_data)
64
 
 
65
 
    def add_tag(self, tag, revid):
66
 
        self.branch.tags.set_tag(tag, revid)
67
 
        try:
68
 
            self.tags[revid].append(tag)
69
 
        except KeyError:
70
 
            self.tags[revid] = [tag]
71
 
 
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]
76
 
        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:
83
 
            revision = self.repository.get_revisions([revid])[0]
 
35
        self.line_graph_data = line_graph_data
 
36
    
 
37
    def on_get_flags(self):
 
38
        return gtk.TREE_MODEL_LIST_ONLY
 
39
    
 
40
    def on_get_n_columns(self):
 
41
        return 11
 
42
    
 
43
    def on_get_column_type(self, index):
 
44
        if index == REVID: return gobject.TYPE_STRING
 
45
        if index == NODE: return gobject.TYPE_PYOBJECT
 
46
        if index == LINES: return gobject.TYPE_PYOBJECT
 
47
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
 
48
        if index == REVNO: return gobject.TYPE_STRING
 
49
        if index == MESSAGE: return gobject.TYPE_STRING
 
50
        if index == COMMITER: return gobject.TYPE_STRING
 
51
        if index == TIMESTAMP: return gobject.TYPE_STRING
 
52
        if index == REVISION: return gobject.TYPE_PYOBJECT
 
53
        if index == PARENTS: return gobject.TYPE_PYOBJECT
 
54
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
 
55
        
 
56
    def on_get_iter(self, path):
 
57
        return path[0]
 
58
    
 
59
    def on_get_path(self, rowref):
 
60
        return rowref
 
61
    
 
62
    def on_get_value(self, rowref, column):
 
63
        (revid, node, lines, parents,
 
64
         children, revno_sequence) = self.line_graph_data[rowref]
 
65
        if column == REVID: return revid
 
66
        if column == NODE: return node
 
67
        if column == LINES: return lines
 
68
        if column == PARENTS: return parents
 
69
        if column == CHILDREN: return children
 
70
        if column == LAST_LINES:
 
71
            if rowref>0:
 
72
                return self.line_graph_data[rowref-1][2]
 
73
            return []
 
74
        if column == REVNO: return ".".join(["%d" % (revno)
 
75
                                      for revno in revno_sequence])
 
76
        
 
77
        if revid not in self.revisions:
 
78
            revision = self.branch.repository.get_revisions([revid])[0]
84
79
            self.revisions[revid] = revision
85
80
        else:
86
81
            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)
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)
 
82
        
 
83
        if column == REVISION: return revision
 
84
        if column == MESSAGE: return revision.message.split("\n")[0]
 
85
        if column == COMMITER: return revision.committer
 
86
        if column == TIMESTAMP: return format_date(revision.timestamp,
 
87
                                                   revision.timezone)
 
88
    
 
89
    def on_iter_next(self, rowref):
 
90
        if rowref < len(self.line_graph_data) - 1:
 
91
            return rowref+1
 
92
        return None
 
93
    
 
94
    def on_iter_children(self, parent):
 
95
        if parent is None: return 0
 
96
        return None
 
97
    
 
98
    def on_iter_has_child(self, rowref):
 
99
        return False
 
100
    
 
101
    def on_iter_n_children(self, rowref):
 
102
        if rowref is None: return len(self.line_graph_data)
 
103
        return 0
 
104
    
 
105
    def on_iter_nth_child(self, parent, n):
 
106
        if parent is None: return n
 
107
        return None
 
108
    
 
109
    def on_iter_parent(self, child):
 
110
        return None