/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
245 by Jelmer Vernooij
Fix exception in gmissing.
33
    def __init__(self, revision=None, scroll=True, tags=[]):
179 by Jelmer Vernooij
Don't use scrolling inside revisions in missing window.
34
        super(LogView, self).__init__()
35
        if scroll:
36
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
37
        else:
38
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
0.1.1 by Dan Loda
First working version of xannotate.
39
        self.set_shadow_type(gtk.SHADOW_NONE)
40
        self._create()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
41
        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.
42
        self._go_callback = None
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
43
        self._clicked_callback = None
0.1.1 by Dan Loda
First working version of xannotate.
44
45
        if revision is not None:
241 by Jelmer Vernooij
Show tags in bzr viz.
46
            self.set_revision(revision, tags=tags)
0.1.1 by Dan Loda
First working version of xannotate.
47
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
48
    def set_show_callback(self, callback):
49
        self._show_callback = callback
50
51
    def set_go_callback(self, callback):
52
        self._go_callback = callback
53
244 by Jelmer Vernooij
Fix non-sequence iteration warnings.
54
    def set_revision(self, revision, tags=[]):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
55
        self._revision = revision
0.1.1 by Dan Loda
First working version of xannotate.
56
        self.revision_id.set_text(revision.revision_id)
192 by Jelmer Vernooij
Allow committer to be None.
57
        if revision.committer is not None:
58
            self.committer.set_text(revision.committer)
59
        else:
60
            self.committer.set_text("")
259 by Aaron Bentley
Add author support to gannotate and log viewer
61
        author = revision.properties.get('author', '')
62
        if author != '':
63
            self.author.set_text(author)
64
            self.author.show()
65
            self.author_label.show()
66
        else:
67
            self.author.hide()
68
            self.author_label.hide()
69
197 by Jelmer Vernooij
Fix some warnings when displaying ghost revisions. Reported by John.
70
        if revision.timestamp is not None:
71
            self.timestamp.set_text(format_date(revision.timestamp,
72
                                                revision.timezone))
0.1.1 by Dan Loda
First working version of xannotate.
73
        self.message_buffer.set_text(revision.message)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
74
        try:
75
            self.branchnick_label.set_text(revision.properties['branch-nick'])
76
        except KeyError:
77
            self.branchnick_label.set_text("")
78
0.1.1 by Dan Loda
First working version of xannotate.
79
        self._add_parents(revision.parent_ids)
241 by Jelmer Vernooij
Show tags in bzr viz.
80
        self._add_tags(tags)
0.1.1 by Dan Loda
First working version of xannotate.
81
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
82
    def _show_clicked_cb(self, widget, revid, parentid):
83
        """Callback for when the show button for a parent is clicked."""
84
        self._show_callback(revid, parentid)
85
86
    def _go_clicked_cb(self, widget, revid):
87
        """Callback for when the go button for a parent is clicked."""
88
        self._go_callback(revid)
89
241 by Jelmer Vernooij
Show tags in bzr viz.
90
    def _add_tags(self, tags):
91
        if tags == []:
92
            self.tags_list.hide()
93
            self.tags_label.hide()
94
            return
95
96
        for widget in self.tags_widgets:
97
            self.tags_list.remove(widget)
98
242 by Jelmer Vernooij
Avoid cleanup warning.
99
        self.tags_widgets = []
100
241 by Jelmer Vernooij
Show tags in bzr viz.
101
        for tag in tags:
102
            widget = gtk.Label(tag)
103
            widget.set_selectable(True)
104
            self.tags_widgets.append(widget)
105
            self.tags_list.add(widget)
106
        self.tags_list.show_all()
107
        self.tags_label.show_all()
108
        
109
0.1.1 by Dan Loda
First working version of xannotate.
110
    def _add_parents(self, parent_ids):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
111
        for widget in self.parents_widgets:
112
            self.parents_table.remove(widget)
0.1.1 by Dan Loda
First working version of xannotate.
113
            
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
114
        self.parents_widgets = []
115
        self.parents_table.resize(max(len(parent_ids), 1), 2)
116
117
        for idx, parent_id in enumerate(parent_ids):
118
            align = gtk.Alignment(0.0, 0.0)
119
            self.parents_widgets.append(align)
