Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: client/bin/factory_ui_lib.py

Issue 3226005: Refactory UI to grab shortcut keys, and tests to not look for triggers. (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/bin/factory_ui ('k') | client/deps/factory/startx.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 7
8 # DESCRIPTION : 8 # DESCRIPTION :
9 # 9 #
10 # This library provides convenience routines to launch factory tests. 10 # This library provides convenience routines to launch factory tests.
11 # This includes support for identifying keyboard test switching 11 # This includes support for drawing the test widget in a window at the
12 # triggers, grabbing control of the keyboard and mouse, and making the 12 # proper location, grabbing control of the mouse, and making the mouse
13 # mouse cursor disappear. It also manages communication of any found 13 # cursor disappear.
14 # keyboard triggers to the control process, via writing data to
15 # factory.RESULT_FILE_PATH.
16 14
17 15
18 from autotest_lib.client.bin import factory 16 from autotest_lib.client.bin import factory
19 from autotest_lib.client.common_lib import error 17 from autotest_lib.client.common_lib import error
20 18
21 from factory import ACTIVE, PASSED, FAILED, UNTESTED, STATUS_CODE_MAP 19 from factory import ACTIVE, PASSED, FAILED, UNTESTED, STATUS_CODE_MAP
22 20
23 import cairo 21 import cairo
24 import gtk 22 import gtk
25 import pango 23 import pango
26 import sys 24 import sys
27 25
28 26
29 BLACK = gtk.gdk.Color() 27 BLACK = gtk.gdk.Color()
30 RED = gtk.gdk.Color(0xFFFF, 0, 0) 28 RED = gtk.gdk.Color(0xFFFF, 0, 0)
31 GREEN = gtk.gdk.Color(0, 0xFFFF, 0) 29 GREEN = gtk.gdk.Color(0, 0xFFFF, 0)
32 BLUE = gtk.gdk.Color(0, 0, 0xFFFF) 30 BLUE = gtk.gdk.Color(0, 0, 0xFFFF)
33 WHITE = gtk.gdk.Color(0xFFFF, 0xFFFF, 0xFFFF) 31 WHITE = gtk.gdk.Color(0xFFFF, 0xFFFF, 0xFFFF)
34 32
35 LIGHT_GREEN = gtk.gdk.color_parse('light green') 33 LIGHT_GREEN = gtk.gdk.color_parse('light green')
36 34
35 SEP_COLOR = gtk.gdk.color_parse('grey50')
36
37 RGBA_GREEN_OVERLAY = (0, 0.5, 0, 0.6) 37 RGBA_GREEN_OVERLAY = (0, 0.5, 0, 0.6)
38 RGBA_YELLOW_OVERLAY = (0.6, 0.6, 0, 0.6) 38 RGBA_YELLOW_OVERLAY = (0.6, 0.6, 0, 0.6)
39 39
40 LABEL_COLORS = { 40 LABEL_COLORS = {
41 ACTIVE: gtk.gdk.color_parse('light goldenrod'), 41 ACTIVE: gtk.gdk.color_parse('light goldenrod'),
42 PASSED: gtk.gdk.color_parse('pale green'), 42 PASSED: gtk.gdk.color_parse('pale green'),
43 FAILED: gtk.gdk.color_parse('tomato'), 43 FAILED: gtk.gdk.color_parse('tomato'),
44 UNTESTED: gtk.gdk.color_parse('dark slate grey')} 44 UNTESTED: gtk.gdk.color_parse('dark slate grey')}
45 45
46 LABEL_FONT = pango.FontDescription('courier new condensed 16') 46 LABEL_FONT = pango.FontDescription('courier new condensed 16')
(...skipping 10 matching lines...) Expand all
57 l = gtk.Label(message) 57 l = gtk.Label(message)
58 l.modify_font(font) 58 l.modify_font(font)
59 l.modify_fg(gtk.STATE_NORMAL, fg) 59 l.modify_fg(gtk.STATE_NORMAL, fg)
60 if size: 60 if size:
61 l.set_size_request(*size) 61 l.set_size_request(*size)
62 if alignment: 62 if alignment:
63 l.set_alignment(*alignment) 63 l.set_alignment(*alignment)
64 return l 64 return l
65 65
66 66
67 def make_hsep(width=1):
68 frame = gtk.EventBox()
69 frame.set_size_request(-1, width)
70 frame.modify_bg(gtk.STATE_NORMAL, SEP_COLOR)
71 return frame
72
73
74 def make_vsep(width=1):
75 frame = gtk.EventBox()
76 frame.set_size_request(width, -1)
77 frame.modify_bg(gtk.STATE_NORMAL, SEP_COLOR)
78 return frame
79
80
67 def make_countdown_widget(): 81 def make_countdown_widget():
68 title = make_label('time remaining / 剩餘時間: ', alignment=(1, 0.5)) 82 title = make_label('time remaining / 剩餘時間: ', alignment=(1, 0.5))
69 countdown = make_label('%d' % FAIL_TIMEOUT, alignment=(0, 0.5)) 83 countdown = make_label('%d' % FAIL_TIMEOUT, alignment=(0, 0.5))
70 hbox = gtk.HBox() 84 hbox = gtk.HBox()
71 hbox.pack_start(title) 85 hbox.pack_start(title)
72 hbox.pack_start(countdown) 86 hbox.pack_start(countdown)
73 eb = gtk.EventBox() 87 eb = gtk.EventBox()
74 eb.modify_bg(gtk.STATE_NORMAL, BLACK) 88 eb.modify_bg(gtk.STATE_NORMAL, BLACK)
75 eb.add(hbox) 89 eb.add(hbox)
76 return eb, countdown 90 return eb, countdown
77 91
78 92
79 def hide_cursor(gdk_window): 93 def hide_cursor(gdk_window):
80 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1) 94 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
81 color = gtk.gdk.Color() 95 color = gtk.gdk.Color()
82 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0) 96 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
83 gdk_window.set_cursor(cursor) 97 gdk_window.set_cursor(cursor)
84 98
85 99
86 class State: 100 def run_test_widget(job, test_widget,
101 invisible_cursor=True,
102 window_registration_callback=None,
103 cleanup_callback=None):
87 104
88 def __init__(self, trigger_set=set()): 105 test_widget_size = job.factory_shared_dict.get('test_widget_size')
89 self._got_trigger = None
90 self._trigger_set = [ord(x) for x in trigger_set]
91 106
92 def exit_on_trigger(self, event): 107 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
93 char = event.keyval in range(32,127) and chr(event.keyval) or None 108 window.modify_bg(gtk.STATE_NORMAL, BLACK)
94 if ('GDK_CONTROL_MASK' not in event.state.value_names 109 window.set_size_request(*test_widget_size)
95 or event.keyval not in self._trigger_set):
96 return False
97 factory.log('got test switch trigger %s(%s)' % (event.keyval, char))
98 self._got_trigger = char
99 gtk.main_quit()
100 return True
101 110
102 def run_test_widget(self, 111 align = gtk.Alignment(xalign=0.5, yalign=0.5)
103 test_widget=None, 112 align.add(test_widget)
104 test_widget_size=None,
105 invisible_cursor=True,
106 window_registration_callback=None,
107 cleanup_callback=None):
108 113
109 window = gtk.Window(gtk.WINDOW_TOPLEVEL) 114 window.add(align)
110 window.modify_bg(gtk.STATE_NORMAL, BLACK) 115 window.show_all()
111 window.set_size_request(*test_widget_size)
112 116
113 align = gtk.Alignment(xalign=0.5, yalign=0.5) 117 if window_registration_callback is not None:
114 align.add(test_widget) 118 window_registration_callback(window)
115 119
116 window.add(align) 120 gtk.gdk.pointer_grab(window.window, confine_to=window.window)
117 window.show_all()
118 121
119 gtk.gdk.pointer_grab(window.window, confine_to=window.window) 122 if invisible_cursor:
120 gtk.gdk.keyboard_grab(window.window) 123 hide_cursor(window.window)
121 124
122 if invisible_cursor: 125 gtk.main()
123 hide_cursor(window.window)
124 126
125 if window_registration_callback is not None: 127 gtk.gdk.pointer_ungrab()
126 window_registration_callback(window)
127 128
128 factory.log('factory_test running gtk.main') 129 if cleanup_callback is not None:
129 gtk.main() 130 cleanup_callback()
130 factory.log('factory_test quit gtk.main')
131
132 if cleanup_callback is not None:
133 cleanup_callback()
134
135 gtk.gdk.pointer_ungrab()
136 gtk.gdk.keyboard_ungrab()
137
138 if self._got_trigger is not None:
139 factory.log('run_test_widget returning kbd_shortcut "%s"' %
140 self._got_trigger)
141 factory.log_shared_data('activated_kbd_shortcut', self._got_trigger)
OLDNEW
« no previous file with comments | « client/bin/factory_ui ('k') | client/deps/factory/startx.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698