/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: Daniel Schierbeck
  • Date: 2007-10-14 15:54:57 UTC
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: daniel.schierbeck@gmail.com-20071014155457-m3ek29p4ima8ev7d
Added the new Window base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import gtk
13
13
import gobject
14
14
import pango
 
15
import treemodel
15
16
 
 
17
from bzrlib.plugins.gtk.window import Window
16
18
from bzrlib.osutils import format_date
17
19
 
18
 
from graph import distances, graph, same_branch
 
20
from linegraph import linegraph, same_branch
19
21
from graphcell import CellRendererGraph
20
 
 
21
 
 
22
 
class BranchWindow(gtk.Window):
 
22
from treemodel import TreeModel
 
23
 
 
24
 
 
25
class BranchWindow(Window):
23
26
    """Branch window.
24
27
 
25
28
    This object represents and manages a single window containing information
26
29
    for a particular branch.
27
30
    """
28
31
 
29
 
    def __init__(self, app=None):
30
 
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
 
32
    def __init__(self, parent=None):
 
33
        Window.__init__(self, parent=parent)
31
34
        self.set_border_width(0)
32
 
        self.set_title("bzrk")
33
 
 
34
 
        self.app = app
 
35
        self.set_title("Revision history")
35
36
 
36
37
        # Use three-quarters of the screen by default
37
38
        screen = self.get_screen()
55
56
        self.add(vbox)
56
57
 
57
58
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
58
 
 
 
59
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
60
        
59
61
        paned = gtk.VPaned()
60
62
        paned.pack1(self.construct_top(), resize=True, shrink=False)
61
63
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
64
66
        vbox.set_focus_child(paned)
65
67
 
66
68
        vbox.show()
 
69
    
 
70
    def construct_loading_msg(self):
 
71
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
72
                                                 gtk.ICON_SIZE_BUTTON)
 
73
        image_loading.show()
 
74
        
 
75
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
 
76
        label_loading.set_alignment(0.0, 0.5)        
 
77
        label_loading.show()
 
78
        
 
79
        self.loading_msg_box = gtk.HBox()
 
80
        self.loading_msg_box.set_spacing(5)
 
81
        self.loading_msg_box.set_border_width(5)        
 
82
        self.loading_msg_box.pack_start(image_loading, False, False)
 
83
        self.loading_msg_box.pack_start(label_loading, True, True)
 
84
        self.loading_msg_box.show()
 
85
        
 
86
        return self.loading_msg_box
67
87
 
68
88
    def construct_top(self):
69
89
        """Construct the top-half of the window."""
75
95
        self.treeview = gtk.TreeView()
76
96
        self.treeview.set_rules_hint(True)
77
97
        self.treeview.set_search_column(4)
78
 
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
 
98
        self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
79
99
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
 
100
        self.treeview.connect("button-release-event", 
 
101
                self._treeview_row_mouseclick)
 
102
        self.treeview.set_property('fixed-height-mode', True)
80
103
        scrollwin.add(self.treeview)
81
104
        self.treeview.show()
82
105
 
83
 
        cell = CellRendererGraph()
84
 
        column = gtk.TreeViewColumn()
 
106
        cell = gtk.CellRendererText()
 
107
        cell.set_property("width-chars", 15)
 
108
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
109
        column = gtk.TreeViewColumn("Revision No")
85
110
        column.set_resizable(True)
86
 
        column.pack_start(cell, expand=False)
87
 
        column.add_attribute(cell, "node", 1)
88
 
        column.add_attribute(cell, "in-lines", 2)
89
 
        column.add_attribute(cell, "out-lines", 3)
 
111
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
112
        column.set_fixed_width(cell.get_size(self.treeview)[2])
 
113
        column.pack_start(cell, expand=True)
 
114
        column.add_attribute(cell, "text", treemodel.REVNO)
90
115
        self.treeview.append_column(column)
91
116
 
 
117
        self.graph_cell = CellRendererGraph()
 
118
        self.graph_column = gtk.TreeViewColumn()
 
119
        self.graph_column.set_resizable(True)
 
120
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
121
        self.graph_column.pack_start(self.graph_cell, expand=False)
 
122
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
123
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
 
124
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
 
125
        self.treeview.append_column(self.graph_column)
 
126
 
92
127
        cell = gtk.CellRendererText()
