/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:13:34 UTC
  • Revision ID: jelmer@samba.org-20070715151334-2t0g8fmpgj6vnqa7
Add icon for Bazaar preferences.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
1
# -*- coding: UTF-8 -*-
3
2
"""Branch window.
4
3
 
10
9
__author__    = "Scott James Remnant <scott@ubuntu.com>"
11
10
 
12
11
 
13
 
import os
14
 
 
15
12
import gtk
16
13
import gobject
17
14
import pango
36
33
 
37
34
        # Use three-quarters of the screen by default
38
35
        screen = self.get_screen()
39
 
        width = int(screen.get_width() * 0.75)
40
 
        height = int(screen.get_height() * 0.75)
 
36
        monitor = screen.get_monitor_geometry(0)
 
37
        width = int(monitor.width * 0.75)
 
38
        height = int(monitor.height * 0.75)
41
39
        self.set_default_size(width, height)
42
40
 
43
41
        # FIXME AndyFitz!
51
49
 
52
50
    def construct(self):
53
51
        """Construct the window contents."""
 
52
        vbox = gtk.VBox(spacing=0)
 
53
        self.add(vbox)
 
54
 
 
55
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
 
56
 
54
57
        paned = gtk.VPaned()
55
58
        paned.pack1(self.construct_top(), resize=True, shrink=False)
56
 
        paned.pack2(self.construct_bottom(), resize=True, shrink=True)
57
 
        self.add(paned)
 
59
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
58
60
        paned.show()
 
61
        vbox.pack_start(paned, expand=True, fill=True)
 
62
        vbox.set_focus_child(paned)
 
63
 
 
64
        vbox.show()
59
65
 
60
66
    def construct_top(self):
61
67
        """Construct the top-half of the window."""
62
 
        vbox = gtk.VBox(spacing=6)
63
 
        vbox.set_border_width(12)
64
 
        vbox.show()
65
 
 
66
68
        scrollwin = gtk.ScrolledWindow()
67
69
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
68
70
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
69
 
        #scrollwin.set_border_width(12)
70
 
        vbox.pack_start(scrollwin, expand=True, fill=True)
71
71
        scrollwin.show()
72
72
 
73
73
        self.treeview = gtk.TreeView()
74
74
        self.treeview.set_rules_hint(True)
75
75
        self.treeview.set_search_column(4)
76
76
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
 
77
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
77
78
        scrollwin.add(self.treeview)
78
79
        self.treeview.show()
79
80
 
80
81
        cell = CellRendererGraph()
81
82
        column = gtk.TreeViewColumn()
82
 
        column.set_resizable(False)
 
83
        column.set_resizable(True)
83
84
        column.pack_start(cell, expand=False)
84
85
        column.add_attribute(cell, "node", 1)
85
86
        column.add_attribute(cell, "in-lines", 2)
112
113
        column.add_attribute(cell, "text", 6)
113
114
        self.treeview.append_column(column)
114
115
 
115
 
        hbox = gtk.HBox(False, spacing=6)
116
 
        vbox.pack_start(hbox, expand=False, fill=False)
 
116
        return scrollwin
 
117
 
 
118
    def construct_navigation(self):
 
119
        """Construct the navigation buttons."""
 
120
        frame = gtk.Frame()
 
121
        frame.set_shadow_type(gtk.SHADOW_OUT)
 
122
        frame.show()
 
123
        
 
124
        hbox = gtk.HBox(spacing=12)
 
125
        frame.add(hbox)
117
126
        hbox.show()
118
127
 
119
128
        self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
 
129
        self.back_button.set_relief(gtk.RELIEF_NONE)
120
130
        self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
121
131
                                         0, 0)
122
132
        self.back_button.connect("clicked", self._back_clicked_cb)
124
134
        self.back_button.show()
125
135
 
126
136
        self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
 
137
        self.fwd_button.set_relief(gtk.RELIEF_NONE)
127
138
        self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
128
139
                                        0, 0)
129
140
        self.fwd_button.connect("clicked", self._fwd_clicked_cb)
130
141
        hbox.pack_start(self.fwd_button, expand=False, fill=True)
131
142
        self.fwd_button.show()
132
143
 
133
 
        return vbox
 
144
        return frame
134
145
 
135
146
    def construct_bottom(self):
136
147
        """Construct the bottom half of the window."""
137
 
        label = gtk.Label("test")
138
 
        label.show()
139
 
 
140
 
        return label
141
 
 
142
 
    def set_branch(self, branch, start):
 
148
        from bzrlib.plugins.gtk.logview import LogView
 
149
        self.logview = LogView()
 
150
        (width, height) = self.get_size()
 
151
        self.logview.set_size_request(width, int(height / 2.5))
 
152
        self.logview.show()
 
153
        self.logview.set_show_callback(self._show_clicked_cb)
 
154
        self.logview.set_go_callback(self._go_clicked_cb)
 
155
        return self.logview
 
156
 
 
157
    def set_branch(self, branch, start, maxnum):
143
158
        """Set the branch and start position for this window.
144
159
 
145
160
        Creates a new TreeModel and populates it with information about
146
161
        the new branch before updating the window title and model of the
