/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>
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import pygtk
18
pygtk.require("2.0")
19
import gtk
20
import pango
21
22
from bzrlib.osutils import format_date
23
24
25
class LogView(gtk.ScrolledWindow):
26
    """ Custom widget for commit log details.
27
28
    A variety of bzr tools may need to implement such a thing. This is a
29
    start.
30
    """
31
32
    def __init__(self, revision=None):
33
        gtk.ScrolledWindow.__init__(self)
34
        self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
35
        self.set_shadow_type(gtk.SHADOW_NONE)
36
        self._create()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
37
        self._show_callback = None
38
        self._clicked_callback = None
0.1.1 by Dan Loda
First working version of xannotate.
39
40
        if revision is not None:
41
            self.set_revision(revision)
42
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
43
    def set_show_callback(self, callback):
44
        self._show_callback = callback
45
46
    def set_go_callback(self, callback):
47
        self._go_callback = callback
48
0.1.1 by Dan Loda
First working version of xannotate.
49
    def set_revision(self, revision):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
50
        self._revision = revision
0.1.1 by Dan Loda
First working version of xannotate.
51
        self.revision_id.set_text(revision.revision_id)
52
        self.committer.set_text(revision.committer)
53
        self.timestamp.set_text(format_date(revision.timestamp,
0.2.1 by Dan Loda
first go at emacs vc-annotate like highlighting
54
                                            revision.timezone))
0.1.1 by Dan Loda
First working version of xannotate.
55
        self.message_buffer.set_text(revision.message)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
56
        try:
57
            self.branchnick_label.set_text(revision.properties['branch-nick'])
58
        except KeyError:
59
            self.branchnick_label.set_text("")
60
0.1.1 by Dan Loda
First working version of xannotate.
61
        self._add_parents(revision.parent_ids)
62
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
63
    def _show_clicked_cb(self, widget, revid, parentid):
64
        """Callback for when the show button for a parent is clicked."""
65
        self._show_callback(revid, parentid)
66
67
    def _go_clicked_cb(self, widget, revid):
68
        """Callback for when the go button for a parent is clicked."""
69
        self._go_callback(revid)
70
0.1.1 by Dan Loda
First working version of xannotate.
71
    def _add_parents(self, parent_ids):
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
72
        for widget in self.parents_widgets:
73
            self.parents_table.remove(widget)
0.1.1 by Dan Loda
First working version of xannotate.
74
            
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
75
        self.parents_widgets = []
76
        self.parents_table.resize(max(len(parent_ids), 1), 2)
77
78
        for idx, parent_id in enumerate(parent_ids):
79
            align = gtk.Alignment(0.0, 0.0)
80
            self.parents_widgets.append(align)
81
            self.parents_table.attach(align, 1, 2, idx, idx + 1,
82
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
83
            align.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
84
85
            hbox = gtk.HBox(False, spacing=6)
86
            align.add(hbox)
87
            hbox.show()
88
89
            image = gtk.Image()
90
            image.set_from_stock(
91
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
92
            image.show()
93
94
            button = gtk.Button()
95
            button.add(image)
96
            button.set_sensitive(self._show_callback is not None)
97
            button.connect("clicked", self._show_clicked_cb,
98
                           self._revision.revision_id, parent_id)
99
            hbox.pack_start(button, expand=False, fill=True)
100
            button.show()
101
102
            button = gtk.Button(parent_id)
103
            button.set_use_underline(False)
104
            button.connect("clicked", self._go_clicked_cb, parent_id)
105
            hbox.pack_start(button, expand=False, fill=True)
106
            button.show()
0.1.1 by Dan Loda
First working version of xannotate.
107
108
    def _create(self):
109
        vbox = gtk.VBox(False, 6)
110
        vbox.set_border_width(6)
111
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
112
        vbox.pack_start(self._create_parents_table(), expand=False, fill=True)
0.1.1 by Dan Loda
First working version of xannotate.
113
        vbox.pack_start(self._create_message_view())
114
        self.add_with_viewport(vbox)
115
        vbox.show()
116
117
    def _create_headers(self):
118
        self.table = gtk.Table(rows=4, columns=2)
119
        self.table.set_row_spacings(6)
120
        self.table.set_col_spacings(6)
121
        self.table.show()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
122
123
        align = gtk.Alignment(1.0, 0.5)
124
        label = gtk.Label()
125
        label.set_markup("<b>Revision Id:</b>")
126
        align.add(label)
127
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
128
        align.show()
129
        label.show()
130
131
        align = gtk.Alignment(0.0, 0.5)
132
        self.revision_id = gtk.Label()
133
        self.revision_id.set_selectable(True)
134
        align.add(self.revision_id)
135
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
136
        align.show()
137
        self.revision_id.show()
138
0.1.1 by Dan Loda
First working version of xannotate.
139
        align = gtk.Alignment(1.0, 0.5)
140
        label = gtk.Label()
141
        label.set_markup("<b>Committer:</b>")
142
        align.add(label)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
143
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
144
        align.show()
145
        label.show()
146
147
        align = gtk.Alignment(0.0, 0.5)
148
        self.committer = gtk.Label()
149
        self.committer.set_selectable(True)
150
        align.add(self.committer)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
151
        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.
152
        align.show()
153
        self.committer.show()
154
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
155
        align = gtk.Alignment(0.0, 0.5)
156
        label = gtk.Label()
157
        label.set_markup("<b>Branch nick:</b>")
158
        align.add(label)
159
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
160
        label.show()
161
        align.show()
162
163
        align = gtk.Alignment(0.0, 0.5)
164
        self.branchnick_label = gtk.Label()
165
        self.branchnick_label.set_selectable(True)
166
        align.add(self.branchnick_label)
167
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
168
        self.branchnick_label.show()
169
        align.show()
170
0.1.1 by Dan Loda
First working version of xannotate.
171
        align = gtk.Alignment(1.0, 0.5)
172
        label = gtk.Label()
173
        label.set_markup("<b>Timestamp:</b>")
174
        align.add(label)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
175
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
0.1.1 by Dan Loda
First working version of xannotate.
176
        align.show()
177
        label.show()
178
179
        align = gtk.Alignment(0.0, 0.5)
180
        self.timestamp = gtk.Label()
181
        self.timestamp.set_selectable(True)
182
        align.add(self.timestamp)
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
183
        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.
184
        align.show()
185
        self.timestamp.show()
186
187
        return self.table
188
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
189
    def _create_parents_table(self):
190
        self.parents_table = gtk.Table(rows=1, columns=2)
191
        self.parents_table.set_row_spacings(3)
192
        self.parents_table.set_col_spacings(6)
193
        self.parents_table.show()
194
        self.parents_widgets = []
195
196
        label = gtk.Label()
197
        label.set_markup("<b>Parents:</b>")
198
        align = gtk.Alignment(0.0, 0.5)
199
        align.add(label)
200
        self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
201
        label.show()
202
        align.show()
203
204
        return self.parents_table
205
0.1.1 by Dan Loda
First working version of xannotate.
206
    def _create_message_view(self):
207
        self.message_buffer = gtk.TextBuffer()
208
        tv = gtk.TextView(self.message_buffer)
209
        tv.set_editable(False)
210
        tv.set_wrap_mode(gtk.WRAP_WORD)
211
        tv.modify_font(pango.FontDescription("Monospace"))
212
        tv.show()
213
        return tv
214