/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: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

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
 
    def _add_parents_or_children(self, revids, widgets, table):
120
 
        while len(widgets) > 0:
121
 
            widget = widgets.pop()
122
 
            table.remove(widget)
123
 
        
124
 
        table.resize(max(len(revids), 1), 2)
125
 
 
126
 
        for idx, revid in enumerate(revids):
127
 
            align = gtk.Alignment(0.0, 0.0)
128
 
            widgets.append(align)
129
 
            table.attach(align, 1, 2, idx, idx + 1,
130
 
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
131
 
            align.show()
132
 
 
133
 
            hbox = gtk.HBox(False, spacing=6)
134
 
            align.add(hbox)
135
 
            hbox.show()
136
 
 
137
 
            image = gtk.Image()
138
 
            image.set_from_stock(
139
 
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
140
 
            image.show()
141
 
 
142
 
            if self._show_callback is not None:
143
 
                button = gtk.Button()
144
 
                button.add(image)
145
 
                button.connect("clicked", self._show_clicked_cb,
146
 
                               self._revision.revision_id, revid)
147
 
                hbox.pack_start(button, expand=False, fill=True)
148
 
                button.show()
149
 
 
150
 
            if self._go_callback is not None:
151
 
                button = gtk.Button(revid)
152
 
                button.connect("clicked", self._go_clicked_cb, revid)
153
 
            else:
154
 
                button = gtk.Label(revid)
155
 
            button.set_use_underline(False)
156
 
            hbox.pack_start(button, expand=False, fill=True)
157
 
            button.show()
158
 
 
159
 
    def _create(self):
160
 
        vbox = gtk.VBox(False, 6)
161
 
        vbox.set_border_width(6)
162
 
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
163
 
        vbox.pack_start(self._create_parents(), expand=False, fill=True)
164
 
        if self.show_children:
165
 
            vbox.pack_start(self._create_children(), expand=False, fill=True)
166
 
        vbox.pack_start(self._create_message_view())
167
 
        self.add_with_viewport(vbox)
168
 
        vbox.show()
169
 
 
170
 
    def _create_headers(self):
171
 
        self.table = gtk.Table(rows=5, columns=2)
172
 
        self.table.set_row_spacings(6)
173
 
        self.table.set_col_spacings(6)
174
 
        self.table.show()
175
 
 
176
 
        align = gtk.Alignment(1.0, 0.5)
177
 
        label = gtk.Label()
178
 
        label.set_markup("<b>Revision Id:</b>")
179
 
        align.add(label)
180
 
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
181
 
        align.show()
182
 
        label.show()
183
 
 
184
 
        align = gtk.Alignment(0.0, 0.5)
185
 
        self.revision_id = gtk.Label()
186
 
        self.revision_id.set_selectable(True)
187
 
        align.add(self.revision_id)
188
 
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
189
 
        align.show()
190
 
        self.revision_id.show()
191
 
 
192
 
        align = gtk.Alignment(1.0, 0.5)
193
 
        self.author_label = gtk.Label()
194
 
        self.author_label.set_markup("<b>Author:</b>")
195
 
        align.add(self.author_label)
196
 
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
197
 
        align.show()
198
 
        self.author_label.show()
199
 
 
200
 
        align = gtk.Alignment(0.0, 0.5)
201
 
        self.author = gtk.Label()
202
 
        self.author.set_selectable(True)
203
 
        align.add(self.author)
204
 
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
205
 
        align.show()
206
 
        self.author.show()
207
 
        self.author.hide()
208
 
 
209
 
        align = gtk.Alignment(1.0, 0.5)
210
 
        label = gtk.Label()
211
 
        label.set_markup("<b>Committer:</b>")
212
 
        align.add(label)
213
 
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
214
 
        align.show()
215
 
        label.show()
216
 
 
217
 
        align = gtk.Alignment(0.0, 0.5)
218
 
        self.committer = gtk.Label()
219
 
        self.committer.set_selectable(True)
220
 
        align.add(self.committer)
221
 
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
222
 
        align.show()
223
 
        self.committer.show()
224
 
 
225
 
        align = gtk.Alignment(0.0, 0.5)
226
 
        label = gtk.Label()
227
 
        label.set_markup("<b>Branch nick:</b>")
228
 
        align.add(label)
229
 
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
230
 
        label.show()
231
 
        align.show()
232
 
 
233
 
        align = gtk.Alignment(0.0, 0.5)
234
 
        self.branchnick_label = gtk.Label()
235
 
        self.branchnick_label.set_selectable(True)
236
 
        align.add(self.branchnick_label)
237
 
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
238
 
        self.branchnick_label.show()
239
 
        align.show()
240
 
 
241
 
        align = gtk.Alignment(1.0, 0.5)
242
 
        label = gtk.Label()
243
 
        label.set_markup("<b>Timestamp:</b>")
244
 
        align.add(label)
245
 
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
246
 
        align.show()
247
 
        label.show()
248
 
 
249
 
        align = gtk.Alignment(0.0, 0.5)
250
 
        self.timestamp = gtk.Label()
251
 
        self.timestamp.set_selectable(True)
252
 
        align.add(self.timestamp)
253
 
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
254
 
        align.show()
255
 
        self.timestamp.show()
256
 
 
257
 
        align = gtk.Alignment(1.0, 0.5)
258
 
        self.tags_label = gtk.Label()
259
 
        self.tags_label.set_markup("<b>Tags:</b>")
260
 
        align.add(self.tags_label)
261
 
        align.show()
262
 
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
263
 
        self.tags_label.show()
264
 
 
265
 
        align = gtk.Alignment(0.0, 0.5)
266
 
        self.tags_list = gtk.VBox()
267
 
        align.add(self.tags_list)
268
 
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
269
 
        align.show()
270
 
        self.tags_list.show()
271
 
        self.tags_widgets = []
272
 
 
273
 
        return self.table
274
 
 
275
 
    
276
 
    def _create_parents(self):
277
 
        hbox = gtk.HBox(True, 3)
278
 
        
279
 
        self.parents_table = self._create_parents_or_children_table(
280
 
            "<b>Parents:</b>")
281
 
        self.parents_widgets = []
282
 
        hbox.pack_start(self.parents_table)
283
 
 
284
 
        hbox.show()
285
 
        return hbox
286
 
 
287
 
    def _create_children(self):
288
 
        hbox = gtk.HBox(True, 3)
289
 
        self.children_table = self._create_parents_or_children_table(
290
 
            "<b>Children:</b>")
291
 
        self.children_widgets = []
292
 
        hbox.pack_start(self.children_table)
293
 
        hbox.show()
294
 
        return hbox
295
 
        
296
 
    def _create_parents_or_children_table(self, text):
297
 
        table = gtk.Table(rows=1, columns=2)
298
 
        table.set_row_spacings(3)
299
 
        table.set_col_spacings(6)
300
 
        table.show()
301
 
 
302
 
        label = gtk.Label()
303
 
        label.set_markup(text)
304
 
        align = gtk.Alignment(0.0, 0.5)
305
 
        align.add(label)
306
 
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
307
 
        label.show()
308
 
        align.show()
309
 
 
310
 
        return table
311
 
    
312
 
 
313
 
 
314
 
    def _create_message_view(self):
315
 
        self.message_buffer = gtk.TextBuffer()
316
 
        tv = gtk.TextView(self.message_buffer)
317
 
        tv.set_editable(False)
318
 
        tv.set_wrap_mode(gtk.WRAP_WORD)
319
 
        tv.modify_font(pango.FontDescription("Monospace"))
320
 
        tv.show()
321
 
        return tv
322