[gnome-initial-setup/shell/4765: 283/362] Ubuntu files related to keyboard detection



commit 97dc6b2abe5d47271c6ddaf813b0c6cd6d431a65
Author: Roddy Shuler <roddy endlessm com>
Date:   Tue Nov 25 13:35:18 2014 -0800

    Ubuntu files related to keyboard detection
    
    From ubiquity 2.21.0 source package:
    - ubiquity/keyboard_detector.py
    - ubiquity/frontend/gtk_components/keyboard_query.py
    
    From console-setup 1.70ubuntu9 binary package:
    - /usr/share/console-setup/pc105.tree
    
    Note: pc105.tree is normally generated at build-time by keymaptree.
    We could possibly address the need for this file by installing
    console-setup rather than console-setup-mini (adds about 500 kB
    to image), or perhaps by including the file in console-setup-mini.
    
    [endlessm/eos-shell#3425]

 keyboard-detector/keyboard_detector.py |   99 +++++++
 keyboard-detector/keyboard_query.py    |  130 +++++++++
 keyboard-detector/pc105.tree           |  448 ++++++++++++++++++++++++++++++++
 3 files changed, 677 insertions(+), 0 deletions(-)
---
diff --git a/keyboard-detector/keyboard_detector.py b/keyboard-detector/keyboard_detector.py
new file mode 100644
index 0000000..5ff77df
--- /dev/null
+++ b/keyboard-detector/keyboard_detector.py
@@ -0,0 +1,99 @@
+class KeyboardDetector:
+    UNKNOWN, PRESS_KEY, KEY_PRESENT, KEY_PRESENT_P, RESULT = list(range(5))
+
+    def __init__(self):
+        self.current_step = -1
+        f = '/usr/share/console-setup/pc105.tree'
+        self.fp = open(f)
+
+        # Dictionary of keycode -> step.
+        self.keycodes = {}
+        self.symbols = []
+        self.present = -1
+        self.not_present = -1
+        self.result = ''
+
+    def __del__(self):
+        if self.fp:
+            self.fp.close()
+
+    def read_step(self, step):
+        if self.current_step != -1:
+            valid_steps = (
+                list(self.keycodes.values()) +
+                [self.present] + [self.not_present])
+            if step not in valid_steps:
+                raise KeyError('invalid argument')
+            if self.result:
+                raise Exception('already done')
+
+        step_type = KeyboardDetector.UNKNOWN
+        self.keycodes = {}
+        self.symbols = []
+        self.present = -1
+        self.not_present = -1
+        self.result = ''
+
+        for line in self.fp:
+            if line.startswith('STEP '):
+                # This line starts a new step.
+                if self.current_step == step:
+                    self.current_step = int(line[5:])
+                    return step_type
+                else:
+                    self.current_step = int(line[5:])
+            elif self.current_step != step:
+                continue
+            elif line.startswith('PRESS '):
+                # Ask the user to press a character on the keyboard.
+                if step_type == KeyboardDetector.UNKNOWN:
+                    step_type = KeyboardDetector.PRESS_KEY
+                if step_type != KeyboardDetector.PRESS_KEY:
+                    raise Exception
+                self.symbols.append(line[6:].strip())
+            elif line.startswith('CODE '):
+                # Direct the evaluating code to process step ## next if the
+                # user has pressed a key which returned that keycode.
+                if step_type != KeyboardDetector.PRESS_KEY:
+                    raise Exception
+                keycode = int(line[5:line.find(' ', 5)])
+                s = int(line[line.find(' ', 5) + 1:])
+                self.keycodes[keycode] = s
+            elif line.startswith('FIND '):
+                # Ask the user whether that character is present on their
+                # keyboard.
+                if step_type == KeyboardDetector.UNKNOWN:
+                    step_type = KeyboardDetector.KEY_PRESENT
+                else:
+                    raise Exception
+                self.symbols = [line[5:].strip()]
+            elif line.startswith('FINDP '):
+                # Equivalent to FIND, except that the user is asked to consider
+                # only the primary symbols (i.e. Plain and Shift).
+                if step_type == KeyboardDetector.UNKNOWN:
+                    step_type = KeyboardDetector.KEY_PRESENT_P
+                else:
+                    raise Exception
+                self.symbols = [line[6:].strip()]
+            elif line.startswith('YES '):
+                # Direct the evaluating code to process step ## next if the
+                # user does have this key.
+                if (step_type != KeyboardDetector.KEY_PRESENT_P and
+                        step_type != KeyboardDetector.KEY_PRESENT):
+                    raise Exception
+                self.present = int(line[4:].strip())
+            elif line.startswith('NO '):
+                # Direct the evaluating code to process step ## next if the
+                # user does not have this key.
+                if (step_type != KeyboardDetector.KEY_PRESENT_P and
+                        step_type != KeyboardDetector.KEY_PRESENT):
+                    raise Exception
+                self.not_present = int(line[3:].strip())
+            elif line.startswith('MAP '):
+                # This step uniquely identifies a keymap.
+                if step_type == KeyboardDetector.UNKNOWN:
+                    step_type = KeyboardDetector.RESULT
+                self.result = line[4:].strip()
+                return step_type
+            else:
+                raise Exception
diff --git a/keyboard-detector/keyboard_query.py b/keyboard-detector/keyboard_query.py
new file mode 100644
index 0000000..a33adad
--- /dev/null
+++ b/keyboard-detector/keyboard_query.py
@@ -0,0 +1,130 @@
+from gi.repository import Gtk, GObject, Gdk
+
+from ubiquity import keyboard_detector
+
+
+class Keyrow(Gtk.Box):
+    def __init__(self):
+        GObject.GObject.__init__(self, spacing=24)
+
+    def add_character(self, key):
+        l = Gtk.Label(label='<big>%s</big>' % key)
+        l.set_use_markup(True)
+        self.pack_start(l, True, True, 0)
+        l.show()
+
+    def clear(self):
+        for ch in self.get_children():
+            self.remove(ch)
+
+
+class KeyboardQuery(Gtk.Window):
+    __gtype_name__ = 'KeyboardQuery'
+    __gsignals__ = {
+        'layout_result': (
+            GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_STRING,)),
+    }
+
+    def __init__(self, frontend):
+        Gtk.Window.__init__(self)
+
+        self.set_title(
+            frontend.get_string('ubiquity/text/keyboard_query_title'))
+        self.set_keep_above(True)
+        self.set_modal(True)
+        self.set_border_width(20)
+        self.set_property('resizable', False)
+        # TODO if we can allocate the space we'll need ahead of time, we can
+        # use center_on_parent here.
+        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
+        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
+        self.vbox = Gtk.Box(spacing=10)
+        self.vbox.set_orientation(Gtk.Orientation.VERTICAL)
+
+        self.press_string = \
+            frontend.get_string('ubiquity/text/keyboard_query_press')
+        self.present_string = \
+            frontend.get_string('ubiquity/text/keyboard_query_present')
+        self.heading = Gtk.Label(label=self.press_string)
+        self.heading.set_alignment(0, 0.5)
+        self.vbox.pack_start(self.heading, False, True, 0)
+
+        self.keyrow = Keyrow()
+        self.vbox.pack_start(self.keyrow, False, True, 0)
+
+        self.buttons = Gtk.ButtonBox()
+        self.buttons.set_spacing(12)
+        self.buttons.set_layout(Gtk.ButtonBoxStyle.START)
+        # FIXME evand 2009-12-16: i18n
+        no = Gtk.Button(stock=Gtk.STOCK_NO)
+        yes = Gtk.Button(stock=Gtk.STOCK_YES)
+        self.buttons.add(no)
+        self.buttons.add(yes)
+        self.vbox.add(self.buttons)
+
+        self.add(self.vbox)
+
+        yes.connect('clicked', self.have_key)
+        no.connect('clicked', self.no_have_key)
+        self.connect('key_press_event', self.key_press_event)
+
+        self.keyboard_detect = keyboard_detector.KeyboardDetector()
+        self.buttons.hide()
+
+    def run(self, *args):
+        self.show_all()
+        r = self.keyboard_detect.read_step(0)
+        self.process(r)
+
+    def process(self, r):
+        self.keyrow.clear()
+        for k in self.keyboard_detect.symbols:
+            self.keyrow.add_character(k)
+        if r == keyboard_detector.KeyboardDetector.PRESS_KEY:
+            self.heading.set_label(self.press_string)
+            self.buttons.hide()
+        elif (r == keyboard_detector.KeyboardDetector.KEY_PRESENT or
+              r == keyboard_detector.KeyboardDetector.KEY_PRESENT_P):
+            self.heading.set_label(self.present_string)
+            self.buttons.show()
+        elif r == keyboard_detector.KeyboardDetector.RESULT:
+            self.emit('layout_result', self.keyboard_detect.result)
+            self.hide()
+        else:
+            raise Exception('should not have got here')
+
+    def have_key(self, *args):
+        try:
+            r = self.keyboard_detect.read_step(self.keyboard_detect.present)
+            self.process(r)
+        except:
+            self.hide()
+
+    def no_have_key(self, *args):
+        try:
+            r = self.keyboard_detect.read_step(
+                self.keyboard_detect.not_present)
+            self.process(r)
+        except:
+            self.hide()
+
+    def key_press_event(self, widget, event):
+        # FIXME need to account for possible remapping.  Find the API to
+        # translate kernel keycodes to X keycodes (xkb).
+        # MIN_KEYCODE = 8
+
+        # FIXME escape should close the window.
+
+        code = event.hardware_keycode - 8
+        if code > 255:
+            return
+        if code in self.keyboard_detect.keycodes:
+            # XKB doesn't support keycodes > 255.
+            c = self.keyboard_detect.keycodes[code]
+            try:
+                r = self.keyboard_detect.read_step(c)
+                self.process(r)
+            except:
+                self.hide()
+
+GObject.type_register(KeyboardQuery)
diff --git a/keyboard-detector/pc105.tree b/keyboard-detector/pc105.tree
new file mode 100644
index 0000000..57c1995
--- /dev/null
+++ b/keyboard-detector/pc105.tree
@@ -0,0 +1,448 @@
+STEP 0
+PRESS )
+PRESS у
+PRESS υ
+PRESS г
+PRESS n
+PRESS γ
+PRESS u
+PRESS ה
+PRESS v
+PRESS y
+PRESS ν
+CODE 10 1
+CODE 11 39
+CODE 12 76
+CODE 17 44
+CODE 18 63
+CODE 20 40
+CODE 21 83
+CODE 22 104
+CODE 23 2
+CODE 27 108
+CODE 30 2
+CODE 33 40
+CODE 34 41
+CODE 35 44
+CODE 38 40
+CODE 39 2
+CODE 41 44
+CODE 43 91
+CODE 44 106
+CODE 45 68
+CODE 46 2
+CODE 47 104
+CODE 49 104
+CODE 52 40
+STEP 1
+PRESS b
+PRESS ß
+PRESS y
+PRESS v
+PRESS u
+PRESS ה
+PRESS n
+CODE 39 2
+CODE 40 3
+CODE 44 6
+CODE 12 9
+CODE 46 2
+CODE 47 11
+CODE 48 11
+CODE 49 11
+CODE 51 2
+CODE 21 12
+CODE 22 11
+CODE 23 2
+CODE 30 2
+CODE 31 34
+STEP 3
+FINDP ö
+YES 5
+NO 4
+STEP 11
+PRESS z
+CODE 44 12
+CODE 21 6
+STEP 12
+FINDP ö
+YES 26
+NO 13
+STEP 13
+FINDP ç
+YES 21
+NO 14
+STEP 14
+FINDP æ
+YES 18
+NO 15
+STEP 15
+FINDP ñ
+YES 17
+NO 16
+STEP 6
+FINDP ö
+YES 7
+NO 4
+STEP 34
+PRESS z
+CODE 44 35
+CODE 21 8
+STEP 35
+FINDP ö
+YES 38
+NO 36
+STEP 36
+FINDP ç
+YES 21
+NO 37
+STEP 37
+PRESS æ
+CODE 40 19
+CODE 30 17
+CODE 39 20
+STEP 38
+PRESS ö
+CODE 12 28
+CODE 39 31
+STEP 39
+PRESS r
+PRESS у
+PRESS υ
+PRESS г
+PRESS n
+PRESS γ
+PRESS u
+PRESS ה
+PRESS v
+PRESS y
+PRESS ν
+CODE 33 40
+CODE 34 41
+CODE 35 44
+CODE 38 40
+CODE 17 44
+CODE 47 45
+CODE 49 45
+CODE 18 63
+CODE 19 45
+CODE 20 40
+CODE 21 45
+CODE 22 45
+CODE 24 40
+CODE 52 40
+STEP 45
+FINDP ș
+YES 75
+NO 46
+STEP 46
+FINDP é
+YES 74
+NO 47
+STEP 47
+FINDP ç
+YES 73
+NO 48
+STEP 48
+FINDP š
+YES 72
+NO 49
+STEP 83
+PRESS ω
+PRESS w
+CODE 16 84
+CODE 17 94
+CODE 44 76
+CODE 30 80
+CODE 47 42
+STEP 84
+PRESS q
+CODE 16 85
+CODE 30 81
+STEP 41
+FINDP ч
+YES 43
+NO 42
+STEP 2
+MAP tr:f
+STEP 104
+PRESS ω
+PRESS w
+CODE 16 105
+CODE 17 109
+CODE 44 76
+CODE 30 80
+CODE 47 42
+STEP 105
+PRESS z
+CODE 17 81
+CODE 44 85
+CODE 21 106
+STEP 85
+FINDP ö
+YES 92
+NO 86
+STEP 86
+FINDP ç
+YES 21
+NO 87
+STEP 87
+FINDP å
+YES 18
+NO 88
+STEP 88
+FINDP ä
+YES 91
+NO 89
+STEP 89
+FINDP ñ
+YES 17
+NO 90
+STEP 90
+PRESS @
+CODE 16 71
+CODE 40 71
+CODE 3 62
+STEP 21
+PRESS ç
+CODE 43 22
+CODE 39 23
+STEP 23
+FINDP è
+YES 25
+NO 24
+STEP 92
+PRESS ö
+CODE 51 27
+CODE 12 28
+CODE 39 93
+STEP 93
+FINDP ü
+YES 30
+NO 32
+STEP 109
+PRESS z
+PRESS ζ
+CODE 44 94
+CODE 21 106
+STEP 94
+FINDP ö
+YES 26
+NO 95
+STEP 95
+FINDP é
+YES 103
+NO 96
+STEP 96
+FINDP ç
+YES 101
+NO 97
+STEP 97
+FINDP æ
+YES 18
+NO 98
+STEP 98
+FINDP ș
+YES 75
+NO 99
+STEP 99
+FINDP š
+YES 72
+NO 100
+STEP 100
+FINDP ñ
+YES 17
+NO 49
+STEP 49
+FINDP £
+YES 71
+NO 50
+STEP 50
+FINDP ¨
+YES 70
+NO 51
+STEP 51
+FINDP ѝ
+YES 44
+NO 52
+STEP 52
+FINDP ș
+YES 69
+NO 53
+STEP 53
+FINDP ψ
+YES 42
+NO 54
+STEP 54
+FINDP ב
+YES 16
+NO 55
+STEP 55
+FINDP љ
+YES 43
+NO 56
+STEP 56
+FINDP ภ
+YES 68
+NO 57
+STEP 57
+FINDP ч
+YES 63
+NO 58
+STEP 58
+FINDP ə
+YES 62
+NO 59
+STEP 59
+FINDP š
+YES 61
+NO 60
+STEP 60
+MAP us
+STEP 61
+MAP lv
+STEP 62
+MAP pl
+STEP 63
+FINDP ы
+YES 65
+NO 64
+STEP 64
+MAP ua
+STEP 65
+FINDP и
+YES 67
+NO 66
+STEP 66
+MAP by
+STEP 67
+MAP ru
+STEP 68
+MAP th:tis
+STEP 43
+MAP mk
+STEP 16
+MAP il
+STEP 69
+MAP ro
+STEP 44
+MAP bg
+STEP 70
+MAP us:intl
+STEP 71
+MAP gb
+STEP 17
+MAP latam
+STEP 72
+MAP lt
+STEP 75
+MAP ro:std
+STEP 18
+PRESS æ
+CODE 40 19
+CODE 39 20
+STEP 19
+MAP no
+STEP 20
+MAP dk
+STEP 101
+PRESS º
+CODE 40 24
+CODE 41 22
+CODE 50 102
+CODE 43 73
+CODE 86 73
+STEP 102
+PRESS ç
+CODE 43 22
+CODE 39 24
+STEP 22
+MAP es
+STEP 24
+MAP pt
+STEP 73
+MAP br
+STEP 103
+PRESS é
+CODE 26 25
+CODE 11 91
+CODE 53 74
+STEP 25
+MAP it
+STEP 91
+MAP sk:qwerty
+STEP 74
+MAP ca
+STEP 26
+PRESS ö
+CODE 51 27
+CODE 12 28
+CODE 39 29
+STEP 27
+MAP tr
+STEP 28
+MAP is
+STEP 29
+FINDP å
+YES 31
+NO 30
+STEP 30
+MAP ee
+STEP 31
+FINDP ə
+YES 33
+NO 32
+STEP 32
+MAP se
+STEP 33
+MAP fi
+STEP 106
+FINDP ö
+YES 7
+NO 107
+STEP 107
+PRESS š
+CODE 26 4
+CODE 4 108
+STEP 4
+MAP hr
+STEP 108
+MAP cz
+STEP 7
+PRESS ö
+CODE 11 5
+CODE 39 8
+STEP 5
+MAP hu
+STEP 8
+FINDP é
+YES 10
+NO 9
+STEP 9
+MAP de:nodeadkeys
+STEP 10
+MAP ch
+STEP 76
+FINDP œ
+YES 82
+NO 77
+STEP 77
+FINDP º
+YES 79
+NO 78
+STEP 78
+MAP fr:oss
+STEP 79
+FINDP œ
+YES 81
+NO 80
+STEP 81
+MAP be
+STEP 82
+MAP fr:latin9
+STEP 80
+MAP fr
+STEP 42
+MAP gr
+STEP 40
+MAP us:dvorak


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]