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