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
window = self.wTree.get_widget("window")
36
window.set_resizable(False)
37
window.set_size_request(450, 410)
38
window.set_icon_from_file(os.path.join(GUI_DIR, 'ubuntu_logo.png'))
39
window.connect("destroy", lambda w: gtk.main_quit())
41
# Vertical and horizontal boxes
42
self.vbox1 = gtk.VBox(False, 0)
43
self.hbox1 = gtk.HBox(False, 0)
47
text = "<big><b>%s</b></big>\n%s" % (self.application.title, self.application.intro)
48
self.intro = self.root.add(gnomecanvas.CanvasText,
49
markup=text, size=9000, fill_color_rgba=self.start_color, x=220, y=80)
50
self._fade_in(self.intro)
52
# Vertical and horizontal boxes
53
self.vbox2 = gtk.VBox(False, 0)
54
self.hbox2 = gtk.HBox(False, 0)
55
for category in ALL_CATEGORIES:
56
button_name = '%s_button' % category
57
type_button = self.wTree.get_widget(button_name)
58
type_button.connect("clicked", lambda w, category=category: self.do_intro(category))
60
self.vbox2.pack_start(type_button, False, False, 2)
62
self.hbox2.pack_start(self.vbox2, False, False, 0)
64
self.category = self.root.add(gnomecanvas.CanvasWidget, x=180, y=160,
65
widget=self.hbox2, width=140, height=80)
69
self.category.destroy()
71
def do_intro(self, category):
72
def exclude_func(test, category=category):
73
return category not in test.categories
77
self.show_test_common()
80
manager_tests = self.application.test_manager.get_iterator()
81
self.tests = Excluder(manager_tests, exclude_func, exclude_func)
82
self.test = self.tests.next()
85
def show_test_common(self):
87
self.direction_buttons = {}
88
for direction in ['previous', 'next']:
89
button = self.wTree.get_widget("%s_button" % direction)
90
func = getattr(self, "do_%s" % direction)
91
button.connect("clicked", lambda w, func=func: func())
93
self.direction_buttons[direction] = button
95
def hide_test_common(self):
96
for direction_button in self.direction_buttons.values():
97
direction_button.destroy()
100
result = self.test.result
103
gtk.rc_parse_string('gtk_font_name = "Sans 8"')
104
self.content_txt = self.root.add(gnomecanvas.CanvasRichText, x=30,
105
y=10, width=300, height=180, text=self.test.description, cursor_visible=False)
106
self.content_line = self.root.add(gnomecanvas.CanvasLine,
107
points=[30, 120, 430, 120], width_pixels=1,
108
fill_color_rgba=288581136)
109
gtk.rc_reset_styles(gtk.settings_get_default())
113
self.radio_buttons = {}
114
for status in ALL_STATUS:
115
button = gtk.RadioButton(previous, status.capitalize())
117
self.radio_buttons[status] = button
118
if result and result.status is status:
119
button.set_active(True)
121
radio_vbox = gtk.VBox(False, 0)
122
radio_hbox = gtk.HBox(False, 0)
123
for status in ALL_STATUS:
124
radio_vbox.pack_start(self.radio_buttons[status], False, False, 2)
125
radio_hbox.pack_start(radio_vbox, False, False, 0)
126
radio_hbox.show_all()
127
self.radio_win = self.root.add(gnomecanvas.CanvasWidget,
128
x=40, y=160, widget=radio_hbox, width=140, height=100)
131
self.direction_buttons["previous"].set_sensitive(self.tests.has_prev())
134
self.comment_txt = self.root.add(gnomecanvas.CanvasText,
135
markup="<span size='10000'><b>%s</b></span>" % "Comments:",
136
fill_color_rgba=288581375, x=225, y=135)
138
comment_bg = gtk.gdk.pixbuf_new_from_file(os.path.join(GUI_DIR, 'comment_bg.png'))
139
self.comment_bg = self.root.add(gnomecanvas.CanvasPixbuf, pixbuf=comment_bg,
140
x=175, y=140, anchor="nw")
142
comment_win = gtk.ScrolledWindow(None, None)
143
comment_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
144
self.comment_buf = gtk.TextView()
145
self.comment_buf.set_editable(True)
146
self.comment_buf.set_cursor_visible(True)
147
self.comment_buf.set_wrap_mode(gtk.WRAP_WORD)
148
if result and result.data:
149
buffer = gtk.TextBuffer()
150
buffer.set_text(result.data)
151
self.comment_buf.set_buffer(buffer)
152
comment_win.add(self.comment_buf)
153
comment_win.show_all()
154
self.comment_win = self.root.add(gnomecanvas.CanvasWidget,
155
x=185, y=150, widget=comment_win, width=220, height=120)
158
self.content_txt.destroy()
159
self.content_line.destroy()
160
for radio_button in self.radio_buttons.values():
161
radio_button.destroy()
162
self.radio_win.destroy()
163
self.comment_txt.destroy()
164
self.comment_bg.destroy()
165
self.comment_buf.destroy()
166
self.comment_win.destroy()
168
def do_previous(self):
169
if self.tests.has_prev():
170
self.test = self.tests.prev()
177
for radio, button in self.radio_buttons.items():
178
if button.get_active():
182
buffer = self.comment_buf.get_buffer()
183
data = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
185
self.test.create_result(status, data)
187
if self.tests.has_next():
188
self.test = self.tests.next()
193
self.hide_test_common()
194
self.show_send_common()
197
def show_send_common(self):
199
Please enter the secure ID corresponding
200
to the machine being tested."""
201
self.send_txt = self.root.add(gnomecanvas.CanvasText, markup=txt,
202
size=9000, fill_color_rgba=288581136, x=220, y=80)
203
self._fade_in(self.send_txt)
206
table = gtk.Table(rows=1, columns=2, homogeneous=False)
207
self.vbox1.pack_start(table, True, True, 0)
209
secure_id_label = gtk.Label('Secure ID')
210
table.attach(secure_id_label, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND, 2, 2)
211
secure_id_entry = gtk.Entry()
212
table.attach(secure_id_entry, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND, 2, 2)
215
send_button = self.wTree.get_widget('send_button')
216
send_button.connect("clicked",
217
lambda w: self.do_send(secure_id_entry.get_text()))
218
self.vbox1.pack_start(send_button, False, False, 2)
220
self.hbox1.pack_start(self.vbox1, False, False, 0)
221
self.hbox1.show_all()
223
self.login = self.root.add(gnomecanvas.CanvasWidget, x=100, y=120,
224
widget=self.hbox1, width=140, height=160)
226
def hide_send_common(self):
227
self.send_txt.destroy()
230
def show_send(self, error=None):
232
self.error_txt = self.root.add(gnomecanvas.CanvasText, markup=error,
233
size=9000, fill_color_rgba=0xFF000000, x=190, y=20)
234
self._fade_in(self.error_txt)
236
self.error_txt = None
240
self.error_txt.destroy()
242
def do_send(self, secure_id):
245
error = '''Must provide a secure ID.'''
247
application = self.application
248
application.message_store.set_secure_id(secure_id)
250
error = self.application.plugin_manager.get_error()
253
self.show_send(error)
255
self.hide_send_common()
262
def _fade_in(self, text):
263
i = self.start_color - 538976288
265
while gtk.events_pending():
266
gtk.main_iteration(1)
269
text.set(fill_color_rgba = i)
273
def _fade_out(self, text):
275
while i <= 4294967040:
276
while gtk.events_pending():
277
gtk.main_iteration(1)
278
text.set(fill_color_rgba = i)