/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: John Arbash Meinel
  • Date: 2007-10-30 20:36:16 UTC
  • mfrom: (322.1.1 trunk)
  • mto: (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071030203616-op14zvvmflw6ds1n
Merge in Jelmer's trunk update + conflict resolution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import pango
15
15
import treemodel
16
16
 
 
17
from bzrlib.plugins.gtk.window import Window
17
18
from bzrlib.osutils import format_date
18
19
 
19
20
from linegraph import linegraph, same_branch
20
21
from graphcell import CellRendererGraph
21
22
from treemodel import TreeModel
22
 
 
23
 
 
24
 
class BranchWindow(gtk.Window):
 
23
from treeview  import TreeView
 
24
 
 
25
class BranchWindow(Window):
25
26
    """Branch window.
26
27
 
27
28
    This object represents and manages a single window containing information
28
29
    for a particular branch.
29
30
    """
30
31
 
31
 
    def __init__(self, parent=None):
32
 
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
 
32
    def __init__(self, branch, start, maxnum, parent=None):
 
33
        """Create a new BranchWindow.
 
34
 
 
35
        :param branch: Branch object for branch to show.
 
36
        :param start: Revision id of top revision.
 
37
        :param maxnum: Maximum number of revisions to display, 
 
38
                       None for no limit.
 
39
        """
 
40
 
 
41
        Window.__init__(self, parent=parent)
33
42
        self.set_border_width(0)
34
 
        self.set_title("bzrk")
35
 
 
36
 
        self._parent = parent
37
 
 
38
 
        self.connect('key-press-event', self._on_key_pressed)
 
43
 
 
44
        self.branch = branch
 
45
        self.start  = start
 
46
        self.maxnum = maxnum
 
47
 
 
48
        self.set_title(branch.nick + " - revision history")
39
49
 
40
50
        # Use three-quarters of the screen by default
41
51
        screen = self.get_screen()
59
69
        self.add(vbox)
60
70
 
61
71
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
62
 
 
 
72
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
73
        
63
74
        paned = gtk.VPaned()
64
75
        paned.pack1(self.construct_top(), resize=True, shrink=False)
65
76
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
68
79
        vbox.set_focus_child(paned)
69
80
 
70
81
        vbox.show()
 
82
    
 
83
    def construct_loading_msg(self):
 
84
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
85
                                                 gtk.ICON_SIZE_BUTTON)
 
86
        image_loading.show()
 
87
        
 
88
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
 
89
        label_loading.set_alignment(0.0, 0.5)        
 
90
        label_loading.show()
 
91
        
 
92
        self.loading_msg_box = gtk.HBox()
 
93
        self.loading_msg_box.set_spacing(5)
 
94
        self.loading_msg_box.set_border_width(5)        
 
95
        self.loading_msg_box.pack_start(image_loading, False, False)
 
96
        self.loading_msg_box.pack_start(label_loading, True, True)
 
97
        self.loading_msg_box.show()
 
98
        
 
99
        return self.loading_msg_box
71
100
 
72
101
    def construct_top(self):
73
102
        """Construct the top-half of the window."""
74
 
        scrollwin = gtk.ScrolledWindow()
75
 
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
76
 
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
77
 
        scrollwin.show()
78
 
 
79
 
        self.treeview = gtk.TreeView()
80
 
        self.treeview.set_rules_hint(True)
81
 
        self.treeview.set_search_column(4)
82
 
        self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
83
 
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
84
 
        self.treeview.connect("button-release-event", 
85
 
                self._treeview_row_mouseclick)
86
 
        self.treeview.set_property('fixed-height-mode', True)
87
 
        scrollwin.add(self.treeview)
 
103
        self.treeview = TreeView(self.branch, self.start, self.maxnum)
 
104
 
 
105
        self.treeview.connect("revision-selected",
 
106
                self._treeselection_changed_cb)
 
107
 
 
108
        self.treeview.connect('revisions-loaded', 
 
109
                lambda x: self.loading_msg_box.hide())
 
110
 
88
111
        self.treeview.show()
89
112
 
90
 
        cell = gtk.CellRendererText()
91
 
        cell.set_property("width-chars", 15)
92
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
93
 
        column = gtk.TreeViewColumn("Revision No")
94
 
        column.set_resizable(True)
95
 
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
96
 
        column.set_fixed_width(cell.get_size(self.treeview)[2])
97
 
        column.pack_start(cell, expand=True)
98
 
        column.add_attribute(cell, "text", treemodel.REVNO)
