/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: 2007-07-15 15:22:29 UTC
  • Revision ID: jelmer@samba.org-20070715152229-clmlen0vpd8d2pzx
Add docstrings, remove unused code.

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
16
15
 
17
 
from bzrlib.plugins.gtk.window import Window
18
16
from bzrlib.osutils import format_date
19
17
 
20
 
from linegraph import linegraph, same_branch
 
18
from graph import distances, graph, same_branch
21
19
from graphcell import CellRendererGraph
22
 
from treemodel import TreeModel
23
 
 
24
 
 
25
 
class BranchWindow(Window):
 
20
 
 
21
 
 
22
class BranchWindow(gtk.Window):
26
23
    """Branch window.
27
24
 
28
25
    This object represents and manages a single window containing information
29
26
    for a particular branch.
30
27
    """
31
28
 
32
 
    def __init__(self, parent=None):
33
 
        Window.__init__(self, parent=parent)
 
29
    def __init__(self):
 
30
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
34
31
        self.set_border_width(0)
35
 
        self.set_title("Revision history")
 
32
        self.set_title("bzrk")
36
33
 
37
34
        # Use three-quarters of the screen by default
38
35
        screen = self.get_screen()
56
53
        self.add(vbox)
57
54
 
58
55
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
59
 
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
60
 
        
 
56
 
61
57
        paned = gtk.VPaned()
62
58
        paned.pack1(self.construct_top(), resize=True, shrink=False)
63
59
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
66
62
        vbox.set_focus_child(paned)
67
63
 
68
64
        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
87
65
 
88
66
    def construct_top(self):
89
67
        """Construct the top-half of the window."""
95
73
        self.treeview = gtk.TreeView()
96
74
        self.treeview.set_rules_hint(True)
97
75
        self.treeview.set_search_column(4)
98
 
        self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
 
76
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
99
77
        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)
103
78
        scrollwin.add(self.treeview)
104
79
        self.treeview.show()
105
80
 
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")
 
81
        cell = CellRendererGraph()
 
82
        column = gtk.TreeViewColumn()
110
83
        column.set_resizable(True)
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)
 
84
        column.pack_start(cell, expand=False)
 
85
        column.add_attribute(cell, "node", 1)
 
86
        column.add_attribute(cell, "in-lines", 2)
 
87
        column.add_attribute(cell, "out-lines", 3)
115
88
        self.treeview.append_column(column)
116
89
 
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
 
 
127
90
        cell = gtk.CellRendererText()
128
 
        cell.set_property("width-chars", 65)
 
91
        cell.set_property("width-chars", 40)
129
92
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
130
93
        column = gtk.TreeViewColumn("Message")
131
94
        column.set_resizable(True)
132
 
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
133
 
        column.set_fixed_width(cell.get_size(self.treeview)[2])
134
95
        column.pack_start(cell, expand=True)
135
 
        column.add_attribute(cell, "text", treemodel.MESSAGE)
 
96
        column.add_attribute(cell, "text", 4)
136
97
        self.treeview.append_column(column)
137
98
 
138
99
        cell = gtk.CellRendererText()
139
 
        cell.set_property("width-chars", 15)
 
100
        cell.set_property("width-chars", 40)
140
101
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
141
102
        column = gtk.TreeViewColumn("Committer")
142
103
        column.set_resizable(True)
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)
 
104
        column.pack_start(cell, expand=True)
 
105
        column.add_attribute(cell, "text", 5)
 
106
        self.treeview.append_column(column)
 
107
 
 
108
        cell = gtk.CellRendererText()
 
109
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
110
        column = gtk.TreeViewColumn("Date")
 
111
        column.set_resizable(True)
 
112
        column.pack_start(cell, expand=True)
 
113
        column.add_attribute(cell, "text", 6)
147
114
        self.treeview.append_column(column)
148
115
 
149
116
        return scrollwin
179
146
    def construct_bottom(self):
180
147
        """Construct the bottom half of the window."""
181
148
        from bzrlib.plugins.gtk.logview import LogView
182
 
        self.logview = LogView(None, True, [], True)
 
149
        self.logview = LogView()
183
150
        (width, height) = self.get_size()
184
151
        self.logview.set_size_request(width, int(height / 2.5))
185
152
        self.logview.show()
195
162
        treeview itself.
