/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: Szilveszter Farkas (Phanatic)
  • Date: 2007-09-30 21:58:29 UTC
  • mfrom: (256.2.64 gtk)
  • Revision ID: szilveszter.farkas@gmail.com-20070930215829-ty0js2529sni7ziv
Merge the vizchanges/brokenlines branch from Gary.

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
 
16
17
from bzrlib.osutils import format_date
17
18
 
18
 
from graph import distances, graph, same_branch
 
19
from linegraph import linegraph, same_branch
19
20
from graphcell import CellRendererGraph
 
21
from treemodel import TreeModel
20
22
 
21
23
 
22
24
class BranchWindow(gtk.Window):
81
83
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
82
84
        self.treeview.connect("button-release-event", 
83
85
                self._treeview_row_mouseclick)
 
86
        self.treeview.set_property('fixed-height-mode', True)
84
87
        scrollwin.add(self.treeview)
85
88
        self.treeview.show()
86
89
 
87
 
        cell = CellRendererGraph()
88
 
        column = gtk.TreeViewColumn()
 
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")
89
94
        column.set_resizable(True)
90
 
        column.pack_start(cell, expand=False)
91
 
        column.add_attribute(cell, "node", 1)
92
 
        column.add_attribute(cell, "in-lines", 2)
93
 
        column.add_attribute(cell, "out-lines", 3)
 
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)
94
99
        self.treeview.append_column(column)
95
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
 
96
111
        cell = gtk.CellRendererText()
97
112
        cell.set_property("width-chars", 40)
98
113
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
99
114
        column = gtk.TreeViewColumn("Message")
100
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])
101
118
        column.pack_start(cell, expand=True)
102
 
        column.add_attribute(cell, "text", 4)
 
119
        column.add_attribute(cell, "text", treemodel.MESSAGE)
103
120
        self.treeview.append_column(column)
104
121
 
105
122
        cell = gtk.CellRendererText()
107
124
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
108
125
        column = gtk.TreeViewColumn("Committer")
109
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])
110
129
        column.pack_start(cell, expand=True)
111
 
        column.add_attribute(cell, "text", 5)
 
130
        column.add_attribute(cell, "text", treemodel.COMMITER)
112
131
        self.treeview.append_column(column)
113
132
 
114
133
        cell = gtk.CellRendererText()
 
134
        cell.set_property("width-chars", 40)
115
135
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
116
136
        column = gtk.TreeViewColumn("Date")
117
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])
118
140
        column.pack_start(cell, expand=True)
119
 
        column.add_attribute(cell, "text", 6)
 
141
        column.add_attribute(cell, "text", treemodel.TIMESTAMP)
120
142
        self.treeview.append_column(column)
121
143
 
122
144
        return scrollwin
152
174
    def construct_bottom(self):
153
175
        """Construct the bottom half of the window."""
154
176
        from bzrlib.plugins.gtk.logview import LogView
155
 
        self.logview = LogView()
 
177
        self.logview = LogView(None, True, [], True)
156
178
        (width, height) = self.get_size()
157
179
        self.logview.set_size_request(width, int(height / 2.5))
158
180
        self.logview.show()
168
190
        treeview itself.
