/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 logview.py

  • Committer: Gary van der Merwe
  • Date: 2007-09-20 19:42:26 UTC
  • mto: (256.2.54 gtk)
  • mto: This revision was merged to the branch mainline in revision 289.
  • Revision ID: garyvdm@gmail.com-20070920194226-t9wlbuyaaqowjvsz
RevertĀ GTKTreeModelĀ on_ref_nodeĀ implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
 
2
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
import pygtk
 
19
pygtk.require("2.0")
 
20
import gtk
 
21
import pango
 
22
 
 
23
from bzrlib.osutils import format_date
 
24
 
 
25
 
 
26
class LogView(gtk.ScrolledWindow):
 
27
    """ Custom widget for commit log details.
 
28
 
 
29
    A variety of bzr tools may need to implement such a thing. This is a
 
30
    start.
 
31
    """
 
32
 
 
33
    def __init__(self, revision=None, scroll=True, tags=[],
 
34
                 show_children=False):
 
35
        super(LogView, self).__init__()
 
36
        if scroll:
 
37
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
38
        else:
 
39
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
 
40
        self.set_shadow_type(gtk.SHADOW_NONE)
 
41
        self.show_children = show_children
 
42
        self._create()
 
43
        self._show_callback = None
 
44
        self._go_callback = None
 
45
        self._clicked_callback = None
 
46
 
 
47
        if revision is not None:
 
48
            self.set_revision(revision, tags=tags)
 
49
 
 
50
    def set_show_callback(self, callback):
 
51
        self._show_callback = callback
 
52
 
 
53
    def set_go_callback(self, callback):
 
54
        self._go_callback = callback
 
55
 
 
56
    def set_revision(self, revision, tags=[], children=[]):
 
57
        self._revision = revision
 
58
        self.revision_id.set_text(revision.revision_id)
 
59
        if revision.committer is not None:
 
60
            self.committer.set_text(revision.committer)
 
61
        else:
 
62
            self.committer.set_text("")
 
63
        author = revision.properties.get('author', '')
 
64
        if author != '':
 
65
            self.author.set_text(author)
 
66
            self.author.show()
 
67
            self.author_label.show()
 
68
        else:
 
69
            self.author.hide()
 
70
            self.author_label.hide()
 
71
 
 
72
        if revision.timestamp is not None:
 
73
            self.timestamp.set_text(format_date(revision.timestamp,
 
74
                                                revision.timezone))
 
75
        self.message_buffer.set_text(revision.message)
 
76
        try:
 
77
            self.branchnick_label.set_text(revision.properties['branch-nick'])
 
78
        except KeyError:
 
79
            self.branchnick_label.set_text("")
 
80
 
 
81
        self._add_parents_or_children(revision.parent_ids,
 
82
                                      self.parents_widgets,
 
83
                                      self.parents_table)
 
84
        
 
85
        if self.show_children:
 
86
            self._add_parents_or_children(children,
 
87
                                          self.children_widgets,
 
88
                                          self.children_table)
 
89
        
 
90
        self._add_tags(tags)
 
91
 
 
92
    def _show_clicked_cb(self, widget, revid, parentid):
 
93
        """Callback for when the show button for a parent is clicked."""
 
94
        self._show_callback(revid, parentid)
 
95
 
 
96
    def _go_clicked_cb(self, widget, revid):
 
97
        """Callback for when the go button for a parent is clicked."""
 
98
        self._go_callback(revid)
 
99
 
 
100
    def _add_tags(self, tags):
 
101
        if tags == []:
 
102
            self.tags_list.hide()
 
103
            self.tags_label.hide()
 
104
            return
 
105
 
 
106
        for widget in self.tags_widgets:
 
107
            self.tags_list.remove(widget)
 
108
 
 
109
        self.tags_widgets = []
 
110
 
 
111
        for tag in tags:
 
112
            widget = gtk.Label(tag)
 
113
            widget.set_selectable(True)
 
114
            self.tags_widgets.append(widget)
 
115
            self.tags_list.add(widget)
 
116
        self.tags_list.show_all()
 
117
        self.tags_label.show_all()
 
118
        
 
119
 
 
120
    def _add_parents_or_children(self, revids, widgets, table):
 
121
        while len(widgets) > 0:
 
122
            widget = widgets.pop()
 
123
            table.remove(widget)
 
124
        
 
125
        table.resize(max(len(revids), 1), 2)
 
126
 
 
127
        for idx, revid in enumerate(revids):
 
128
            align = gtk.Alignment(0.0, 0.0)
 
129
            widgets.append(align)
 
