/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: Jelmer Vernooij
  • Date: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
14
 
from bzrlib.osutils import format_date
15
 
 
16
 
REVID = 0
17
 
NODE = 1
18
 
LINES = 2
19
 
LAST_LINES = 3
20
 
REVNO = 4
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)
33
 
        self.revisions = {}
34
 
        self.branch = branch
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]
79
 
            self.revisions[revid] = revision
80
 
        else:
81
 
            revision = self.revisions[revid]
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