93
 
        cell.set_property("width-chars", 40)
 
128
        cell.set_property("width-chars", 65)
94
129
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
95
130
        column = gtk.TreeViewColumn("Message")
96
131
        column.set_resizable(True)
 
132
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
133
        column.set_fixed_width(cell.get_size(self.treeview)[2])
97
134
        column.pack_start(cell, expand=True)
98
 
        column.add_attribute(cell, "text", 4)
 
135
        column.add_attribute(cell, "text", treemodel.MESSAGE)
99
136
        self.treeview.append_column(column)
100
137
 
101
138
        cell = gtk.CellRendererText()
102
 
        cell.set_property("width-chars", 40)
 
139
        cell.set_property("width-chars", 15)
103
140
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
104
141
        column = gtk.TreeViewColumn("Committer")
105
142
        column.set_resizable(True)
106
 
        column.pack_start(cell, expand=True)
107
 
        column.add_attribute(cell, "text", 5)
108
 
        self.treeview.append_column(column)
109
 
 
110
 
        cell = gtk.CellRendererText()
111
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
112
 
        column = gtk.TreeViewColumn("Date")
113
 
        column.set_resizable(True)
114
 
        column.pack_start(cell, expand=True)
115
 
        column.add_attribute(cell, "text", 6)
 
143
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
144
        column.set_fixed_width(cell.get_size(self.treeview)[2])
 
145
        column.pack_start(cell, expand=True)
 
146
        column.add_attribute(cell, "text", treemodel.COMMITER)
116
147
        self.treeview.append_column(column)
117
148
 
118
149
        return scrollwin
147
178
 
148
179
    def construct_bottom(self):
149
180
        """Construct the bottom half of the window."""
150
 
        scrollwin = gtk.ScrolledWindow()
151
 
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
152
 
        scrollwin.set_shadow_type(gtk.SHADOW_NONE)
 
181
        from bzrlib.plugins.gtk.logview import LogView
 
182
        self.logview = LogView(None, True, [], True)
153
183
        (width, height) = self.get_size()
154
 
        scrollwin.set_size_request(width, int(height / 2.5))
155
 
        scrollwin.show()
156
 
 
157
 
        vbox = gtk.VBox(False, spacing=6)
158
 
        vbox.set_border_width(6)
159
 
        scrollwin.add_with_viewport(vbox)
160
 
        vbox.show()
161
 
 
162
 
        table = gtk.Table(rows=4, columns=2)
163
 
        table.set_row_spacings(6)
164
 
        table.set_col_spacings(6)
165
 
        vbox.pack_start(table, expand=False, fill=True)
166
 
        table.show()
167
 
 
168
 
        align = gtk.Alignment(0.0, 0.5)
169
 
        label = gtk.Label()
170
 
        label.set_markup("<b>Revision:</b>")
171
 
        align.add(label)
172
 
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
173
 
        label.show()
174
 
        align.show()
175
 
 
176
 
        align = gtk.Alignment(0.0, 0.5)
177
 
        self.revid_label = gtk.Label()
178
 
        self.revid_label.set_selectable(True)
179
 
        align.add(self.revid_label)
180
 
        table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
181
 
        self.revid_label.show()
182
 
        align.show()
183
 
 
184
 
        align = gtk.Alignment(0.0, 0.5)
185
 
        label = gtk.Label()
186
 
        label.set_markup("<b>Committer:</b>")
187
 
        align.add(label)
188
 
        table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
189
 
        label.show()
190
 
        align.show()
191
 
 
192
 
        align = gtk.Alignment(0.0, 0.5)
193
 
        self.committer_label = gtk.Label()
194
 
        self.committer_label.set_selectable(True)
195
 
        align.add(self.committer_label)
196
 
        table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
197
 
        self.committer_label.show()
198
 
        align.show()
199
 
 
200
 
        align = gtk.Alignment(0.0, 0.5)
201
 
        label = gtk.Label()
202
 
        label.set_markup("<b>Branch nick:</b>")
203
 
        align.add(label)
204
 
        table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
205
 
        label.show()
206
 
        align.show()
207
 
 
208
 
        align = gtk.Alignment(0.0, 0.5)
209
 
        self.branchnick_label = gtk.Label()
210
 
        self.branchnick_label.set_selectable(True)
211
 
        align.add(self.branchnick_label)
212
 
        table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