120
            self.parents_table.attach(align, 1, 2, idx, idx + 1,
121
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
122
            align.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
123
124
            hbox = gtk.HBox(False, spacing=6)
125
            align.add(hbox)
126
            hbox.show()
127
128
            image = gtk.Image()
129
            image.set_from_stock(
130
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
131
            image.show()
132
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.
133
            if self._show_callback is not None:
134
                button = gtk.Button()
135
                button.add(image)
136
                button.connect("clicked", self._show_clicked_cb,
137
                               self._revision.revision_id, parent_id)
138
                hbox.pack_start(button, expand=False, fill=True)
139
                button.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
140
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.
141
            if self._go_callback is not None:
142
                button = gtk.Button(parent_id)
143
                button.connect("clicked", self._go_clicked_cb, parent_id)
144
            else:
145
                button = gtk.Label(parent_id)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
146
            button.set_use_underline(False)
147
            hbox.pack_start(button, expand=False, fill=True)
148
            button.show()
0.1.1 by Dan Loda
First working version of xannotate.
149
150
    def _create(self):
151
        vbox = gtk.VBox(False, 6)
152
        vbox.set_border_width(6)
153
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
154
        vbox.pack_start(self._create_parents_table(), expand=False, fill=True)
0.1.1 by Dan Loda
First working version of xannotate.
155
        vbox.pack_start(self._create_message_view())
156
        self.add_with_viewport(vbox)
157
        vbox.show()
158
159
    def _create_headers(self):
241 by Jelmer Vernooij
Show tags in bzr viz.
160
        self.table = gtk.Table(rows=5, columns=2)
0.1.1 by Dan Loda
First working version of xannotate.
161
        self.table.set_row_spacings(6)
162
        self.table.set_col_spacings(6)
163
        self.table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
164
165
        align = gtk.Alignment(1.0, 0.5)
166
        label = gtk.Label()
167
        label.set_markup("<b>Revision Id:</b>")
168
        align.add(label)
169
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
170
        align.show()
171
        label.show()
172
173
        align = gtk.Alignment(0.0, 0.5)
174
        self.revision_id = gtk.Label()
175
        self.revision_id.set_selectable(True)
176
        align.add(self.revision_id)
177
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
178
        align.show()
179
        self.revision_id.show()
180
0.1.1 by Dan Loda
First working version of xannotate.
181
        align = gtk.Alignment(1.0, 0.5)
259 by Aaron Bentley
Add author support to gannotate and log viewer
182
        self.author_label = gtk.Label()
183
        self.author_label.set_markup("<b>Author:</b>")
184
        align.add(self.author_label)
185
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
186
        align.show()
187
        self.author_label.show()
188
189
        align = gtk.Alignment(0.0, 0.5)
190
        self.author = gtk.Label()
191
        self.author.set_selectable(True)
192
        align.add(self.author)
193
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
194
        align.show()
195
        self.author.show()
196
        self.author.hide()
197
198
        align = gtk.Alignment(1.0, 0.5)
0.1.1 by Dan Loda
First working version of xannotate.
199
        label = gtk.Label()
200
        label.set_markup("<b>Committer:</b>")
201
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
202
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
203
        align.show()
204
        label.show()
205
206
        align = gtk.Alignment(0.0, 0.5)
207
        self.committer = gtk.Label()
208
        self.committer.set_selectable(True)
209
        align.add(self.committer)
259 by Aaron Bentley
Add author support to gannotate and log viewer
210
        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.
211
        align.show()
212
        self.committer.show()
213
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
214
        align = gtk.Alignment(0.0, 0.5)
215
        label = gtk.Label()
216
        label.set_markup("<b>Branch nick:</b>")
217
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
218
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
219
        label.show()
220
        align.show()
221
222
        align = gtk.Alignment(0.0, 0.5)
223
        self.branchnick_label = gtk.Label()
224
        self.branchnick_label.set_selectable(True)
225
        align.add(self.branchnick_label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
226
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
227
        self.branchnick_label.show()
228
        align.show()
229
0.1.1 by Dan Loda
First working version of xannotate.
230
        align = gtk.Alignment(1.0, 0.5)
231
        label = gtk.Label()
232
        label.set_markup("<b>Timestamp:</b>")
233
        align.add(label)
259 by Aaron Bentley
Add author support to gannotate and log viewer
234
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
235
        align.show()
236
        label.show()
237
238
        align = gtk.Alignment(0.0, 0.5)
239
        self.timestamp = gtk.Label()
240
        self.timestamp.set_selectable(True)
241
        align.add(self.timestamp)
259 by Aaron Bentley
Add author support to gannotate and log viewer
242
        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.
243
        align.show()
244
        self.timestamp.show()
245
241 by Jelmer Vernooij
Show tags in bzr viz.
246
        align = gtk.Alignment(1.0, 0.5)
247
        self.tags_label = gtk.Label()
248
        self.tags_label.set_markup("<b>Tags:</b>")
249
        align.add(self.tags_label)
250
        align.show()
261 by Aaron Bentley
Fix tags formatting
251
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
252
        self.tags_label.show()
253
254
        align = gtk.Alignment(0.0, 0.5)
255
        self.tags_list = gtk.VBox()
256
        align.add(self.tags_list)
261 by Aaron Bentley
Fix tags formatting
257
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
241 by Jelmer Vernooij
Show tags in bzr viz.
258
        align.show()
259
        self.tags_list.show()
260
        self.tags_widgets = []
261
0.1.1 by Dan Loda
First working version of xannotate.
262
        return self.table
263
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
264
    def _create_parents_table(self):
265
        self.parents_table = gtk.Table(rows=1, columns=2)
266
        self.parents_table.set_row_spacings(3)
267
        self.parents_table.set_col_spacings(6)
268
        self.parents_table.show()
269
        self.parents_widgets = []
270
271
        label = gtk.Label()
272
        label.set_markup("<b>Parents:</b>")
273
        align = gtk.Alignment(0.0, 0.5)
274
        align.add(label)
275
        self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
276
        label.show()
277
        align.show()
278
279
        return self.parents_table
280
0.1.1 by Dan Loda
First working version of xannotate.
281
    def _create_message_view(self):
282
        self.message_buffer = gtk.TextBuffer()
283
        tv = gtk.TextView(self.message_buffer)
284
        tv.set_editable(False)
285
        tv.set_wrap_mode(gtk.WRAP_WORD)
286
        tv.modify_font(pango.FontDescription("Monospace"))
287
        tv.show()
288
        return tv
289