OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 |
| 6 # DESCRIPTION : |
| 7 # |
| 8 # Select the keyboard type, and write to VPD. |
| 9 |
| 10 |
| 11 import gtk |
| 12 import pango |
| 13 import sys |
| 14 import utils |
| 15 |
| 16 from gtk import gdk |
| 17 |
| 18 from autotest_lib.client.bin import factory |
| 19 from autotest_lib.client.bin import factory_ui_lib as ful |
| 20 from autotest_lib.client.bin import test |
| 21 from autotest_lib.client.common_lib import error |
| 22 |
| 23 # Mapping between menu choice and KB. |
| 24 kb_map = { |
| 25 '1': 'en-US', |
| 26 '2': 'en-GB', |
| 27 'q': None, |
| 28 } |
| 29 |
| 30 # Message to display. |
| 31 msg = ('Choose a keyboard:\n' + |
| 32 "".join([ '%s) %s\n' % (i, kb_map[i]) for i in sorted(kb_map)])) |
| 33 |
| 34 class factory_SelectKeyboard(test.test): |
| 35 version = 1 |
| 36 |
| 37 def write_kb(self, kb): |
| 38 cmd = 'vpd -s "initial_locale"="%s"' % kb |
| 39 utils.system_output(cmd) |
| 40 |
| 41 def key_release_callback(self, widget, event): |
| 42 char = event.keyval in range(32,127) and chr(event.keyval) or None |
| 43 factory.log('key_release %s(%s)' % (event.keyval, char)) |
| 44 if char in kb_map: |
| 45 kb = kb_map[char] |
| 46 factory.log('Keyboard specified as %s, (pressed %s)' % ( |
| 47 kb, char)) |
| 48 |
| 49 if kb: |
| 50 self.write_kb(kb) |
| 51 |
| 52 gtk.main_quit() |
| 53 return True |
| 54 |
| 55 def register_callbacks(self, window): |
| 56 window.connect('key-release-event', self.key_release_callback) |
| 57 window.add_events(gdk.KEY_RELEASE_MASK) |
| 58 |
| 59 def run_once(self): |
| 60 |
| 61 factory.log('%s run_once' % self.__class__) |
| 62 label = ful.make_label(msg) |
| 63 |
| 64 test_widget = gtk.EventBox() |
| 65 test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK) |
| 66 test_widget.add(label) |
| 67 |
| 68 ful.run_test_widget(self.job, test_widget, |
| 69 window_registration_callback=self.register_callbacks) |
| 70 |
| 71 factory.log('%s run_once finished' % repr(self.__class__)) |
OLD | NEW |