196
163
        """
197
164
        self.branch = branch
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
 
165
 
 
166
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
 
167
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
 
168
                                   gobject.TYPE_PYOBJECT,
 
169
                                   gobject.TYPE_PYOBJECT,
 
170
                                   gobject.TYPE_PYOBJECT,
 
171
                                   str, str, str)
 
172
        self.index = {}
 
173
        index = 0
 
174
 
 
175
        last_lines = []
 
176
        (self.revisions, colours, self.children, self.parent_ids,
 
177
         merge_sorted) = distances(branch, start)
 
178
        for (index, (revision, node, lines)) in enumerate(graph(
 
179
                self.revisions, colours, merge_sorted)):
 
180
            # FIXME: at this point we should be able to show the graph order
 
181
            # and lines with no message or commit data - and then incrementally
 
182
            # fill the timestamp, committer etc data as desired.
 
183
            message = revision.message.split("\n")[0]
 
184
            if revision.committer is not None:
 
185
                timestamp = format_date(revision.timestamp, revision.timezone)
 
186
            else:
 
187
                timestamp = None
 
188
            self.model.append([revision, node, last_lines, lines,
 
189
                               message, revision.committer, timestamp])
 
190
            self.index[revision] = index
 
191
            last_lines = lines
 
192
            if maxnum is not None and index > maxnum:
 
193
                break
 
194
 
 
195
        self.set_title(branch.nick + " - bzrk")
211
196
        self.treeview.set_model(self.model)
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)
 
197
 
 
198
    def _treeview_cursor_cb(self, *args):
 
199
        """Callback for when the treeview cursor changes."""
 
200
        (path, col) = self.treeview.get_cursor()
 
201
        revision = self.model[path][0]
 
202
 
 
203
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
 
204
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
 
205
        self.logview.set_revision(revision)
233
206
 
234
207
    def _back_clicked_cb(self, *args):
235
208
        """Callback for when the back button is clicked."""
236
209
        (path, col) = self.treeview.get_cursor()
237
210
        revision = self.model[path][0]
238
 
        parents = self.model[path][4]
239
 
        if not len(parents):
 
211
        if not len(self.parent_ids[revision]):
240
212
            return
241
213
 
242
 
        for parent_id in parents:
243
 
            parent = self.revisions[self.index[parent_id]]
 
214
        for parent_id in self.parent_ids[revision]:
 
215
            parent = self.revisions[parent_id]
244
216
            if same_branch(revision, parent):
245
 
                self.treeview.set_cursor(self.index[parent_id])
 
217
                self.treeview.set_cursor(self.index[parent])
246
218
                break
247
219
        else:
248
 
            self.treeview.set_cursor(self.index[parents[0]])
 
220
            next = self.revisions[self.parent_ids[revision][0]]
 
221
            self.treeview.set_cursor(self.index[next])
249
222
        self.treeview.grab_focus()
250
223
 
251
224
    def _fwd_clicked_cb(self, *args):
252
225
        """Callback for when the forward button is clicked."""
253
226
        (path, col) = self.treeview.get_cursor()
254
227
        revision = self.model[path][0]
255
 
        children = self.model[path][5]
256
 
        if not len(children):
 
228
        if not len(self.children[revision]):
257
229
            return
258
230
 
259
 
        for child_id in children:
260
 
            child = self.revisions[self.index[child_id]]
 
231
        for child in self.children[revision]:
261
232
            if same_branch(child, revision):
262
 
                self.treeview.set_cursor(self.index[child_id])
 
233
                self.treeview.set_cursor(self.index[child])
263
234
                break
264
235
        else:
265
 
            self.treeview.set_cursor(self.index[children[0]])
 
236
            prev = list(self.children[revision])[0]
 
237
            self.treeview.set_cursor(self.index[prev])
266
238
        self.treeview.grab_focus()
267
239
 
268
240
    def _go_clicked_cb(self, revid):
269
241
        """Callback for when the go button for a parent is clicked."""
270
 
        self.treeview.set_cursor(self.index[revid])
 
242
        self.treeview.set_cursor(self.index[self.revisions[revid]])
271
243
        self.treeview.grab_focus()
272
244
 
273
245
    def show_diff(self, branch, revid, parentid):
274
246
        """Open a new window to show a diff between the given revisions."""
275
247
        from bzrlib.plugins.gtk.diff import DiffWindow
276
 
        window = DiffWindow(parent=self)
277
 
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
278
 
                                                                   revid])
 
248
        window = DiffWindow()
 
249
        rev_tree = branch.repository.revision_tree(revid)
 
250
        parent_tree = branch.repository.revision_tree(parentid)
279
251
        description = revid + " - " + branch.nick
280
252
        window.set_diff(description, rev_tree, parent_tree)
281
253
        window.show()
285
257
        self.show_diff(self.branch, revid, parentid)
286
258
        self.treeview.grab_focus()
287
259
 
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
 
 
303
260
    def _treeview_row_activated_cb(self, widget, path, col):
304
261
        # TODO: more than one parent
305
262
        """Callback for when a treeview row gets activated."""
306
 
        revision_id = self.model[path][treemodel.REVID]
307
 
        parents = self.model[path][treemodel.PARENTS]
308
 
        if len(parents) == 0:
 
263
        revision = self.model[path][0]
 
264
        if len(self.parent_ids[revision]) == 0:
309
265
            # Ignore revisions without parent
310
266
            return
311
 
        parent_id = parents[0]
312
 
        self.show_diff(self.branch, revision_id, parent_id)
 
267
        parent_id = self.parent_ids[revision][0]
 
268
        self.show_diff(self.branch, revision.revision_id, parent_id)
313
269
        self.treeview.grab_focus()