99
 
        self.treeview.append_column(column)
100
 
 
101
 
        self.graph_cell = CellRendererGraph()
102
 
        self.graph_column = gtk.TreeViewColumn()
103
 
        self.graph_column.set_resizable(True)
104
 
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
105
 
        self.graph_column.pack_start(self.graph_cell, expand=False)
106
 
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
107
 
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
108
 
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
109
 
        self.treeview.append_column(self.graph_column)
110
 
 
111
 
        cell = gtk.CellRendererText()
112
 
        cell.set_property("width-chars", 40)
113
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
114
 
        column = gtk.TreeViewColumn("Message")
115
 
        column.set_resizable(True)
116
 
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
117
 
        column.set_fixed_width(cell.get_size(self.treeview)[2])
118
 
        column.pack_start(cell, expand=True)
119
 
        column.add_attribute(cell, "text", treemodel.MESSAGE)
120
 
        self.treeview.append_column(column)
121
 
 
122
 
        cell = gtk.CellRendererText()
123
 
        cell.set_property("width-chars", 40)
124
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
125
 
        column = gtk.TreeViewColumn("Committer")
126
 
        column.set_resizable(True)
127
 
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
128
 
        column.set_fixed_width(cell.get_size(self.treeview)[2])
129
 
        column.pack_start(cell, expand=True)
130
 
        column.add_attribute(cell, "text", treemodel.COMMITER)
131
 
        self.treeview.append_column(column)
132
 
 
133
 
        cell = gtk.CellRendererText()
134
 
        cell.set_property("width-chars", 40)
135
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
136
 
        column = gtk.TreeViewColumn("Date")
137
 
        column.set_resizable(True)
138
 
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
139
 
        column.set_fixed_width(cell.get_size(self.treeview)[2])
140
 
        column.pack_start(cell, expand=True)
141
 
        column.add_attribute(cell, "text", treemodel.TIMESTAMP)
142
 
        self.treeview.append_column(column)
143
 
 
144
 
        return scrollwin
 
113
        return self.treeview
145
114
 
146
115
    def construct_navigation(self):
147
116
        """Construct the navigation buttons."""
181
150
        self.logview.set_show_callback(self._show_clicked_cb)
182
151
        self.logview.set_go_callback(self._go_clicked_cb)
183
152
        return self.logview
184
 
 
185
 
    def set_branch(self, branch, start, maxnum):
186
 
        """Set the branch and start position for this window.
187
 
 
188
 
        Creates a new TreeModel and populates it with information about
189
 
        the new branch before updating the window title and model of the
190
 
        treeview itself.
191
 
        """
192
 
        self.branch = branch
193
 
        self.set_title(branch.nick + " - bzrk")
194
 
        gobject.idle_add(self.populate_model, start, maxnum)
195
 
 
196
 
    def populate_model(self, start, maxnum):
197
 
        (linegraphdata, index, columns_len) = linegraph(self.branch,
198
 
                                                        start,
199
 
                                                        maxnum)
200
 
        self.model = TreeModel(self.branch, linegraphdata)
201
 
        self.graph_cell.columns_len = columns_len
202
 
        width = self.graph_cell.get_size(self.treeview)[2]
203
 
        self.graph_column.set_fixed_width(width)
204
 
        self.graph_column.set_max_width(width)
205
 
        self.index = index
206
 
        self.treeview.set_model(self.model)
207
 
        self.treeview.get_selection().select_path(0)
208
 
        return False
209
 
    
210
 
    def _on_key_pressed(self, widget, event):
211
 
        """ Key press event handler. """
212
 
        keyname = gtk.gdk.keyval_name(event.keyval)
213
 
        func = getattr(self, '_on_key_press_' + keyname, None)
214
 
        if func:
215
 
            return func(event)
216
 
 
217
 
    def _on_key_press_w(self, event):
218
 
        if event.state & gtk.gdk.CONTROL_MASK:
219
 
            self.destroy()
220
 
            if self._parent is None:
221
 
                gtk.main_quit()
222
 
 
223
 
    def _on_key_press_q(self, event):
224
 
        if event.state & gtk.gdk.CONTROL_MASK:
225
 
            gtk.main_quit()
226
153
    
227
154
    def _treeselection_changed_cb(self, selection, *args):
228
 
        """Callback for when the treeview changes."""
229
 
        (model, selected_rows) = selection.get_selected_rows()
230
 
        if len(selected_rows) > 0:
231
 
            iter = self.model.get_iter(selected_rows[0])
