/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.1.1 by Dan Loda
First working version of xannotate.
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
175 by Jelmer Vernooij
Add very simple gmissing command.
2
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
0.1.1 by Dan Loda
First working version of xannotate.
3
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
import pygtk
19
pygtk.require("2.0")
20
import gtk
21
import pango
22
23
from bzrlib.osutils import format_date
24
25
26
class LogView(gtk.ScrolledWindow):
27
    """ Custom widget for commit log details.
28
29
    A variety of bzr tools may need to implement such a thing. This is a
30
    start.
31
    """
32
256.2.23 by Gary van der Merwe
Show Children
33
    def __init__(self, revision=None, scroll=True, tags=[],
34
                 show_children=False):
179 by Jelmer Vernooij
Don't use scrolling inside revisions in missing window.
35
        super(LogView, self).__init__()
36
        if scroll:
37
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
38
        else:
39
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
0.1.1 by Dan Loda
First working version of xannotate.
40
        self.set_shadow_type(gtk.SHADOW_NONE)
256.2.23 by Gary van der Merwe
Show Children
41
        self.show_children = show_children
0.1.1 by Dan Loda
First working version of xannotate.
42
        self._create()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
43
        self._show_callback = None
148 by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set.
44
        self._go_callback = None
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
45
        self._clicked_callback = None
0.1.1 by Dan Loda
First working version of xannotate.
46
47
        if revision is not None:
241 by Jelmer Vernooij
Show tags in bzr viz.
48
            self.set_revision(revision, tags=tags)
0.1.1 by Dan Loda
First working version of xannotate.
49
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
50
    def set_show_callback(self, callback):
51
        self._show_callback = callback
52
53
    def set_go_callback(self, callback):
54
        self._go_callback = callback
55
256.2.23 by Gary van der Merwe
Show Children
56
    def set_revision(self, revision, tags=[], children=[]):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
57
        self._revision = revision
0.1.1 by Dan Loda
First working version of xannotate.
58
        self.revision_id.set_text(revision.revision_id)
192 by Jelmer Vernooij
Allow committer to be None.
59
        if revision.committer is not None:
60
            self.committer.set_text(revision.committer)
61
        else:
62
            self.committer.set_text("")
259 by Aaron Bentley
Add author support to gannotate and log viewer
63
        author = revision.properties.get('author', '')
64
        if author != '':
65
            self.author.set_text(author)
66
            self.author.show()
67
            self.author_label.show()
68
        else:
69
            self.author.hide()
70
            self.author_label.hide()
71
197 by Jelmer Vernooij
Fix some warnings when displaying ghost revisions. Reported by John.
72
        if revision.timestamp is not None:
73
            self.timestamp.set_text(format_date(revision.timestamp,
74
                                                revision.timezone))
0.1.1 by Dan Loda
First working version of xannotate.
75
        self.message_buffer.set_text(revision.message)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
76
        try:
77
            self.branchnick_label.set_text(revision.properties['branch-nick'])
78
        except KeyError:
79
            self.branchnick_label.set_text("")
80
256.2.23 by Gary van der Merwe
Show Children
81
        self._add_parents_or_children(revision.parent_ids,
82
                                      self.parents_widgets,
83
                                      self.parents_table)
84
        
85
        if self.show_children:
86
            self._add_parents_or_children(children,
87
                                          self.children_widgets,
88
                                          self.children_table)
89
        
241 by Jelmer Vernooij
Show tags in bzr viz.
90
        self._add_tags(tags)
0.1.1 by Dan Loda
First working version of xannotate.
91
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
92
    def _show_clicked_cb(self, widget, revid, parentid):
93
        """Callback for when the show button for a parent is clicked."""
94
        self._show_callback(revid, parentid)
95
96
    def _go_clicked_cb(self, widget, revid):
97
        """Callback for when the go button for a parent is clicked."""
98
        self._go_callback(revid)
99
241 by Jelmer Vernooij
Show tags in bzr viz.
100
    def _add_tags(self, tags):
101
        if tags == []:
102
            self.tags_list.hide()
103
            self.tags_label.hide()
104
            return
105
106
        for widget in self.tags_widgets:
107
            self.tags_list.remove(widget)
108
242 by Jelmer Vernooij
Avoid cleanup warning.
109
        self.tags_widgets = []
