/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):
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")
 
35
        self.set_title("Revision history")
33
36
 
34
37
        # Use three-quarters of the screen by default
35
38
        screen = self.get_screen()
53
56
        self.add(vbox)
54
57
 
55
58
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
56
 
 
 
59
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
60
        
57
61
        paned = gtk.VPaned()
58
62
        paned.pack1(self.construct_top(), resize=True, shrink=False)
59
63
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
62
66
        vbox.set_focus_child(paned)
63
67
 
64
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
65
87
 
66
88
    def construct_top(self):
67
89
        """Construct the top-half of the window."""
73
95
        self.treeview = gtk.TreeView()
74
96
        self.treeview.set_rules_hint(True)
75
97
        self.treeview.set_search_column(4)
76
 
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
 
98
        self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
77
99
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
78
100
        self.treeview.connect("button-release-event", 
79
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
148
179
    def construct_bottom(self):
149
180
        """Construct the bottom half of the window."""
150
181
        from bzrlib.plugins.gtk.logview import LogView
151
 
        self.logview = LogView()
 
182
        self.logview = LogView(None, True, [], True)
152
183
        (width, height) = self.get_size()
153
184
        self.logview.set_size_request(width, int(height / 2.5))
154
185
        self.logview.show()
164
195
        treeview itself.
165
196
        """
166
197
        self.branch = branch
167
 
 
168
 
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
169
 
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
170
 
                                   gobject.TYPE_PYOBJECT,
171
 
                                   gobject.TYPE_PYOBJECT,
172
 
                                   gobject.TYPE_PYOBJECT,
173
 
                                   str, str, str)
174
 
        self.index = {}
175
 
        index = 0
176
 
 
177
 
        last_lines = []
178
 
        (self.revisions, colours, self.children, self.parent_ids,
179
 
            merge_sorted) = distances(branch.repository, start)
180
 
        for (index, (revision, node, lines)) in enumerate(graph(
181
 
                self.revisions, colours, merge_sorted)):
182
 
            # FIXME: at this point we should be able to show the graph order
183
 
            # and lines with no message or commit data - and then incrementally
184
 
            # fill the timestamp, committer etc data as desired.
185
 
            message = revision.message.split("\n")[0]
186
 
            if revision.committer is not None:
187
 
                timestamp = format_date(revision.timestamp, revision.timezone)
188
 
            else:
189
 
                timestamp = None
190
 
            self.model.append([revision, node, last_lines, lines,
191
 
                               message, revision.committer, timestamp])
192
 
            self.index[revision] = index
193
 
            last_lines = lines
194
 
            if maxnum is not None and index > maxnum:
195
 
                break
196
 
 
197
 
        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
198
211
        self.treeview.set_model(self.model)
199
 
 
200
 
    def _treeview_cursor_cb(self, *args):
201
 
        """Callback for when the treeview cursor changes."""
202
 
        (path, col) = self.treeview.get_cursor()
203
 
        revision = self.model[path][0]
204
 
 
205
 
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
206
 
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
207
 
        tags = []
208
 
        if self.branch.supports_tags():
209
 
            tagdict = self.branch.tags.get_reverse_tag_dict()
210
 
            if tagdict.has_key(revision.revision_id):
211
 
                tags = tagdict[revision.revision_id]
212
 
        self.logview.set_revision(revision, tags)
 
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)
213
233
 
214
234
    def _back_clicked_cb(self, *args):
215
235
        """Callback for when the back button is clicked."""
216
236
        (path, col) = self.treeview.get_cursor()
217
237
        revision = self.model[path][0]
218
 
        if not len(self.parent_ids[revision]):
 
238
        parents = self.model[path][4]
 
239
        if not len(parents):
219
240
            return
220
241
 
221
 
        for parent_id in self.parent_ids[revision]:
222
 
            parent = self.revisions[parent_id]
 
242
        for parent_id in parents:
 
243
            parent = self.revisions[self.index[parent_id]]
223
244
            if same_branch(revision, parent):
224
 
                self.treeview.set_cursor(self.index[parent])
 
245
                self.treeview.set_cursor(self.index[parent_id])
225
246
                break
226
247
        else:
227
 
            next = self.revisions[self.parent_ids[revision][0]]
228
 
            self.treeview.set_cursor(self.index[next])
 
248
            self.treeview.set_cursor(self.index[parents[0]])
229
249
        self.treeview.grab_focus()
230
250
 
231
251
    def _fwd_clicked_cb(self, *args):
232
252
        """Callback for when the forward button is clicked."""
233
253
        (path, col) = self.treeview.get_cursor()
234
254
        revision = self.model[path][0]
235
 
        if not len(self.children[revision]):
 
255
        children = self.model[path][5]
 
256
        if not len(children):
236
257
            return
237
258
 
238
 
        for child in self.children[revision]:
 
259
        for child_id in children:
 
260
            child = self.revisions[self.index[child_id]]
239
261
            if same_branch(child, revision):
240
 
                self.treeview.set_cursor(self.index[child])
 
262
                self.treeview.set_cursor(self.index[child_id])
241
263
                break
242
264
        else:
243
 
            prev = list(self.children[revision])[0]
244
 
            self.treeview.set_cursor(self.index[prev])
 
265
            self.treeview.set_cursor(self.index[children[0]])
245
266
        self.treeview.grab_focus()
246
267
 
247
268
    def _go_clicked_cb(self, revid):
248
269
        """Callback for when the go button for a parent is clicked."""
249
 
        self.treeview.set_cursor(self.index[self.revisions[revid]])
 
270
        self.treeview.set_cursor(self.index[revid])
250
271
        self.treeview.grab_focus()
251
272
 
252
273
    def show_diff(self, branch, revid, parentid):
253
274
        """Open a new window to show a diff between the given revisions."""
254
275
        from bzrlib.plugins.gtk.diff import DiffWindow
255
 
        window = DiffWindow()
 
276
        window = DiffWindow(parent=self)
256
277
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
257
278
                                                                   revid])
258
279
        description = revid + " - " + branch.nick
273
294
            menu.popup(None, None, None, event.button, event.get_time())
274
295
 
275
296
    def selected_revision(self, path):
276
 
        return self.model[path][0]
 
297
        return self.model[path][treemodel.REVISION]
277
298
 
278
299
    def selected_revisions(self):
279
300
        return [self.selected_revision(path) for path in \
282
303
    def _treeview_row_activated_cb(self, widget, path, col):
283
304
        # TODO: more than one parent
284
305
        """Callback for when a treeview row gets activated."""
285
 
        revision = self.selected_revision(path)
286
 
        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:
287
309
            # Ignore revisions without parent
288
310
            return
289
 
        parent_id = self.parent_ids[revision][0]
290
 
        self.show_diff(self.branch, revision.revision_id, parent_id)
 
311
        parent_id = parents[0]
 
312
        self.show_diff(self.branch, revision_id, parent_id)
291
313
        self.treeview.grab_focus()