/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 04:26:00 UTC
  • Revision ID: scott@netsplit.com-20051017042600-b3a3265abfffdf53
Split the display in two with a pane, we'll use the bottom half to show
information about the current revision.  Add a Back and Forward button
which figure out which revision is logically the next of previous and
moves the cursor to it.  Handle the cursor-changed event to enable/disable
the buttons (and soon update the bottom pane).

Further split up graph.py so we can stash the internal lists to do the
above; also it may allow us in future to produce partial graphs.

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 graph
 
21
from graph import distances, graph, same_branch
22
22
from graphcell import CellRendererGraph
23
23
 
24
24
 
44
44
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
45
45
        self.set_icon(icon)
46
46
 
 
47
        self.accel_group = gtk.AccelGroup()
 
48
        self.add_accel_group(self.accel_group)
 
49
 
47
50
        self.construct()
48
51
 
49
52
    def construct(self):
50
53
        """Construct the window contents."""
 
54
        paned = gtk.VPaned()
 
55
        paned.pack1(self.construct_top(), resize=True, shrink=False)
 
56
        paned.pack2(self.construct_bottom(), resize=True, shrink=True)
 
57
        self.add(paned)
 
58
        paned.show()
 
59
 
 
60
    def construct_top(self):
 
61
        """Construct the top-half of the window."""
 
62
        vbox = gtk.VBox(spacing=6)
 
63
        vbox.set_border_width(12)
 
64
        vbox.show()
 
65
 
51
66
        scrollwin = gtk.ScrolledWindow()
52
67
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
53
68
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
54
 
        scrollwin.set_border_width(12)
55
 
        self.add(scrollwin)
 
69
        #scrollwin.set_border_width(12)
 
70
        vbox.pack_start(scrollwin, expand=True, fill=True)
56
71
        scrollwin.show()
57
72
 
58
73
        self.treeview = gtk.TreeView()
59
74
        self.treeview.set_rules_hint(True)
60
75
        self.treeview.set_search_column(4)
 
76
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
61
77
        scrollwin.add(self.treeview)
62
78
        self.treeview.show()
63
79
 
96
112
        column.add_attribute(cell, "text", 6)
97
113
        self.treeview.append_column(column)
98
114
 
 
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
        label = gtk.Label("test")
 
138
        label.show()
 
139
 
 
140
        return label
 
141
 
99
142
    def set_branch(self, branch, start):
100
143
        """Set the branch and start position for this window.
101
144
 
104
147
        treeview itself.
105
148
        """
106
149
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
107
 
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
108
 
                              gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
109
 
                              str, str, str)
 
150
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
 
151
                                   gobject.TYPE_PYOBJECT,
 
152
                                   gobject.TYPE_PYOBJECT,
 
153
                                   gobject.TYPE_PYOBJECT,
 
154
                                   str, str, str)
 
155
        self.index = {}
 
156
        index = 0
110
157
 
111
158
        last_lines = []
112
 
        for revision, node, lines in graph(branch, start):
 
159
        (revids, self.revisions, colours, self.children) \
 
160
                 = distances(branch, start)
 
161
        for revision, node, lines in graph(revids, self.revisions, colours):
113
162
            message = revision.message.split("\n")[0]
114
163
            if revision.committer is not None:
115
164
                timestamp = format_date(revision.timestamp, revision.timezone)
116
165
            else:
117
166
                timestamp = None
118
167
 
119
 
            model.append([ revision, node, last_lines, lines,
120
 
                           message, revision.committer, timestamp ])
 
168
            self.model.append([ revision, node, last_lines, lines,
 
169
                                message, revision.committer, timestamp ])
 
170
            self.index[revision] = index
 
171
            index += 1
 
172
 
121
173
            last_lines = lines
122
174
 
123
175
        self.set_title(os.path.basename(branch.base) + " - bzrk")
124
 
        self.treeview.set_model(model)
 
176
        self.treeview.set_model(self.model)
 
177
 
 
178
    def _treeview_cursor_cb(self, *args):
 
179
        """Callback for when the treeview cursor changes."""
 
180
        (path, col) = self.treeview.get_cursor()
 
181
        revision = self.model[path][0]
 
182
 
 
183
        self.back_button.set_sensitive(len(self.children[revision]) > 0)
 
184
        self.fwd_button.set_sensitive(len(revision.parent_ids) > 0)
 
185
 
 
186
    def _back_clicked_cb(self, *args):
 
187
        """Callback for when the back button is clicked."""
 
188
        (path, col) = self.treeview.get_cursor()
 
189
        revision = self.model[path][0]
 
190
        if not len(self.children[revision]):
 
191
            return
 
192
 
 
193
        for child in self.children[revision]:
 
194
            if same_branch(child, revision):
 
195
                self.treeview.set_cursor(self.index[child])
 
196
                break
 
197
        else:
 
198
            prev = list(self.children[revision])[0]
 
199
            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()
 
204
        revision = self.model[path][0]
 
205
        if not len(revision.parent_ids):
 
206
            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