1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import pygtk
pygtk.require("2.0")
import gtk
import pango
from bzrlib.osutils import format_date
class LogView(gtk.ScrolledWindow):
""" Custom widget for commit log details.
A variety of bzr tools may need to implement such a thing. This is a
start.
"""
def __init__(self, revision=None):
gtk.ScrolledWindow.__init__(self)
self.parent_id_widgets = []
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.set_shadow_type(gtk.SHADOW_NONE)
self._create()
if revision is not None:
self.set_revision(revision)
def set_revision(self, revision):
self.revision_id.set_text(revision.revision_id)
self.committer.set_text(revision.committer)
self.timestamp.set_text(format_date(revision.timestamp,
revision.timezone))
self.message_buffer.set_text(revision.message)
self._add_parents(revision.parent_ids)
def _add_parents(self, parent_ids):
for widget in self.parent_id_widgets:
self.table.remove(widget)
self.parent_id_widgets = []
if len(parent_ids):
self.table.resize(4 + len(parent_ids), 2)
align = gtk.Alignment(1.0, 0.5)
align.show()
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
self.parent_id_widgets.append(align)
label = gtk.Label()
if len(parent_ids) > 1:
label.set_markup("<b>Parent Ids:</b>")
else:
label.set_markup("<b>Parent Id:</b>")
label.show()
align.add(label)
for i, parent_id in enumerate(parent_ids):
align = gtk.Alignment(0.0, 0.5)
self.parent_id_widgets.append(align)
self.table.attach(align, 1, 2, i + 3, i + 4,
gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
label = gtk.Label(parent_id)
label.set_selectable(True)
label.show()
align.add(label)
def _create(self):
vbox = gtk.VBox(False, 6)
vbox.set_border_width(6)
vbox.pack_start(self._create_headers(), expand=False, fill=True)
vbox.pack_start(self._create_message_view())
self.add_with_viewport(vbox)
vbox.show()
def _create_headers(self):
self.table = gtk.Table(rows=4, columns=2)
self.table.set_row_spacings(6)
self.table.set_col_spacings(6)
self.table.show()
align = gtk.Alignment(1.0, 0.5)
label = gtk.Label()
label.set_markup("<b>Committer:</b>")
align.add(label)
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
align.show()
label.show()
align = gtk.Alignment(0.0, 0.5)
self.committer = gtk.Label()
self.committer.set_selectable(True)
align.add(self.committer)
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
self.committer.show()
align = gtk.Alignment(1.0, 0.5)
label = gtk.Label()
label.set_markup("<b>Timestamp:</b>")
align.add(label)
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
align.show()
label.show()
align = gtk.Alignment(0.0, 0.5)
self.timestamp = gtk.Label()
self.timestamp.set_selectable(True)
align.add(self.timestamp)
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
self.timestamp.show()
align = gtk.Alignment(1.0, 0.5)
label = gtk.Label()
label.set_markup("<b>Revision Id:</b>")
align.add(label)
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
align.show()
label.show()
align = gtk.Alignment(0.0, 0.5)
self.revision_id = gtk.Label()
self.revision_id.set_selectable(True)
align.add(self.revision_id)
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
self.revision_id.show()
return self.table
def _create_message_view(self):
self.message_buffer = gtk.TextBuffer()
tv = gtk.TextView(self.message_buffer)
tv.set_editable(False)
tv.set_wrap_mode(gtk.WRAP_WORD)
tv.modify_font(pango.FontDescription("Monospace"))
tv.show()
return tv
|