/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: Gary van der Merwe
  • Date: 2007-08-12 16:12:33 UTC
  • mto: (256.2.37 gtk)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: garyvdm@gmail.com-20070812161233-yhv1vafcxtsvpugj
Fix for bug Bug #132017 : olive no longer able to find bzrlib location.

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