~cherojeong/ubuntu-keyboard/korean-layout

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_keyboard/emulators/keypad.py

  • Committer: Michael Terry
  • Date: 2013-11-04 17:48:55 UTC
  • mfrom: (96 trunk)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: michael.terry@canonical.com-20131104174855-mtmwbdavrq77nl1r
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Ubuntu Keyboard Test Suite
 
4
# Copyright (C) 2013 Canonical
 
5
#
 
6
# This program is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
 
 
20
from ubuntu_keyboard.emulators import UbuntuKeyboardEmulatorBase
 
21
from ubuntu_keyboard.emulators.key import Key
 
22
 
 
23
import logging
 
24
 
 
25
logger = logging.getLogger(__name__)
 
26
 
 
27
 
 
28
class KeyPadState:
 
29
    NORMAL = "NORMAL"
 
30
    SHIFTED = "SHIFTED"
 
31
    CAPSLOCK = "CAPSLOCK"
 
32
 
 
33
 
 
34
class KeyPad(UbuntuKeyboardEmulatorBase):
 
35
    """A basic emulator that provides the details of the keys contained within.
 
36
 
 
37
    """
 
38
 
 
39
    def get_key_details(self):
 
40
        contained_keys = {}
 
41
        key_positions = {}
 
42
 
 
43
        def _iter_keys(key_type, label_fn):
 
44
            for key in self.select_many(key_type):
 
45
                with key.no_automatic_refreshing():
 
46
                    key_pos = Key.Pos(*key.globalRect)
 
47
                    label = label_fn(key)
 
48
                    if label != '':
 
49
                        contained_keys[label] = KeyPadState.NORMAL
 
50
                        key_positions[label] = key_pos
 
51
                    if key.shifted != '':
 
52
                        contained_keys[key.shifted] = KeyPadState.SHIFTED
 
53
                        key_positions[key.shifted] = key_pos
 
54
 
 
55
        _iter_keys("CharKey", lambda x: x.label)
 
56
        _iter_keys("ActionKey", lambda x: x.action)
 
57
 
 
58
        return (contained_keys, key_positions)