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