213
 
        self.branchnick_label.show()
214
 
        align.show()
215
 
 
216
 
        align = gtk.Alignment(0.0, 0.5)
217
 
        label = gtk.Label()
218
 
        label.set_markup("<b>Timestamp:</b>")
219
 
        align.add(label)
220
 
        table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
221
 
        label.show()
222
 
        align.show()
223
 
 
224
 
        align = gtk.Alignment(0.0, 0.5)
225
 
        self.timestamp_label = gtk.Label()
226
 
        self.timestamp_label.set_selectable(True)
227
 
        align.add(self.timestamp_label)
228
 
        table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
229
 
        self.timestamp_label.show()
230
 
        align.show()
231
 
 
232
 
        self.parents_table = gtk.Table(rows=1, columns=2)
233
 
        self.parents_table.set_row_spacings(3)
234
 
        self.parents_table.set_col_spacings(6)
235
 
        self.parents_table.show()
236
 
        vbox.pack_start(self.parents_table, expand=False, fill=True)
237
 
        self.parents_widgets = []
238
 
 
239
 
        label = gtk.Label()
240
 
        label.set_markup("<b>Parents:</b>")
241
 
        align = gtk.Alignment(0.0, 0.5)
242
 
        align.add(label)
243
 
        self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
244
 
        label.show()
245
 
        align.show()
246
 
 
247
 
        self.message_buffer = gtk.TextBuffer()
248
 
        textview = gtk.TextView(self.message_buffer)
249
 
        textview.set_editable(False)
250
 
        textview.set_wrap_mode(gtk.WRAP_WORD)
251
 
        textview.modify_font(pango.FontDescription("Monospace"))
252
 
        vbox.pack_start(textview, expand=True, fill=True)
253
 
        textview.show()
254
 
 
255
 
        return scrollwin
 
184
        self.logview.set_size_request(width, int(height / 2.5))
 
185
        self.logview.show()
 
186
        self.logview.set_show_callback(self._show_clicked_cb)
 
187
        self.logview.set_go_callback(self._go_clicked_cb)
 
188
        return self.logview
256
189
 
257
190
    def set_branch(self, branch, start, maxnum):
258
191
        """Set the branch and start position for this window.
262
195
        treeview itself.
263
196
        """
264
197
        self.branch = branch
265
 
 
266
 
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
267
 
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
268
 
                                   gobject.TYPE_PYOBJECT,
269
 
                                   gobject.TYPE_PYOBJECT,
270
 
                                   gobject.TYPE_PYOBJECT,
271
 
                                   str, str, str)
272
 
        self.index = {}
273
 
        index = 0
274
 
 
275
 
        last_lines = []
276
 
        (self.revisions, colours, self.children, self.parent_ids,
277
 
         merge_sorted) = distances(branch, start)
278
 
        for (index, (revision, node, lines)) in enumerate(graph(
279
 
                self.revisions, colours, merge_sorted)):
280
 
            # FIXME: at this point we should be able to show the graph order
281
 
            # and lines with no message or commit data - and then incrementally
282
 
            # fill the timestamp, committer etc data as desired.
283
 
            message = revision.message.split("\n")[0]
284
 
            if revision.committer is not None:
285
 
                timestamp = format_date(revision.timestamp, revision.timezone)
286
 
            else:
287
 
                timestamp = None
288
 
            self.model.append([revision, node, last_lines, lines,
289
 
                               message, revision.committer, timestamp])
290
 
            self.index[revision] = index
291
 
            last_lines = lines
292
 
            if maxnum is not None and index > maxnum:
293
 
                break
294
 
 
295
 
        self.set_title(branch.nick + " - bzrk")
 
198
        self.set_title(branch.nick + " - revision history")
 
199
        gobject.idle_add(self.populate_model, start, maxnum)
 
200
 
 
201
    def populate_model(self, start, maxnum):
 
202
        (linegraphdata, index, columns_len) = linegraph(self.branch,
 
203
                                                        start,
 
204
                                                        maxnum)
 
205
        self.model = TreeModel(self.branch, linegraphdata)
 
206
        self.graph_cell.columns_len = columns_len
 
207
        width = self.graph_cell.get_size(self.treeview)[2]
 
208
        self.graph_column.set_fixed_width(width)
 
209
        self.graph_column.set_max_width(width)
 
210
        self.index = index