130
            table.attach(align, 1, 2, idx, idx + 1,
 
131
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
 
132
            align.show()
 
133
 
 
134
            hbox = gtk.HBox(False, spacing=6)
 
135
            align.add(hbox)
 
136
            hbox.show()
 
137
 
 
138
            image = gtk.Image()
 
139
            image.set_from_stock(
 
140
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
 
141
            image.show()
 
142
 
 
143
            if self._show_callback is not None:
 
144
                button = gtk.Button()
 
145
                button.add(image)
 
146
                button.connect("clicked", self._show_clicked_cb,
 
147
                               self._revision.revision_id, revid)
 
148
                hbox.pack_start(button, expand=False, fill=True)
 
149
                button.show()
 
150
 
 
151
            if self._go_callback is not None:
 
152
                button = gtk.Button(revid)
 
153
                button.connect("clicked", self._go_clicked_cb, revid)
 
154
            else:
 
155
                button = gtk.Label(revid)
 
156
            button.set_use_underline(False)
 
157
            hbox.pack_start(button, expand=False, fill=True)
 
158
            button.show()
 
159
 
 
160
    def _create(self):
 
161
        vbox = gtk.VBox(False, 6)
 
162
        vbox.set_border_width(6)
 
163
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
 
164
        vbox.pack_start(self._create_parents_and_children(), expand=False, fill=True)
 
165
        vbox.pack_start(self._create_message_view())
 
166
        self.add_with_viewport(vbox)
 
167
        vbox.show()
 
168
 
 
169
    def _create_headers(self):
 
170
        self.table = gtk.Table(rows=5, columns=2)
 
171
        self.table.set_row_spacings(6)
 
172
        self.table.set_col_spacings(6)
 
173
        self.table.show()
 
174
 
 
175
        align = gtk.Alignment(1.0, 0.5)
 
176
        label = gtk.Label()
 
177
        label.set_markup("<b>Revision Id:</b>")
 
178
        align.add(label)
 
179
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
180
        align.show()
 
181
        label.show()
 
182
 
 
183
        align = gtk.Alignment(0.0, 0.5)
 
184
        self.revision_id = gtk.Label()
 
185
        self.revision_id.set_selectable(True)
 
186
        align.add(self.revision_id)
 
187
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
188
        align.show()
 
189
        self.revision_id.show()
 
190
 
 
191
        align = gtk.Alignment(1.0, 0.5)
 
192
        self.author_label = gtk.Label()
 
193
        self.author_label.set_markup("<b>Author:</b>")
 
194
        align.add(self.author_label)
 
195
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
 
196
        align.show()
 
197
        self.author_label.show()
 
198
 
 
199
        align = gtk.Alignment(0.0, 0.5)
 
200
        self.author = gtk.Label()
 
201
        self.author.set_selectable(True)
 
202
        align.add(self.author)
 
203
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
204
        align.show()
 
205
        self.author.show()
 
206
        self.author.hide()
 
207
 
 
208
        align = gtk.Alignment(1.0, 0.5)
 
209
        label = gtk.Label()
 
210
        label.set_markup("<b>Committer:</b>")
 
211
        align.add(label)
 
212
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
 
213
        align.show()
 
214
        label.show()
 
215
 
 
216
        align = gtk.Alignment(0.0, 0.5)
 
217
        self.committer = gtk.Label()
 
218
        self.committer.set_selectable(True)
 
219
        align.add(self.committer)
 
220
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
221
        align.show()
 
222
        self.committer.show()
 
223
 
 
224
        align = gtk.Alignment(0.0, 0.5)
 
225
        label = gtk.Label()
 
226
        label.set_markup("<b>Branch nick:</b>")
 
227
        align.add(label)
 
228
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
 
229
        label.show()
 
230
        align.show()
 
231
 
 
232
        align = gtk.Alignment(0.0, 0.5)
 
233
        self.branchnick_label = gtk.Label()
 
234
        self.branchnick_label.set_selectable(True)
 
235
        align.add(self.branchnick_label)
 
236
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
237
        self.branchnick_label.show()
 
238
        align.show()
 
239
 
 
240
        align = gtk.Alignment(1.0, 0.5)
 
241
        label = gtk.Label()
 
242
        label.set_markup("<b>Timestamp:</b>")
 
243
        align.add(label)
 
244
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
 
245
        align.show()
 
246
        label.show()
 
247
 
 
248
        align = gtk.Alignment(0.0, 0.5)
 
249
        self.timestamp = gtk.Label()
 
250
        self.timestamp.set_selectable(True)
 
251
        align.add(self.timestamp)
 
252
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
253
        align.show()
 
254
        self.timestamp.show()
 
255
 
 
256
        align = gtk.Alignment(1.0, 0.5)
 
257
        self.tags_label = gtk.Label()
 
258
        self.tags_label.set_markup("<b>Tags:</b>")
 
259
        align.add(self.tags_label)
 
260
        align.show()
 
261
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
 
262
        self.tags_label.show()
 
263
 
 
264
        align = gtk.Alignment(0.0, 0.5)
 
265
        self.tags_list = gtk.VBox()
 
266
        align.add(self.tags_list)
 
267
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
268
        align.show()
 
269
        self.tags_list.show()
 
270
        self.tags_widgets = []
 
271
 
 
272
        return self.table
 
273
 
 
274
    
 
275
    def _create_parents_and_children(self):
 
276
        hbox = gtk.HBox(True, 6)
 
277
        
 
278
        self.parents_table = self._create_parents_or_children_table(
 
279
            "<b>Parents:</b>")
 
280
        self.parents_widgets = []
 
281
        hbox.pack_start(self.parents_table)
 
282
        
 
283
        if self.show_children:
 
284
            self.children_table = self._create_parents_or_children_table(
 
285
                "<b>Children:</b>")
 
286
            self.children_widgets = []
 
287
            hbox.pack_start(self.children_table)
 
288
        
 
289
        hbox.show()
 
290
        return hbox
 
291
        
 
292
    def _create_parents_or_children_table(self, text):
 
293
        table = gtk.Table(rows=1, columns=2)
 
294
        table.set_row_spacings(3)
 
295
        table.set_col_spacings(6)
 
296
        table.show()
 
297
 
 
298
        label = gtk.Label()
 
299
        label.set_markup(text)
 
300
        align = gtk.Alignment(0.0, 0.5)
 
301
        align.add(label)
 
302
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
303
        label.show()
 
304
        align.show()
 
305
 
 
306
        return table
 
307
    
 
308
 
 
309
 
 
310
    def _create_message_view(self):
 
311
        self.message_buffer = gtk.TextBuffer()
 
312
        tv = gtk.TextView(self.message_buffer)
 
313
        tv.set_editable(False)
 
314
        tv.set_wrap_mode(gtk.WRAP_WORD)
 
315
        tv.modify_font(pango.FontDescription("Monospace"))
 
316
        tv.show()
 
317
        return tv
 
318