/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to logview.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2007-03-15 12:43:48 UTC
  • mto: (126.1.38 bzr-gtk)
  • mto: This revision was merged to the branch mainline in revision 172.
  • Revision ID: szilveszter.farkas@gmail.com-20070315124348-0nx0zb7fv4pa8xk6
Fix the indentation error in the TortoiseBZR test.

Show diffs side-by-side

added added

removed removed

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