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