6
from hwtest.constants import SHARE_DIR
7
from hwtest.excluder import Excluder
8
from hwtest.result import (ALL_STATUS)
9
from hwtest.test import (ALL_CATEGORIES)
10
from hwtest.ui import Ui
12
GUI_DIR = os.path.join(SHARE_DIR, 'gui')
16
def __init__(self, application):
17
super(Gui, self).__init__(application)
19
self.start_color = 3638089728
20
self.end_color = 4294967040
21
self.wTree = gtk.glade.XML(os.path.join(GUI_DIR, 'hwtest.glade'),
25
canvas = self.wTree.get_widget("canvas")
26
self.root = canvas.root().add(gnomecanvas.CanvasGroup)
29
canvas_bg = gtk.gdk.pixbuf_new_from_file(os.path.join(GUI_DIR,
31
self.root.add(gnomecanvas.CanvasPixbuf, pixbuf=canvas_bg, x=0,
35
header = self.wTree.get_widget('header_image')
36
header.set_from_file(os.path.join(GUI_DIR, 'hwtest_head.png'))
40
window = self.wTree.get_widget("window")
41
window.set_resizable(False)
42
window.set_size_request(450, 410)
43
window.set_icon_from_file(os.path.join(GUI_DIR, 'ubuntu_logo.png'))
44
window.connect("destroy", lambda w: gtk.main_quit())
46
# Vertical and horizontal boxes
47
self.vbox1 = gtk.VBox(False, 0)
48
self.hbox1 = gtk.HBox(False, 0)
52
text = "<big><b>%s</b></big>\n%s" % (
53
self.application.title, self.application.intro)
54
self.intro = self.root.add(gnomecanvas.CanvasText,
55
markup=text, size=9000, fill_color_rgba=self.start_color,
57
self._fade_in(self.intro)
59
# Vertical and horizontal boxes
60
self.vbox2 = gtk.VBox(False, 0)
61
self.hbox2 = gtk.HBox(False, 0)
62
for category in ALL_CATEGORIES:
63
button_name = '%s_button' % category
64
type_button = self.wTree.get_widget(button_name)
65
type_button.connect("clicked", lambda w,
66
category=category: self.do_intro(category))
68
self.vbox2.pack_start(type_button, False, False, 2)
70
self.hbox2.pack_start(self.vbox2, False, False, 0)
72
self.category = self.root.add(gnomecanvas.CanvasWidget, x=180, y=160,
73
widget=self.hbox2, width=140, height=80)
77
self.category.destroy()
79
def do_intro(self, category):
80
def exclude_func(test, category=category):
81
return category not in test.categories
85
self.show_test_common()
88
manager_tests = self.application.test_manager.get_iterator()
89
self.tests = Excluder(manager_tests, exclude_func, exclude_func)
90
self.test = self.tests.next()
93
def show_test_common(self):
95
self.direction_buttons = {}
96
for direction in ['previous', 'next']:
97
button = self.wTree.get_widget("%s_button" % direction)
98
func = getattr(self, "do_%s" % direction)
99
button.connect("clicked", lambda w, func=func: func())
101
self.direction_buttons[direction] = button
103
def hide_test_common(self):
104
for direction_button in self.direction_buttons.values():
105
direction_button.destroy()
108
result = self.test.result
111
gtk.rc_parse_string('gtk_font_name = "Sans 8"')
112
self.content_txt = self.root.add(gnomecanvas.CanvasRichText, x=30,
113
y=10, width=300, height=180, text=self.test.description, cursor_visible=False)
114
self.content_line = self.root.add(gnomecanvas.CanvasLine,
115
points=[30, 120, 430, 120], width_pixels=1,
116
fill_color_rgba=288581136)
117
gtk.rc_reset_styles(gtk.settings_get_default())
121
self.radio_buttons = {}
122
for status in ALL_STATUS:
123
button = gtk.RadioButton(previous, status.capitalize())
125
self.radio_buttons[status] = button
126
if result and result.status is status:
127
button.set_active(True)
129
radio_vbox = gtk.VBox(False, 0)
130
radio_hbox = gtk.HBox(False, 0)
131
for status in ALL_STATUS:
132
radio_vbox.pack_start(self.radio_buttons[status], False, False, 2)
133
radio_hbox.pack_start(radio_vbox, False, False, 0)
134
radio_hbox.show_all()
135
self.radio_win = self.root.add(gnomecanvas.CanvasWidget,
136
x=40, y=160, widget=radio_hbox, width=140, height=100)
139
self.direction_buttons["previous"].set_sensitive(self.tests.has_prev())
142
self.comment_txt = self.root.add(gnomecanvas.CanvasText,
143
markup="<span size='10000'><b>%s</b></span>" % "Comments:",
144
fill_color_rgba=288581375, x=225, y=135)
146
comment_bg = gtk.gdk.pixbuf_new_from_file(os.path.join(GUI_DIR, 'comment_bg.png'))
147
self.comment_bg = self.root.add(gnomecanvas.CanvasPixbuf, pixbuf=comment_bg,
148
x=175, y=140, anchor="nw")
150
comment_win = gtk.ScrolledWindow(None, None)
151
comment_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
152
self.comment_buf = gtk.TextView()
153
self.comment_buf.set_editable(True)
154
self.comment_buf.set_cursor_visible(True)
155
self.comment_buf.set_wrap_mode(gtk.WRAP_WORD)
156
if result and result.data:
157
buffer = gtk.TextBuffer()
158
buffer.set_text(result.data)
159
self.comment_buf.set_buffer(buffer)
160
comment_win.add(self.comment_buf)
161
comment_win.show_all()
162
self.comment_win = self.root.add(gnomecanvas.CanvasWidget,
163
x=185, y=150, widget=comment_win, width=220, height=120)
166
self.content_txt.destroy()
167
self.content_line.destroy()
168
for radio_button in self.radio_buttons.values():
169
radio_button.destroy()
170
self.radio_win.destroy()
171
self.comment_txt.destroy()
172
self.comment_bg.destroy()
173
self.comment_buf.destroy()
174
self.comment_win.destroy()
176
def do_previous(self):
177
if self.tests.has_prev():
178
self.test = self.tests.prev()
185
for radio, button in self.radio_buttons.items():
186
if button.get_active():
190
buffer = self.comment_buf.get_buffer()
191
data = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
193
self.test.create_result(status, data)
195
if self.tests.has_next():
196
self.test = self.tests.next()
201
self.hide_test_common()
202
self.show_send_common()
205
def show_send_common(self):
207
Please enter the secure ID corresponding
208
to the machine being tested."""
209
self.send_txt = self.root.add(gnomecanvas.CanvasText, markup=txt,
210
size=9000, fill_color_rgba=288581136, x=220, y=80)
211
self._fade_in(self.send_txt)
214
table = gtk.Table(rows=1, columns=2, homogeneous=False)
215
self.vbox1.pack_start(table, True, True, 0)
217
secure_id_label = gtk.Label('Secure ID')
218
table.attach(secure_id_label, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND, 2, 2)
219
secure_id_entry = gtk.Entry()
220
table.attach(secure_id_entry, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND, 2, 2)
223
send_button = self.wTree.get_widget('send_button')
224
send_button.connect("clicked",
225
lambda w: self.do_send(secure_id_entry.get_text()))
226
self.vbox1.pack_start(send_button, False, False, 2)
228
self.hbox1.pack_start(self.vbox1, False, False, 0)
229
self.hbox1.show_all()
231
self.login = self.root.add(gnomecanvas.CanvasWidget, x=100, y=120,
232
widget=self.hbox1, width=140, height=160)
234
def hide_send_common(self):
235
self.send_txt.destroy()
238
def show_send(self, error=None):
240
self.error_txt = self.root.add(gnomecanvas.CanvasText, markup=error,
241
size=9000, fill_color_rgba=0xFF000000, x=190, y=20)
242
self._fade_in(self.error_txt)
244
self.error_txt = None
248
self.error_txt.destroy()
250
def do_send(self, secure_id):
253
error = '''Must provide a secure ID.'''
255
application = self.application
256
application.report.secure_id = secure_id
258
error = self.application.plugin_manager.get_error()
261
self.show_send(error)
263
self.hide_send_common()
270
def _fade_in(self, text):
271
i = self.start_color - 538976288
273
while gtk.events_pending():
274
gtk.main_iteration(1)
277
text.set(fill_color_rgba = i)
281
def _fade_out(self, text):
283
while i <= 4294967040:
284
while gtk.events_pending():
285
gtk.main_iteration(1)
286
text.set(fill_color_rgba = i)