/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 branchwin.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:
18
18
 
19
19
from bzrlib.osutils import format_date
20
20
 
21
 
from graph import distances, graph, same_branch
 
21
from graph import graph
22
22
from graphcell import CellRendererGraph
23
23
 
24
24
 
36
36
 
37
37
        # Use three-quarters of the screen by default
38
38
        screen = self.get_screen()
39
 
        monitor = screen.get_monitor_geometry(0)
40
 
        width = int(monitor.width * 0.75)
41
 
        height = int(monitor.height * 0.75)
 
39
        width = int(screen.get_width() * 0.75)
 
40
        height = int(screen.get_height() * 0.75)
42
41
        self.set_default_size(width, height)
43
42
 
44
43
        # FIXME AndyFitz!
45
44
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
46
45
        self.set_icon(icon)
47
46
 
48
 
        self.accel_group = gtk.AccelGroup()
49
 
        self.add_accel_group(self.accel_group)
50
 
 
51
47
        self.construct()
52
48
 
53
49
    def construct(self):
54
50
        """Construct the window contents."""
55
 
        paned = gtk.VPaned()
56
 
        paned.pack1(self.construct_top(), resize=True, shrink=False)
57
 
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
58
 
        self.add(paned)
59
 
        paned.show()
60
 
 
61
 
    def construct_top(self):
62
 
        """Construct the top-half of the window."""
63
 
        vbox = gtk.VBox(spacing=6)
64
 
        vbox.set_border_width(12)
65
 
        vbox.show()
66
 
 
67
51
        scrollwin = gtk.ScrolledWindow()
68
52
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
69
53
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
70
 
        vbox.pack_start(scrollwin, expand=True, fill=True)
 
54
        scrollwin.set_border_width(12)
 
55
        self.add(scrollwin)
71
56
        scrollwin.show()
72
57
 
73
58
        self.treeview = gtk.TreeView()
74
59
        self.treeview.set_rules_hint(True)
75
60
        self.treeview.set_search_column(4)
76
 
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
77
61
        scrollwin.add(self.treeview)
78
62
        self.treeview.show()
79
63
 
112
96
        column.add_attribute(cell, "text", 6)
113
97
        self.treeview.append_column(column)
114
98
 
115
 
        hbox = gtk.HBox(False, spacing=6)
116
 
        vbox.pack_start(hbox, expand=False, fill=False)
117
 
        hbox.show()
118
 
 
119
 
        self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
120
 
        self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
121
 
                                         0, 0)
122
 
        self.back_button.connect("clicked", self._back_clicked_cb)
123
 
        hbox.pack_start(self.back_button, expand=False, fill=True)
124
 
        self.back_button.show()
125
 
 
126
 
        self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
127
 
        self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
128
 
                                        0, 0)
129
 
        self.fwd_button.connect("clicked", self._fwd_clicked_cb)
130
 
        hbox.pack_start(self.fwd_button, expand=False, fill=True)
131
 
        self.fwd_button.show()
132
 
 
133
 
        return vbox
134
 
 
135
 
    def construct_bottom(self):
136
 
        """Construct the bottom half of the window."""
137
 
        vbox = gtk.VBox(False, spacing=6)
138
 
        vbox.set_border_width(12)
139
 
        (width, height) = self.get_size()
140
 
        vbox.set_size_request(width, int(height / 2.5))
141
 
        vbox.show()
142
 
 
143
 
        self.table = gtk.Table(rows=4, columns=2)
144
 
        self.table.set_row_spacings(6)
145
 
        self.table.set_col_spacings(6)
146
 
        vbox.pack_start(self.table, expand=False, fill=True)
147
 
        self.table.show()
148
 
 
149
 
        align = gtk.Alignment(0.0, 0.5)
150
 
        label = gtk.Label()
151
 
        label.set_markup("<b>Revision:</b>")
152
 
        align.add(label)
153
 
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
154
 
        label.show()
155
 
        align.show()
156
 
 
157
 
        align = gtk.Alignment(0.0, 0.5)
158
 
        self.revid_label = gtk.Label()
159
 
        self.revid_label.set_selectable(True)
160
 
        align.add(self.revid_label)
161
 
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
162
 
        self.revid_label.show()
