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