110
241 by Jelmer Vernooij
Show tags in bzr viz.
111
        for tag in tags:
112
            widget = gtk.Label(tag)
113
            widget.set_selectable(True)
114
            self.tags_widgets.append(widget)
115
            self.tags_list.add(widget)
116
        self.tags_list.show_all()
117
        self.tags_label.show_all()
118
        
119
256.2.23 by Gary van der Merwe
Show Children
120
    def _add_parents_or_children(self, revids, widgets, table):
121
        while len(widgets) > 0:
122
            widget = widgets.pop()
123
            table.remove(widget)
124
        
125
        table.resize(max(len(revids), 1), 2)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
126
256.2.23 by Gary van der Merwe
Show Children
127
        for idx, revid in enumerate(revids):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
128
            align = gtk.Alignment(0.0, 0.0)
256.2.23 by Gary van der Merwe
Show Children
129
            widgets.append(align)
130
            table.attach(align, 1, 2, idx, idx + 1,
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
131
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
132
            align.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
133
134
            hbox = gtk.HBox(False, spacing=6)
135
            align.add(hbox)
136
            hbox.show()
137
138
            image = gtk.Image()
139
            image.set_from_stock(
140
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
141
            image.show()
142
148 by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set.
143
            if self._show_callback is not None:
144
                button = gtk.Button()
145
                button.add(image)
146
                button.connect("clicked", self._show_clicked_cb,
256.2.23 by Gary van der Merwe
Show Children
147
                               self._revision.revision_id, revid)
148 by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set.
148
                hbox.pack_start(button, expand=False, fill=True)
149
                button.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
150
148 by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set.
151
            if self._go_callback is not None:
256.2.23 by Gary van der Merwe
Show Children
152
                button = gtk.Button(revid)
153
                button.connect("clicked", self._go_clicked_cb, revid)
148 by Jelmer Vernooij
Clean up interface a bit: don't show diff button when no diff can be accessed, use label instead of button when there is no callback set.
154
            else:
256.2.23 by Gary van der Merwe
Show Children
155
                button = gtk.Label(revid)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
156
            button.set_use_underline(False)
157
            hbox.pack_start(button, expand=False, fill=True)
158
            button.show()
0.1.1 by Dan Loda
First working version of xannotate.
159
160
    def _create(self):
161
        vbox = gtk.VBox(False, 6)
162
        vbox.set_border_width(6)
163
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
256.2.23 by Gary van der Merwe
Show Children
164
        vbox.pack_start(self._create_parents_and_children(), expand=False, fill=True)
0.1.1 by Dan Loda
First working version of xannotate.
165
        vbox.pack_start(self._create_message_view())
166
        self.add_with_viewport(vbox)
167
        vbox.show()
168
169
    def _create_headers(self):
241 by Jelmer Vernooij
Show tags in bzr viz.
170
        self.table = gtk.Table(rows=5, columns=2)
0.1.1 by Dan Loda
First working version of xannotate.
171
        self.table.set_row_spacings(6)
172
        self.table.set_col_spacings(6)
173
        self.table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
174
175
        align = gtk.Alignment(1.0, 0.5)
176
        label = gtk.Label()
177
        label.set_markup("<b>Revision Id:</b>")
178
        align.add(label)
179
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
180
        align.show()
181
        label.show()
182
183
        align = gtk.Alignment(0.0, 0.5)
184
        self.revision_id = gtk.Label()
185
        self.revision_id.set_selectable(True)
186
        align.add(self.revision_id)
187
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
188
        align.show()
189
        self.revision_id.show()
190
0.1.1 by Dan Loda
First working version of xannotate.
191
        align = gtk.Alignment(1.0, 0.5)
259 by Aaron Bentley
Add author support to gannotate and log viewer
192
        self.author_label = gtk.Label()
193
        self.author_label.set_markup("<b>Author:</b>")
194
        align.add(self.author_label)
195
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
196
        align.show()
197
        self.author_label.show()
198
199
        align = gtk.Alignment(0.0, 0.5)
200
        self.author = gtk.Label()
201
        self.author.set_selectable(True)
202
        align.add(self.author)
203
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
204
        align.show()
205
        self.author.show()
206
        self.author.hide()
207
208
        align = gtk.Alignment(1.0, 0.5)
0.1.1 by Dan Loda
First working version of xannotate.
209
        label = gtk.Label()
210
        label.set_markup("<b>Committer:</b>")
211
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
212
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
213
        align.show()
214
        label.show()
215
216
        align = gtk.Alignment(0.0, 0.5)
217
        self.committer = gtk.Label()
218
        self.committer.set_selectable(True)
219
        align.add(self.committer)
259 by Aaron Bentley
Add author support to gannotate and log viewer
220
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
221
        align.show()
222
        self.committer.show()
223
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
224
        align = gtk.Alignment(0.0, 0.5)
225
        label = gtk.Label()
226
        label.set_markup("<b>Branch nick:</b>")
227
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
228
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
229
        label.show()
230
        align.show()
231
232
        align = gtk.Alignment(0.0, 0.5)
233
        self.branchnick_label = gtk.Label()
234
        self.branchnick_label.set_selectable(True)
235
        align.add(self.branchnick_label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
236
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
237
        self.branchnick_label.show()
238
        align.show()
239
0.1.1 by Dan Loda
First working version of xannotate.
240
        align = gtk.Alignment(1.0, 0.5)
241
        label = gtk.Label()
242
        label.set_markup("<b>Timestamp:</b>")
243
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
244
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
245
        align.show()
246
        label.show()
247
248
        align = gtk.Alignment(0.0, 0.5)
249
        self.timestamp = gtk.Label()
250
        self.timestamp.set_selectable(True)
251
        align.add(self.timestamp)
259 by Aaron Bentley
Add author support to gannotate and log viewer
252
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
253
        align.show()
254
        self.timestamp.show()
255
241 by Jelmer Vernooij
Show tags in bzr viz.
256
        align = gtk.Alignment(1.0, 0.5)
257
        self.tags_label = gtk.Label()
258
        self.tags_label.set_markup("<b>Tags:</b>")
259
        align.add(self.tags_label)
260
        align.show()
261 by Aaron Bentley
Fix tags formatting
261
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
262
        self.tags_label.show()
263
264
        align = gtk.Alignment(0.0, 0.5)
265
        self.tags_list = gtk.VBox()
266
        align.add(self.tags_list)
261 by Aaron Bentley
Fix tags formatting
267
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
268
        align.show()
269
        self.tags_list.show()
270
        self.tags_widgets = []
271
0.1.1 by Dan Loda
First working version of xannotate.
272
        return self.table
273
256.2.23 by Gary van der Merwe
Show Children
274
    
275
    def _create_parents_and_children(self):
276
        hbox = gtk.HBox(True, 6)
277
        
278
        self.parents_table = self._create_parents_or_children_table(
279
            "<b>Parents:</b>")
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
280
        self.parents_widgets = []
256.2.23 by Gary van der Merwe
Show Children
281
        hbox.pack_start(self.parents_table)
282
        
283
        if self.show_children:
284
            self.children_table = self._create_parents_or_children_table(
285
                "<b>Children:</b>")
286
            self.children_widgets = []
287
            hbox.pack_start(self.children_table)
288
        
289
        hbox.show()
290
        return hbox
291
        
292
    def _create_parents_or_children_table(self, text):
293
        table = gtk.Table(rows=1, columns=2)
294
        table.set_row_spacings(3)
295
        table.set_col_spacings(6)
296
        table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
297
298
        label = gtk.Label()
256.2.23 by Gary van der Merwe
Show Children
299
        label.set_markup(text)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
300
        align = gtk.Alignment(0.0, 0.5)
301
        align.add(label)
256.2.23 by Gary van der Merwe
Show Children
302
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
303
        label.show()
304
        align.show()
305
256.2.23 by Gary van der Merwe
Show Children
306
        return table
307
    
308
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
309
0.1.1 by Dan Loda
First working version of xannotate.
310
    def _create_message_view(self):
311
        self.message_buffer = gtk.TextBuffer()
312
        tv = gtk.TextView(self.message_buffer)
313
        tv.set_editable(False)
314
        tv.set_wrap_mode(gtk.WRAP_WORD)
315
        tv.modify_font(pango.FontDescription("Monospace"))
316
        tv.show()
317
        return tv
318