296
211
        self.treeview.set_model(self.model)
297
 
 
298
 
    def _treeview_cursor_cb(self, *args):
299
 
        """Callback for when the treeview cursor changes."""
300
 
        (path, col) = self.treeview.get_cursor()
301
 
        revision = self.model[path][0]
302
 
 
303
 
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
304
 
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
305
 
 
306
 
        if revision.committer is not None:
307
 
            branchnick = ""
308
 
            committer = revision.committer
309
 
            timestamp = format_date(revision.timestamp, revision.timezone)
310
 
            message = revision.message
311
 
            try:
312
 
                branchnick = revision.properties['branch-nick']
313
 
            except KeyError:
314
 
                pass
315
 
 
316
 
        else:
317
 
            committer = ""
318
 
            timestamp = ""
319
 
            message = ""
320
 
            branchnick = ""
321
 
 
322
 
        self.revid_label.set_text(revision.revision_id)
323
 
        self.branchnick_label.set_text(branchnick)
324
 
 
325
 
        self.committer_label.set_text(committer)
326
 
        self.timestamp_label.set_text(timestamp)
327
 
        self.message_buffer.set_text(message)
328
 
 
329
 
        for widget in self.parents_widgets:
330
 
            self.parents_table.remove(widget)
331
 
 
332
 
        self.parents_widgets = []
333
 
        self.parents_table.resize(max(len(self.parent_ids[revision]), 1), 2)
334
 
        
335
 
        for idx, parent_id in enumerate(self.parent_ids[revision]):
336
 
            align = gtk.Alignment(0.0, 0.0)
337
 
            self.parents_widgets.append(align)
338
 
            self.parents_table.attach(align, 1, 2, idx, idx + 1,
339
 
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
340
 
            align.show()
341
 
 
342
 
            hbox = gtk.HBox(False, spacing=6)
343
 
            align.add(hbox)
344
 
            hbox.show()
345
 
 
346
 
            image = gtk.Image()
347
 
            image.set_from_stock(
348
 
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
349
 
            image.show()
350
 
 
351
 
            button = gtk.Button()
352
 
            button.add(image)
353
 
            button.set_sensitive(self.app is not None)
354
 
            button.connect("clicked", self._show_clicked_cb,
355
 
                           revision.revision_id, parent_id)
356
 
            hbox.pack_start(button, expand=False, fill=True)
357
 
            button.show()
358
 
 
359
 
            button = gtk.Button(parent_id)
360
 
            button.set_use_underline(False)
361
 
            button.connect("clicked", self._go_clicked_cb, parent_id)
362
 
            hbox.pack_start(button, expand=False, fill=True)
363
 
            button.show()
364
 
 
 
212
        self.treeview.get_selection().select_path(0)
 
213
        self.loading_msg_box.hide()
 
214
        return False
 
215
    
 
216
    def _treeselection_changed_cb(self, selection, *args):
 
217
        """Callback for when the treeview changes."""
 
218
        (model, selected_rows) = selection.get_selected_rows()
 
219
        if len(selected_rows) > 0:
 
220
            iter = self.model.get_iter(selected_rows[0])
 
221
            revision = self.model.get_value(iter, treemodel.REVISION)
 
222
            parents = self.model.get_value(iter, treemodel.PARENTS)
 
223
            children = self.model.get_value(iter, treemodel.CHILDREN)
 
224
            
 
225
            self.back_button.set_sensitive(len(parents) > 0)
 
226
            self.fwd_button.set_sensitive(len(children) > 0)
 
227
            tags = []
 
228
            if self.branch.supports_tags():
 
229
                tagdict = self.branch.tags.get_reverse_tag_dict()
 
230
                if tagdict.has_key(revision.revision_id):
 
231
                    tags = tagdict[revision.revision_id]
 
232
            self.logview.set_revision(revision, tags, children)
365
233
 
366
234
    def _back_clicked_cb(self, *args):
367
235
        """Callback for when the back button is clicked."""
368
236
        (path, col) = self.treeview.get_cursor()
369
237
        revision = self.model[path][0]
370
 
        if not len(self.parent_ids[revision]):
 
238
        parents = self.model[path][4]
 
239
        if not len(parents):
371
240
            return
372
241
 
373
 
        for parent_id in self.parent_ids[revision]:
374
 
            parent = self.revisions[parent_id]
 
242
        for parent_id in parents:
 
243
            parent = self.revisions[self.index[parent_id]]
375
244
            if same_branch(revision, parent):
376
 
                self.treeview.set_cursor(self.index[parent])
 
245
                self.treeview.set_cursor(self.index[parent_id])
377
246
                break
378
247
        else:
379
 
            next = self.revisions[self.parent_ids[revision][0]]
380
 
            self.treeview.set_cursor(self.index[next])
 
248
            self.treeview.set_cursor(self.index[parents[0]])
381
249
        self.treeview.grab_focus()
382
250
 
383
251
    def _fwd_clicked_cb(self, *args):
384
252
        """Callback for when the forward button is clicked."""
385
253
        (path, col) = self.treeview.get_cursor()
386
254
        revision = self.model[path][0]
387
 
        if not len(self.children[revision]):
 
255
        children = self.model[path][5]
 
256
        if not len(children):
388
257
            return
389
258
 
390
 
        for child in self.children[revision]:
 
259
        for child_id in children:
 
260
            child = self.revisions[self.index[child_id]]
391
261
            if same_branch(child, revision):
392
 
                self.treeview.set_cursor(self.index[child])
 
262
                self.treeview.set_cursor(self.index[child_id])
393
263
                break
394
264
        else:
395
 
            prev = list(self.children[revision])[0]
396
 
            self.treeview.set_cursor(self.index[prev])
 
265
            self.treeview.set_cursor(self.index[children[0]])
397
266
        self.treeview.grab_focus()
398
267
 
399
 
    def _go_clicked_cb(self, widget, revid):
 
268
    def _go_clicked_cb(self, revid):
400
269
        """Callback for when the go button for a parent is clicked."""
401
 
        self.treeview.set_cursor(self.index[self.revisions[revid]])
 
270
        self.treeview.set_cursor(self.index[revid])
402
271
        self.treeview.grab_focus()
403
272
 
404
 
    def _show_clicked_cb(self, widget, revid, parentid):
 
273
    def show_diff(self, branch, revid, parentid):
 
274
        """Open a new window to show a diff between the given revisions."""
 
275
        from bzrlib.plugins.gtk.diff import DiffWindow
 
276
        window = DiffWindow(parent=self)
 
277
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
 
278
                                                                   revid])
 
