/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

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