169
191
        """
170
192
        self.branch = branch
171
 
 
172
 
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
173
 
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
174
 
                                   gobject.TYPE_PYOBJECT,
175
 
                                   gobject.TYPE_PYOBJECT,
176
 
                                   gobject.TYPE_PYOBJECT,
177
 
                                   str, str, str)
178
 
        self.index = {}
179
193
        self.set_title(branch.nick + " - bzrk")
180
194
        gobject.idle_add(self.populate_model, start, maxnum)
181
195
 
182
196
    def populate_model(self, start, maxnum):
183
 
        index = 0
184
 
        
185
 
        last_lines = []
186
 
        (self.revisions, colours, self.children, self.parent_ids,
187
 
            merge_sorted) = distances(self.branch.repository, start,
188
 
                                      maxnum=maxnum)
189
 
        for (index, (revision, node, lines)) in enumerate(graph(
190
 
                self.revisions, colours, merge_sorted)):
191
 
            # FIXME: at this point we should be able to show the graph order
192
 
            # and lines with no message or commit data - and then incrementally
193
 
            # fill the timestamp, committer etc data as desired.
194
 
            message = revision.message.split("\n")[0]
195
 
            if revision.committer is not None:
196
 
                timestamp = format_date(revision.timestamp, revision.timezone)
197
 
            else:
198
 
                timestamp = None
199
 
            self.model.append([revision, node, last_lines, lines,
200
 
                               message, revision.committer, timestamp])
201
 
            self.index[revision] = index
202
 
            last_lines = lines
203
 
            if maxnum is not None and index > maxnum:
204
 
                break
 
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
205
206
        self.treeview.set_model(self.model)
206
207
        self.treeview.get_selection().select_path(0)
207
208
        return False
222
223
    def _on_key_press_q(self, event):
223
224
        if event.state & gtk.gdk.CONTROL_MASK:
224
225
            gtk.main_quit()
225
 
 
 
226
    
226
227
    def _treeselection_changed_cb(self, selection, *args):
227
228
        """Callback for when the treeview changes."""
228
229
        (model, selected_rows) = selection.get_selected_rows()
229
230
        if len(selected_rows) > 0:
230
 
            revision = self.model[selected_rows[0]][0]
231
 
 
232
 
            self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
233
 
            self.fwd_button.set_sensitive(len(self.children[revision]) > 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
            
 
236
            self.back_button.set_sensitive(len(parents) > 0)
 
237
            self.fwd_button.set_sensitive(len(children) > 0)
234
238
            tags = []
235
239
            if self.branch.supports_tags():
236
240
                tagdict = self.branch.tags.get_reverse_tag_dict()
237
241
                if tagdict.has_key(revision.revision_id):
238
242
                    tags = tagdict[revision.revision_id]
239
 
            self.logview.set_revision(revision, tags)
 
243
            self.logview.set_revision(revision, tags, children)
240
244
 
241
245
    def _back_clicked_cb(self, *args):
242
246
        """Callback for when the back button is clicked."""
243
247
        (path, col) = self.treeview.get_cursor()
244
248
        revision = self.model[path][0]
245
 
        if not len(self.parent_ids[revision]):
 
249
        parents = self.model[path][4]
 
250
        if not len(parents):
246
251
            return
247
252
 
248
 
        for parent_id in self.parent_ids[revision]:
249
 
            parent = self.revisions[parent_id]
 
253
        for parent_id in parents:
 
254
            parent = self.revisions[self.index[parent_id]]
250
255
            if same_branch(revision, parent):
251
 
                self.treeview.set_cursor(self.index[parent])
 
256
                self.treeview.set_cursor(self.index[parent_id])
252
257
                break
253
258
        else:
254
 
            next = self.revisions[self.parent_ids[revision][0]]
255
 
            self.treeview.set_cursor(self.index[next])
 
259
            self.treeview.set_cursor(self.index[parents[0]])
256
260
        self.treeview.grab_focus()
257
261
 
258
262
    def _fwd_clicked_cb(self, *args):
259
263
        """Callback for when the forward button is clicked."""
260
264
        (path, col) = self.treeview.get_cursor()
261
265
        revision = self.model[path][0]
262
 
        if not len(self.children[revision]):
 
266
        children = self.model[path][5]
 
267
        if not len(children):
263
268
            return
264
269
 
265
 
        for child in self.children[revision]:
 
270
        for child_id in children:
 
271
            child = self.revisions[self.index[child_id]]
266
272
            if same_branch(child, revision):
267
 
                self.treeview.set_cursor(self.index[child])
 
273
                self.treeview.set_cursor(self.index[child_id])
268
274
                break
269
275
        else:
270
 
            prev = list(self.children[revision])[0]
271
 
            self.treeview.set_cursor(self.index[prev])
 
276
            self.treeview.set_cursor(self.index[children[0]])
272
277
        self.treeview.grab_focus()
273
278
 
274
279
    def _go_clicked_cb(self, revid):
275
280
        """Callback for when the go button for a parent is clicked."""
276
 
        self.treeview.set_cursor(self.index[self.revisions[revid]])
 
281
        self.treeview.set_cursor(self.index[revid])
277
282
        self.treeview.grab_focus()
278
283
 
279
284
    def show_diff(self, branch, revid, parentid):
300
305
            menu.popup(None, None, None, event.button, event.get_time())
301
306
 
302
307
    def selected_revision(self, path):
303
 
        return self.model[path][0]
 
308
        return self.model[path][treemodel.REVISION]
304
309
 
305
310
    def selected_revisions(self):
306
311
        return [self.selected_revision(path) for path in \