/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: Daniel Schierbeck
  • Date: 2007-12-06 23:37:06 UTC
  • mto: This revision was merged to the branch mainline in revision 417.
  • Revision ID: daniel.schierbeck@gmail.com-20071206233706-eeinks66w86r3gfm
Fixed bug in gmissing.

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