/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 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

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 distances, graph, same_branch
 
21
from graph import graph
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
 
 
50
47
        self.construct()
51
48
 
52
49
    def construct(self):
53
50
        """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
 
 
66
51
        scrollwin = gtk.ScrolledWindow()
67
52
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
68
53
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
69
 
        #scrollwin.set_border_width(12)
70
 
        vbox.pack_start(scrollwin, expand=True, fill=True)
 
54
        scrollwin.set_border_width(12)
 
55
        self.add(scrollwin)
71
56
        scrollwin.show()
72
57
 
73
58
        self.treeview = gtk.TreeView()
74
59
        self.treeview.set_rules_hint(True)
75
60
        self.treeview.set_search_column(4)
76
 
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
77
61
        scrollwin.add(self.treeview)
78
62
        self.treeview.show()
79
63
 
112
96
        column.add_attribute(cell, "text", 6)
113
97
        self.treeview.append_column(column)
114
98
 
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
 
 
142
99
    def set_branch(self, branch, start):
143
100
        """Set the branch and start position for this window.
144
101
 
147
104
        treeview itself.
148
105
        """
149
106
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
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
 
107
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
108
                              gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
109
                              str, str, str)
157
110
 
158
111
        last_lines = []
159
 
        (revids, self.revisions, colours, self.children) \
160
 
                 = distances(branch, start)
161
 
        for revision, node, lines in graph(revids, self.revisions, colours):
 
112
        for revision, node, lines in graph(branch, start):
162
113
            message = revision.message.split("\n")[0]
163
114
            if revision.committer is not None:
164
115
                timestamp = format_date(revision.timestamp, revision.timezone)
165
116
            else:
166
117
                timestamp = None
167
118
 
168
 
            self.model.append([ revision, node, last_lines, lines,
169
 
                                message, revision.committer, timestamp ])
170
 
            self.index[revision] = index
171
 
            index += 1
172
 
 
 
119
            model.append([ revision, node, last_lines, lines,
 
120
                           message, revision.committer, timestamp ])
173
121
            last_lines = lines
174
122
 
175
123
        self.set_title(os.path.basename(branch.base) + " - bzrk")
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
 
 
 
124
        self.treeview.set_model(model)