163
 
        align.show()
164
 
 
165
 
        align = gtk.Alignment(0.0, 0.5)
166
 
        label = gtk.Label()
167
 
        label.set_markup("<b>Committer:</b>")
168
 
        align.add(label)
169
 
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
170
 
        label.show()
171
 
        align.show()
172
 
 
173
 
        align = gtk.Alignment(0.0, 0.5)
174
 
        self.committer_label = gtk.Label()
175
 
        self.committer_label.set_selectable(True)
176
 
        align.add(self.committer_label)
177
 
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
178
 
        self.committer_label.show()
179
 
        align.show()
180
 
 
181
 
        align = gtk.Alignment(0.0, 0.5)
182
 
        label = gtk.Label()
183
 
        label.set_markup("<b>Timestamp:</b>")
184
 
        align.add(label)
185
 
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
186
 
        label.show()
187
 
        align.show()
188
 
 
189
 
        align = gtk.Alignment(0.0, 0.5)
190
 
        self.timestamp_label = gtk.Label()
191
 
        self.timestamp_label.set_selectable(True)
192
 
        align.add(self.timestamp_label)
193
 
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
194
 
        self.timestamp_label.show()
195
 
        align.show()
196
 
 
197
 
        align = gtk.Alignment(0.0, 0.5)
198
 
        label = gtk.Label()
199
 
        label.set_markup("<b>Parents:</b>")
200
 
        align.add(label)
201
 
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
202
 
        label.show()
203
 
        align.show()
204
 
 
205
 
        self.parents_widgets = []
206
 
 
207
 
        scrollwin = gtk.ScrolledWindow()
208
 
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
209
 
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
210
 
        vbox.pack_start(scrollwin, expand=True, fill=True)
211
 
        scrollwin.show()
212
 
 
213
 
        self.message_buffer = gtk.TextBuffer()
214
 
        textview = gtk.TextView(self.message_buffer)
215
 
        textview.set_editable(False)
216
 
        textview.set_wrap_mode(gtk.WRAP_WORD)
217
 
        textview.modify_font(pango.FontDescription("Monospace"))
218
 
        scrollwin.add(textview)
219
 
        textview.show()
220
 
 
221
 
        return vbox
222
 
 
223
99
    def set_branch(self, branch, start):
224
100
        """Set the branch and start position for this window.
225
101
 
228
104
        treeview itself.
229
105
        """
230
106
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
231
 
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
232
 
                                   gobject.TYPE_PYOBJECT,
233
 
                                   gobject.TYPE_PYOBJECT,
234
 
                                   gobject.TYPE_PYOBJECT,
235
 
                                   str, str, str)
236
 
        self.index = {}
237
 
        index = 0
 
107
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
108
                              gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
109
                              str, str, str)
238
110
 
239
111
        last_lines = []
240
 
        (revids, self.revisions, colours, self.children) \
241
 
                 = distances(branch, start)
242
 
        for revision, node, lines in graph(revids, self.revisions, colours):
 
112
        for revision, node, lines in graph(branch, start):
243
113
            message = revision.message.split("\n")[0]
244
114
            if revision.committer is not None:
245
115
                timestamp = format_date(revision.timestamp, revision.timezone)
246
116
            else:
247
117
                timestamp = None
248
118
 
249
 
            self.model.append([ revision, node, last_lines, lines,
250
 
                                message, revision.committer, timestamp ])
251
 
            self.index[revision] = index
252
 
            index += 1
253
 
 
 
119
            model.append([ revision, node, last_lines, lines,
 
120
                           message, revision.committer, timestamp ])
254
121
            last_lines = lines
255
122
 
256
123
        self.set_title(os.path.basename(branch.base) + " - bzrk")
257
 
        self.treeview.set_model(self.model)
258
 
 
259
 
    def _treeview_cursor_cb(self, *args):
260
 
        """Callback for when the treeview cursor changes."""
261
 
        (path, col) = self.treeview.get_cursor()
262
 
        revision = self.model[path][0]
263
 
 
264
 
        self.back_button.set_sensitive(len(revision.parent_ids) > 0)
265
 
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
266
 
 
267
 
        if revision.committer is not None:
268
 
            committer = revision.committer