232
 
            revision = self.model.get_value(iter, treemodel.REVISION)
233
 
            parents = self.model.get_value(iter, treemodel.PARENTS)
234
 
            children = self.model.get_value(iter, treemodel.CHILDREN)
235
 
            
 
155
        """callback for when the treeview changes."""
 
156
        revision = self.treeview.get_revision()
 
157
        parents  = self.treeview.get_parents()
 
158
        children = self.treeview.get_children()
 
159
 
 
160
        if revision is not None:
236
161
            self.back_button.set_sensitive(len(parents) > 0)
237
162
            self.fwd_button.set_sensitive(len(children) > 0)
238
163
            tags = []
244
169
 
245
170
    def _back_clicked_cb(self, *args):
246
171
        """Callback for when the back button is clicked."""
247
 
        (path, col) = self.treeview.get_cursor()
248
 
        revision = self.model[path][0]
249
 
        parents = self.model[path][4]
250
 
        if not len(parents):
251
 
            return
252
 
 
253
 
        for parent_id in parents:
254
 
            parent = self.revisions[self.index[parent_id]]
255
 
            if same_branch(revision, parent):
256
 
                self.treeview.set_cursor(self.index[parent_id])
257
 
                break
258
 
        else:
259
 
            self.treeview.set_cursor(self.index[parents[0]])
260
 
        self.treeview.grab_focus()
261
 
 
 
172
        self.treeview.back()
 
173
        
262
174
    def _fwd_clicked_cb(self, *args):
263
175
        """Callback for when the forward button is clicked."""
264
 
        (path, col) = self.treeview.get_cursor()
265
 
        revision = self.model[path][0]
266
 
        children = self.model[path][5]
267
 
        if not len(children):
268
 
            return
269
 
 
270
 
        for child_id in children:
271
 
            child = self.revisions[self.index[child_id]]
272
 
            if same_branch(child, revision):
273
 
                self.treeview.set_cursor(self.index[child_id])
274
 
                break
275
 
        else:
276
 
            self.treeview.set_cursor(self.index[children[0]])
277
 
        self.treeview.grab_focus()
 
176
        self.treeview.forward()
278
177
 
279
178
    def _go_clicked_cb(self, revid):
280
179
        """Callback for when the go button for a parent is clicked."""
281
 
        self.treeview.set_cursor(self.index[revid])
282
 
        self.treeview.grab_focus()
283
 
 
284
 
    def show_diff(self, branch, revid, parentid):
285
 
        """Open a new window to show a diff between the given revisions."""
286
 
        from bzrlib.plugins.gtk.diff import DiffWindow
287
 
        window = DiffWindow()
288
 
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
289
 
                                                                   revid])
290
 
        description = revid + " - " + branch.nick
291
 
        window.set_diff(description, rev_tree, parent_tree)
292
 
        window.show()
 
180
        self.treeview.set_revision(revid)
293
181
 
294
182
    def _show_clicked_cb(self, revid, parentid):
295
183
        """Callback for when the show button for a parent is clicked."""
296
 
        self.show_diff(self.branch, revid, parentid)
297
 
        self.treeview.grab_focus()
298
 
 
299
 
    def _treeview_row_mouseclick(self, widget, event):
300
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
301
 
        if event.button == 3:
302
 
            menu = RevisionPopupMenu(self.branch.repository, 
303
 
                [x.revision_id for x in self.selected_revisions()],
304
 
                self.branch)
305
 
            menu.popup(None, None, None, event.button, event.get_time())
306
 
 
307
 
    def selected_revision(self, path):
308
 
        return self.model[path][treemodel.REVISION]
309
 
 
310
 
    def selected_revisions(self):
311
 
        return [self.selected_revision(path) for path in \
312
 
                self.treeview.get_selection().get_selected_rows()[1]]
313
 
 
314
 
    def _treeview_row_activated_cb(self, widget, path, col):
315
 
        # TODO: more than one parent
316
 
        """Callback for when a treeview row gets activated."""
317
 
        revision_id = self.model[path][treemodel.REVID]
318
 
        parents = self.model[path][treemodel.PARENTS]
319
 
        if len(parents) == 0:
320
 
            # Ignore revisions without parent
321
 
            return
322
 
        parent_id = parents[0]
323
 
        self.show_diff(self.branch, revision_id, parent_id)
324
 
        self.treeview.grab_focus()
 
184
        self.treeview.show_diff(self.branch, revid, parentid)
 
185
        self.treeview.grab_focus()
 
186