/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: Daniel Schierbeck
  • Date: 2008-01-21 16:38:50 UTC
  • mto: (423.1.8 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080121163850-51rdlavnxyhrmvvx
Removed end-of-line markers.

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
 
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
28
CHILDREN = 10
29
 
TAGS = 11
30
 
 
31
 
class TreeModel(gtk.GenericTreeModel):
32
 
 
33
 
    
34
 
    def __init__ (self, branch, line_graph_data):
35
 
        gtk.GenericTreeModel.__init__(self)
 
29
TAGS = 11
 
30
 
 
31
class TreeModel(gtk.GenericTreeModel):
 
32
 
 
33
    
 
34
    def __init__ (self, branch, line_graph_data):
 
35
        gtk.GenericTreeModel.__init__(self)
36
36
        self.revisions = {}
37
 
        self.branch = branch
38
 
        self.repository = branch.repository
39
 
        self.line_graph_data = line_graph_data
40
 
    
41
 
    def on_get_flags(self):
42
 
        return gtk.TREE_MODEL_LIST_ONLY
43
 
    
44
 
    def on_get_n_columns(self):
45
 
        return 12
46
 
    
47
 
    def on_get_column_type(self, index):
48
 
        if index == REVID: return gobject.TYPE_STRING
49
 
        if index == NODE: return gobject.TYPE_PYOBJECT
50
 
        if index == LINES: return gobject.TYPE_PYOBJECT
51
 
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
52
 
        if index == REVNO: return gobject.TYPE_STRING
53
 
        if index == MESSAGE: return gobject.TYPE_STRING
54
 
        if index == COMMITER: return gobject.TYPE_STRING
55
 
        if index == TIMESTAMP: return gobject.TYPE_STRING
56
 
        if index == REVISION: return gobject.TYPE_PYOBJECT
57
 
        if index == PARENTS: return gobject.TYPE_PYOBJECT
 
37
        self.branch = branch
 
38
        self.repository = branch.repository
 
39
        self.line_graph_data = line_graph_data
 
40
    
 
41
    def on_get_flags(self):
 
42
        return gtk.TREE_MODEL_LIST_ONLY
 
43
    
 
44
    def on_get_n_columns(self):
 
45
        return 12
 
46
    
 
47
    def on_get_column_type(self, index):
 
48
        if index == REVID: return gobject.TYPE_STRING
 
49
        if index == NODE: return gobject.TYPE_PYOBJECT
 
50
        if index == LINES: return gobject.TYPE_PYOBJECT
 
51
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
 
52
        if index == REVNO: return gobject.TYPE_STRING
 
53
        if index == MESSAGE: return gobject.TYPE_STRING
 
54
        if index == COMMITER: return gobject.TYPE_STRING
 
55
        if index == TIMESTAMP: return gobject.TYPE_STRING
 
56
        if index == REVISION: return gobject.TYPE_PYOBJECT
 
57
        if index == PARENTS: return gobject.TYPE_PYOBJECT
58
58
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
59
 
        if index == TAGS: return gobject.TYPE_PYOBJECT
60
 
        
61
 
    def on_get_iter(self, path):
62
 
        return path[0]
63
 
    
64
 
    def on_get_path(self, rowref):
65
 
        return rowref
66
 
    
67
 
    def on_get_value(self, rowref, column):
68
 
        if len(self.line_graph_data) > 0:
69
 
            (revid, node, lines, parents,
70
 
             children, revno_sequence) = self.line_graph_data[rowref]
71
 
        else:
72
 
            (revid, node, lines, parents,
73
 
             children, revno_sequence) = (None, (0, 0), (), (),
74
 
                                          (), ())
75
 
        if column == REVID: return revid
76
 
        if column == NODE: return node
77
 
        if column == LINES: return lines
78
 
        if column == PARENTS: return parents
79
 
        if column == CHILDREN: return children
80
 
        if column == LAST_LINES:
81
 
            if rowref>0:
82
 
                return self.line_graph_data[rowref-1][2]
83
 
            return []
84
 
        if column == REVNO: return ".".join(["%d" % (revno)
85
 
                                      for revno in revno_sequence])
 
59
        if index == TAGS: return gobject.TYPE_PYOBJECT
 
60
        
 
61
    def on_get_iter(self, path):
 
62
        return path[0]
 
63
    
 
64
    def on_get_path(self, rowref):
 
65
        return rowref
 
66
    
 
67
    def on_get_value(self, rowref, column):
 
68
        if len(self.line_graph_data) > 0:
 
69
            (revid, node, lines, parents,
 
70
             children, revno_sequence) = self.line_graph_data[rowref]
 
71
        else:
 
72
            (revid, node, lines, parents,
 
73
             children, revno_sequence) = (None, (0, 0), (), (),
 
74
                                          (), ())
 
75
        if column == REVID: return revid
 
76
        if column == NODE: return node
 
77
        if column == LINES: return lines
 
78
        if column == PARENTS: return parents
 
79
        if column == CHILDREN: return children
 
80
        if column == LAST_LINES:
 
81
            if rowref>0:
 
82
                return self.line_graph_data[rowref-1][2]
 
83
            return []
 
84
        if column == REVNO: return ".".join(["%d" % (revno)
 
85
                                      for revno in revno_sequence])
86
86
 
87
87
        if column == TAGS:
88
88
            if not self.branch.supports_tags():
91
91
                return self.branch.tags.get_reverse_tag_dict()[revid]
92
92
            except KeyError:
93
93
                return []
94
 
 
95
 
        if revid is None:
96
 
            return None
97
 
        if revid not in self.revisions:
98
 
            revision = self.repository.get_revisions([revid])[0]
99
 
            self.revisions[revid] = revision
100
 
        else:
101
 
            revision = self.revisions[revid]
102
 
        
103
 
        if column == REVISION: return revision
104
 
        if column == MESSAGE: return escape(revision.get_summary())
105
 
        if column == COMMITER: return re.sub('<.*@.*>', '', 
106
 
                                             revision.committer).strip(' ')
107
 
        if column == TIMESTAMP: 
108
 
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
109
 
 
110
 
    def on_iter_next(self, rowref):
111
 
        if rowref < len(self.line_graph_data) - 1:
112
 
            return rowref+1
113
 
        return None
114
 
    
115
 
    def on_iter_children(self, parent):
116
 
        if parent is None: return 0
117
 
        return None
118
 
    
119
 
    def on_iter_has_child(self, rowref):
120
 
        return False
121
 
    
122
 
    def on_iter_n_children(self, rowref):
123
 
        if rowref is None: return len(self.line_graph_data)
124
 
        return 0
125
 
    
126
 
    def on_iter_nth_child(self, parent, n):
127
 
        if parent is None: return n
128
 
        return None
129
 
    
130
 
    def on_iter_parent(self, child):
131
 
        return None
 
94
 
 
95
        if revid is None:
 
96
            return None
 
97
        if revid not in self.revisions:
 
98
            revision = self.repository.get_revisions([revid])[0]
 
99
            self.revisions[revid] = revision
 
100
        else:
 
101
            revision = self.revisions[revid]
 
102
        
 
103
        if column == REVISION: return revision
 
104
        if column == MESSAGE: return escape(revision.get_summary())
 
105
        if column == COMMITER: return re.sub('<.*@.*>', '', 
 
106
                                             revision.committer).strip(' ')
 
107
        if column == TIMESTAMP: 
 
108
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
109
 
 
110
    def on_iter_next(self, rowref):
 
111
        if rowref < len(self.line_graph_data) - 1:
 
112
            return rowref+1
 
113
        return None
 
114
    
 
115
    def on_iter_children(self, parent):
 
116
        if parent is None: return 0
 
117
        return None
 
118
    
 
119
    def on_iter_has_child(self, rowref):
 
120
        return False
 
121
    
 
122
    def on_iter_n_children(self, rowref):
 
123
        if rowref is None: return len(self.line_graph_data)
 
124
        return 0
 
125
    
 
126
    def on_iter_nth_child(self, parent, n):
 
127
        if parent is None: return n
 
128
        return None
 
129
    
 
130
    def on_iter_parent(self, child):
 
131
        return None