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

  • Committer: Jelmer Vernooij
  • Date: 2006-05-19 16:37:13 UTC
  • Revision ID: jelmer@samba.org-20060519163713-be77b31c72cbc7e8
Move visualisation code to a separate directory, preparing for bundling 
the GTK+ plugins for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
1
2
# -*- coding: UTF-8 -*-
2
3
"""Branch window.
3
4
 
26
27
    for a particular branch.
27
28
    """
28
29
 
29
 
    def __init__(self):
 
30
    def __init__(self, app=None):
30
31
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
31
32
        self.set_border_width(0)
32
33
        self.set_title("bzrk")
33
34
 
 
35
        self.app = app
 
36
 
34
37
        # Use three-quarters of the screen by default
35
38
        screen = self.get_screen()
36
39
        monitor = screen.get_monitor_geometry(0)
145
148
 
146
149
    def construct_bottom(self):
147
150
        """Construct the bottom half of the window."""
148
 
        from bzrlib.plugins.gtk.logview import LogView
149
 
        self.logview = LogView()
 
151
        scrollwin = gtk.ScrolledWindow()
 
152
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
153
        scrollwin.set_shadow_type(gtk.SHADOW_NONE)
150
154
        (width, height) = self.get_size()
151
 
        self.logview.set_size_request(width, int(height / 2.5))
152
 
        self.logview.show()
153
 
        self.logview.set_show_callback(self._show_clicked_cb)
154
 
        self.logview.set_go_callback(self._go_clicked_cb)
155
 
        return self.logview
 
155
        scrollwin.set_size_request(width, int(height / 2.5))
 
156
        scrollwin.show()
 
157
 
 
158
        vbox = gtk.VBox(False, spacing=6)
 
159
        vbox.set_border_width(6)
 
160
        scrollwin.add_with_viewport(vbox)
 
161
        vbox.show()
 
162
 
 
163
        table = gtk.Table(rows=4, columns=2)
 
164
        table.set_row_spacings(6)
 
165
        table.set_col_spacings(6)
 
166
        vbox.pack_start(table, expand=False, fill=True)
 
167
        table.show()
 
168
 
 
169
        align = gtk.Alignment(0.0, 0.5)
 
170
        label = gtk.Label()
 
171
        label.set_markup("<b>Revision:</b>")
 
172
        align.add(label)
 
173
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
174
        label.show()
 
175
        align.show()
 
176
 
 
177
        align = gtk.Alignment(0.0, 0.5)
 
178
        self.revid_label = gtk.Label()
 
179
        self.revid_label.set_selectable(True)
 
180
        align.add(self.revid_label)
 
181
        table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
182
        self.revid_label.show()
 
183
        align.show()
 
184
 
 
185
        align = gtk.Alignment(0.0, 0.5)
 
186
        label = gtk.Label()
 
187
        label.set_markup("<b>Committer:</b>")
 
188
        align.add(label)
 
189
        table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
 
190
        label.show()
 
191
        align.show()
 
192
 
 
193
        align = gtk.Alignment(0.0, 0.5)
 
194
        self.committer_label = gtk.Label()
 
195
        self.committer_label.set_selectable(True)
 
196
        align.add(self.committer_label)
 
197
        table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
198
        self.committer_label.show()
 
199
        align.show()
 
200
 
 
201
        align = gtk.Alignment(0.0, 0.5)
 
202
        label = gtk.Label()
 
203
        label.set_markup("<b>Branch nick:</b>")
 
204
        align.add(label)
 
205
        table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
 
206
        label.show()
 
207
        align.show()
 
208
 
 
209
        align = gtk.Alignment(0.0, 0.5)
 
210
        self.branchnick_label = gtk.Label()
 
211
        self.branchnick_label.set_selectable(True)
 
212
        align.add(self.branchnick_label)
 
213
        table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
214
        self.branchnick_label.show()
 
215
        align.show()
 
216
 
 
217
        align = gtk.Alignment(0.0, 0.5)
 
218
        label = gtk.Label()
 
219
        label.set_markup("<b>Timestamp:</b>")
 
220
        align.add(label)
 
221
        table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
 
222
        label.show()
 
223
        align.show()
 
224
 
 
225
        align = gtk.Alignment(0.0, 0.5)
 
226
        self.timestamp_label = gtk.Label()
 
227
        self.timestamp_label.set_selectable(True)
 
228
        align.add(self.timestamp_label)
 
229
        table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
230
        self.timestamp_label.show()
 
231
        align.show()
 
232
 
 
233
        self.parents_table = gtk.Table(rows=1, columns=2)
 
234
        self.parents_table.set_row_spacings(3)
 
235
        self.parents_table.set_col_spacings(6)
 
236
        self.parents_table.show()
 
237
        vbox.pack_start(self.parents_table, expand=False, fill=True)
 
238
        self.parents_widgets = []
 
239
 
 
240
        label = gtk.Label()
 
241
        label.set_markup("<b>Parents:</b>")
 
242
        align = gtk.Alignment(0.0, 0.5)
 
243
        align.add(label)
 
244
        self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
245
        label.show()
 
246
        align.show()
 
247
 
 
248
        self.message_buffer = gtk.TextBuffer()
 
249
        textview = gtk.TextView(self.message_buffer)
 
250
        textview.set_editable(False)
 