269
 
            timestamp = format_date(revision.timestamp, revision.timezone)
270
 
            message = revision.message
271
 
        else:
272
 
            committer = ""
273
 
            timestamp = ""
274
 
            message = ""
275
 
 
276
 
        self.revid_label.set_text(revision.revision_id)
277
 
        self.committer_label.set_text(committer)
278
 
        self.timestamp_label.set_text(timestamp)
279
 
        self.message_buffer.set_text(message)
280
 
 
281
 
        for widget in self.parents_widgets:
282
 
            self.table.remove(widget)
283
 
 
284
 
        self.parents_widgets = []
285
 
        self.table.resize(4 + len(revision.parent_ids) - 1, 2)
286
 
        for idx, parent_id in enumerate(revision.parent_ids):
287
 
            self.table.set_row_spacing(idx + 3, 0)
288
 
 
289
 
            align = gtk.Alignment(0.0, 0.0)
290
 
            self.parents_widgets.append(align)
291
 
            self.table.attach(align, 1, 2, idx + 3, idx + 4,
292
 
                              gtk.EXPAND | gtk.FILL, gtk.FILL)
293
 
            align.show()
294
 
 
295
 
            hbox = gtk.HBox(False, 0)
296
 
            align.add(hbox)
297
 
            hbox.show()
298
 
 
299
 
            label = gtk.Label(parent_id)
300
 
            label.set_selectable(True)
301
 
            hbox.pack_start(label, expand=False, fill=True)
302
 
            label.show()
303
 
 
304
 
            image = gtk.Image()
305
 
            image.set_from_stock(gtk.STOCK_JUMP_TO, gtk.ICON_SIZE_MENU)
306
 
            image.show()
307
 
 
308
 
            button = gtk.Button()
309
 
            button.add(image)
310
 
            button.set_relief(gtk.RELIEF_NONE)
311
 
            button.connect("clicked", self._go_clicked_cb, parent_id)
312
 
            hbox.pack_start(button, expand=False, fill=True)
313
 
            button.show()
314
 
 
315
 
            image = gtk.Image()
316
 
            image.set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)
317
 
            image.show()
318
 
 
319
 
            button = gtk.Button()
320
 
            button.add(image)
321
 
            button.set_relief(gtk.RELIEF_NONE)
322
 
            button.set_sensitive(False)
323
 
            button.connect("clicked", self._show_clicked_cb, parent_id)
324
 
            hbox.pack_start(button, expand=False, fill=True)
325
 
            button.show()
326
 
 
327
 
    def _back_clicked_cb(self, *args):
328
 
        """Callback for when the back button is clicked."""
329
 
        (path, col) = self.treeview.get_cursor()
330
 
        revision = self.model[path][0]
331
 
        if not len(revision.parent_ids):
332
 
            return
333
 
 
334
 
        for parent_id in revision.parent_ids:
335
 
            parent = self.revisions[parent_id]
336
 
            if same_branch(revision, parent):
337
 
                self.treeview.set_cursor(self.index[parent])
338
 
                break
339
 
        else:
340
 
            next = self.revisions[revision.parent_ids[0]]
341
 
            self.treeview.set_cursor(self.index[next])
342
 
 
343
 
    def _fwd_clicked_cb(self, *args):
344
 
        """Callback for when the forward button is clicked."""
345
 
        (path, col) = self.treeview.get_cursor()
346
 
        revision = self.model[path][0]
347
 
        if not len(self.children[revision]):
348
 
            return
349
 
 
350
 
        for child in self.children[revision]:
351
 
            if same_branch(child, revision):
352
 
                self.treeview.set_cursor(self.index[child])
353
 
                break
354
 
        else:
355
 
            prev = list(self.children[revision])[0]
356
 
            self.treeview.set_cursor(self.index[prev])
357
 
 
358
 
    def _go_clicked_cb(self, widget, revid):
359
 
        """Callback for when the go button for a parent is clicked."""
360
 
        self.treeview.set_cursor(self.index[self.revisions[revid]])
361
 
 
362
 
    def _show_clicked_cb(self, widget, revid):
363
 
        """Callback for when the show button for a parent is clicked."""
364
 
        print "SHOW %s" % revid
 
124
        self.treeview.set_model(model)