279
        description = revid + " - " + branch.nick
 
280
        window.set_diff(description, rev_tree, parent_tree)
 
281
        window.show()
 
282
 
 
283
    def _show_clicked_cb(self, revid, parentid):
405
284
        """Callback for when the show button for a parent is clicked."""
406
 
        if self.app is not None:
407
 
            self.app.show_diff(self.branch, revid, parentid)
 
285
        self.show_diff(self.branch, revid, parentid)
408
286
        self.treeview.grab_focus()
409
287
 
 
288
    def _treeview_row_mouseclick(self, widget, event):
 
289
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
290
        if event.button == 3:
 
291
            menu = RevisionPopupMenu(self.branch.repository, 
 
292
                [x.revision_id for x in self.selected_revisions()],
 
293
                self.branch)
 
294
            menu.popup(None, None, None, event.button, event.get_time())
 
295
 
 
296
    def selected_revision(self, path):
 
297
        return self.model[path][treemodel.REVISION]
 
298
 
 
299
    def selected_revisions(self):
 
300
        return [self.selected_revision(path) for path in \
 
301
                self.treeview.get_selection().get_selected_rows()[1]]
 
302
 
410
303
    def _treeview_row_activated_cb(self, widget, path, col):
411
304
        # TODO: more than one parent
412
305
        """Callback for when a treeview row gets activated."""
413
 
        revision = self.model[path][0]
414
 
        if len(self.parent_ids[revision]) == 0:
 
306
        revision_id = self.model[path][treemodel.REVID]
 
307
        parents = self.model[path][treemodel.PARENTS]
 
308
        if len(parents) == 0:
415
309
            # Ignore revisions without parent
416
310
            return
417
 
        parent_id = self.parent_ids[revision][0]
418
 
        if self.app is not None:
419
 
            self.app.show_diff(self.branch, revision.revision_id, parent_id)
 
311
        parent_id = parents[0]
 
312
        self.show_diff(self.branch, revision_id, parent_id)
420
313
        self.treeview.grab_focus()