251
        textview.set_wrap_mode(gtk.WRAP_WORD)
 
252
        textview.modify_font(pango.FontDescription("Monospace"))
 
253
        vbox.pack_start(textview, expand=True, fill=True)
 
254
        textview.show()
 
255
 
 
256
        return scrollwin
156
257
 
157
258
    def set_branch(self, branch, start, maxnum):
158
259
        """Set the branch and start position for this window.
202
303
 
203
304
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
204
305
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
205
 
        self.logview.set_revision(revision)
 
306
 
 
307
        if revision.committer is not None:
 
308
            branchnick = ""
 
309
            committer = revision.committer
 
310
            timestamp = format_date(revision.timestamp, revision.timezone)
 
311
            message = revision.message
 
312
            try:
 
313
                branchnick = revision.properties['branch-nick']
 
314
            except KeyError:
 
315
                pass
 
316
 
 
317
        else:
 
318
            committer = ""
 
319
            timestamp = ""
 
320
            message = ""
 
321
            branchnick = ""
 
322
 
 
323
        self.revid_label.set_text(revision.revision_id)
 
324
        self.branchnick_label.set_text(branchnick)
 
325
 
 
326
        self.committer_label.set_text(committer)
 
327
        self.timestamp_label.set_text(timestamp)
 
328
        self.message_buffer.set_text(message)
 
329
 
 
330
        for widget in self.parents_widgets:
 
331
            self.parents_table.remove(widget)
 
332
 
 
333
        self.parents_widgets = []
 
334
        self.parents_table.resize(max(len(self.parent_ids[revision]), 1), 2)
 
335
        
 
336
        for idx, parent_id in enumerate(self.parent_ids[revision]):
 
337
            align = gtk.Alignment(0.0, 0.0)
 
338
            self.parents_widgets.append(align)
 
339
            self.parents_table.attach(align, 1, 2, idx, idx + 1,
 
340
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
 
341
            align.show()
 
342
 
 
343
            hbox = gtk.HBox(False, spacing=6)
 
344
            align.add(hbox)
 
345
            hbox.show()
 
346
 
 
347
            image = gtk.Image()
 
348
            image.set_from_stock(
 
349
                gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_SMALL_TOOLBAR)
 
350
            image.show()
 
351
 
 
352
            button = gtk.Button()
 
353
            button.add(image)
 
354
            button.connect("clicked", self._go_clicked_cb, parent_id)
 
355
            hbox.pack_start(button, expand=False, fill=True)
 
356
            button.show()
 
357
 
 
358
            image = gtk.Image()
 
359
            image.set_from_stock(
 
360
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
 
361
            image.show()
 
362
 
 
363
            button = gtk.Button()
 
364
            button.add(image)
 
365
            button.set_sensitive(self.app is not None)
 
366
            button.connect("clicked", self._show_clicked_cb,
 
367
                           revision.revision_id, parent_id)
 
368
            hbox.pack_start(button, expand=False, fill=True)
 
369
            button.show()
 
370
 
 
371
            label = gtk.Label(parent_id)
 
372
            label.set_selectable(True)
 
373
            hbox.pack_start(label, expand=False, fill=True)
 
374
            label.show()
 
375
 
206
376
 
207
377
    def _back_clicked_cb(self, *args):
208
378
        """Callback for when the back button is clicked."""
237
407
            self.treeview.set_cursor(self.index[prev])
238
408
        self.treeview.grab_focus()
239
409
 
240
 
    def _go_clicked_cb(self, revid):
 
410
    def _go_clicked_cb(self, widget, revid):
241
411
        """Callback for when the go button for a parent is clicked."""
242
412
        self.treeview.set_cursor(self.index[self.revisions[revid]])
243
413
        self.treeview.grab_focus()
244
414
 
245
 
    def show_diff(self, branch, revid, parentid):
246
 
        """Open a new window to show a diff between the given revisions."""
247
 
        from bzrlib.plugins.gtk.diff import DiffWindow
248
 
        window = DiffWindow()
249
 
        rev_tree = branch.repository.revision_tree(revid)
250
 
        parent_tree = branch.repository.revision_tree(parentid)
251
 
        description = revid + " - " + branch.nick
252
 
        window.set_diff(description, rev_tree, parent_tree)
253
 
        window.show()
254
 
 
255
 
    def _show_clicked_cb(self, revid, parentid):
 
415
    def _show_clicked_cb(self, widget, revid, parentid):
256
416
        """Callback for when the show button for a parent is clicked."""
257
 
        self.show_diff(self.branch, revid, parentid)
 
417
        if self.app is not None:
 
418
            self.app.show_diff(self.branch, revid, parentid)
258
419
        self.treeview.grab_focus()
259
420
 
260
421
    def _treeview_row_activated_cb(self, widget, path, col):
261
422
        # TODO: more than one parent
262
423
        """Callback for when a treeview row gets activated."""
263
424
        revision = self.model[path][0]
264
 
        if len(self.parent_ids[revision]) == 0:
265
 
            # Ignore revisions without parent
266
 
            return
267
425
        parent_id = self.parent_ids[revision][0]
268
 
        self.show_diff(self.branch, revision.revision_id, parent_id)
 
426
        if self.app is not None:
 
427
            self.app.show_diff(self.branch, revision.revision_id, parent_id)
269
428
        self.treeview.grab_focus()