147
162
        treeview itself.
148
163
        """
 
164
        self.branch = branch
 
165
 
149
166
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
150
167
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
151
168
                                   gobject.TYPE_PYOBJECT,
156
173
        index = 0
157
174
 
158
175
        last_lines = []
159
 
        (revids, self.revisions, colours, self.children) \
160
 
                 = distances(branch, start)
161
 
        for revision, node, lines in graph(revids, self.revisions, colours):
 
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.
162
183
            message = revision.message.split("\n")[0]
163
184
            if revision.committer is not None:
164
185
                timestamp = format_date(revision.timestamp, revision.timezone)
165
186
            else:
166
187
                timestamp = None
167
 
 
168
 
            self.model.append([ revision, node, last_lines, lines,
169
 
                                message, revision.committer, timestamp ])
 
188
            self.model.append([revision, node, last_lines, lines,
 
189
                               message, revision.committer, timestamp])
170
190
            self.index[revision] = index
171
 
            index += 1
172
 
 
173
191
            last_lines = lines
 
192
            if maxnum is not None and index > maxnum:
 
193
                break
174
194
 
175
 
        self.set_title(os.path.basename(branch.base) + " - bzrk")
 
195
        self.set_title(branch.nick + " - bzrk")
176
196
        self.treeview.set_model(self.model)
177
197
 
178
198
    def _treeview_cursor_cb(self, *args):
180
200
        (path, col) = self.treeview.get_cursor()
181
201
        revision = self.model[path][0]
182
202
 
183
 
        self.back_button.set_sensitive(len(self.children[revision]) > 0)
184
 
        self.fwd_button.set_sensitive(len(revision.parent_ids) > 0)
 
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)
185
206
 
186
207
    def _back_clicked_cb(self, *args):
187
208
        """Callback for when the back button is clicked."""
188
209
        (path, col) = self.treeview.get_cursor()
189
210
        revision = self.model[path][0]
 
211
        if not len(self.parent_ids[revision]):
 
212
            return
 
213
 
 
214
        for parent_id in self.parent_ids[revision]:
 
215
            parent = self.revisions[parent_id]
 
216
            if same_branch(revision, parent):
 
217
                self.treeview.set_cursor(self.index[parent])
 
218
                break
 
219
        else:
 
220
            next = self.revisions[self.parent_ids[revision][0]]
 
221
            self.treeview.set_cursor(self.index[next])
 
222
        self.treeview.grab_focus()
 
223
 
 
224
    def _fwd_clicked_cb(self, *args):
 
225
        """Callback for when the forward button is clicked."""
 
226
        (path, col) = self.treeview.get_cursor()
 
227
        revision = self.model[path][0]
190
228
        if not len(self.children[revision]):
191
229
            return
192
230
 
197
235
        else:
198
236
            prev = list(self.children[revision])[0]
199
237
            self.treeview.set_cursor(self.index[prev])
200
 
 
201
 
    def _fwd_clicked_cb(self, *args):
202
 
        """Callback for when the forward button is clicked."""
203
 
        (path, col) = self.treeview.get_cursor()
 
238
        self.treeview.grab_focus()
 
239
 
 
240
    def _go_clicked_cb(self, revid):
 
241
        """Callback for when the go button for a parent is clicked."""
 
242
        self.treeview.set_cursor(self.index[self.revisions[revid]])
 
243
        self.treeview.grab_focus()
 
244
 
 
245
    def show_diff(self, branch, revid, parentid):
 
246
        """Open a new window to show a diff between the given revisions."""
 
247
        from bzrlib.plugins.gtk.diff import DiffWindow
 
248
        window = DiffWindow()
 
249
        rev_tree = branch.repository.revision_tree(revid)
 
250
        parent_tree = branch.repository.revision_tree(parentid)
 
251
        description = revid + " - " + branch.nick
 
252
        window.set_diff(description, rev_tree, parent_tree)
 
253
        window.show()
 
254
 
 
255
    def _show_clicked_cb(self, revid, parentid):
 
256
        """Callback for when the show button for a parent is clicked."""
 
257
        self.show_diff(self.branch, revid, parentid)
 
258
        self.treeview.grab_focus()
 
259
 
 
260
    def _treeview_row_activated_cb(self, widget, path, col):
 
261
        # TODO: more than one parent
 
262
        """Callback for when a treeview row gets activated."""
204
263
        revision = self.model[path][0]
205
 
        if not len(revision.parent_ids):
 
264
        if len(self.parent_ids[revision]) == 0:
 
265
            # Ignore revisions without parent
206
266
            return
207
 
 
208
 
        for parent_id in revision.parent_ids:
209
 
            parent = self.revisions[parent_id]
210
 
            if same_branch(revision, parent):
211
 
                self.treeview.set_cursor(self.index[parent])
212
 
                break
213
 
        else:
214
 
            next = self.revisions[revision.parent_ids[0]]
215
 
            self.treeview.set_cursor(self.index[next])
216
 
 
 
267
        parent_id = self.parent_ids[revision][0]
 
268
        self.show_diff(self.branch, revision.revision_id, parent_id)
 
269
        self.treeview.grab_focus()