VKeyboard: Virtual keyboard with custom layout support

# Jump directly to Examples

VKeyboard: Virtual keyboard with custom layout support

class pymt.ui.widgets.composed.vkeyboard.MTVKeyboard(**kwargs)

Bases: pymt.ui.widgets.scatter.MTScatterWidget

MTVKeyboard is an onscreen keyboard with multitouch support. Its layout is entirely customizable and you can switch between available layouts using a button in the bottom right of the widget.

Parameters :
layout : KeyboardLayout object, default to None

If None, keyboard layout will be created from configuration property.

time_lazy_update : float, default to 0.2

Time in seconds to force a lazy update when keyboard size changes

repeat : float, default to 0.2

Key repeat rate. 1/15. will repeat the last key 5 times per seconds

repeat_timeout : float, default to 0.2

Will start to repeat the key after 200ms

Events :
on_key_down : key

Fired when a key is down. The key contains: displayed_str, internal_str, internal_action, width

on_key_up : key

Fired when a key is up. The key contains: displayed_str, internal_str, internal_action, width

on_text_change : text

Fired when the internal text is changed

List of internal actions available :

  • backspace
  • capslock
  • enter
  • escape
  • layout (to display layout list)
  • shift
  • shift_L
  • shift_R
static add_custom_layout(layout_class)

Add a custom layout class on MTVKeyboard

clear()

Clear the text

get_key_at_pos(x, y)

Return the key + size info on the current layout, at the coordinate (x, y)

mode

Get/set mode of vkeyboard (NORMAL, SHIFT...)

text

Get/set text string on vkeyboard

class pymt.ui.widgets.composed.vkeyboard.KeyboardLayout

Bases: object

Base for all Keyboard Layout

class pymt.ui.widgets.composed.vkeyboard.KeyboardLayoutQWERTY

Bases: pymt.ui.widgets.composed.vkeyboard.KeyboardLayout

Implementation of QWERTY Layout

class pymt.ui.widgets.composed.vkeyboard.KeyboardLayoutAZERTY

Bases: pymt.ui.widgets.composed.vkeyboard.KeyboardLayout

Implementation of AZERTY Layout

Examples

File ui_widgets_composed_vkeyboardspellcheck.py

from pymt import *
m = MTTextInput(keyboard=MTSpellVKeyboard(), font_size=42)

runTouchApp(m)

File ui_widgets_composed_vkeyboard_numerical.py

from pymt import *

# create a custom layout, a numerical one
class NumericKeyboardLayout(KeyboardLayout):
    ID              = 'numeric'
    TITLE           = 'Numeric keyboard'
    DESCRIPTION     = ''
    SIZE            = (4, 4)
    NORMAL_1 = [
        ('7', '7', None, 1),    ('8', '8', None, 1),    (u'9', u'9', None, 1),
        (u'\u2a2f', None, 'escape', 1),
    ]
    NORMAL_2 = [
        ('4', '4', None, 1),    ('5', '5', None, 1),    (u'6', u'6', None, 1),
    ]
    NORMAL_3 = [
        ('1', '1', None, 1),    ('2', '2', None, 1),    (u'3', u'3', None, 1),
        (u'\u232b', None, 'backspace', 1),
    ]
    NORMAL_4 = [
        ('0', '0', None, 1),    (',', ',', None, 2),
        (u'\u23ce', None, 'enter', 1)
    ]

# create a keyboard, with our custom layout
k = MTVKeyboard(layout=NumericKeyboardLayout(), size=(400, 300))

# create a instance of textinput, with this keyboard by default
m = MTTextInput(keyboard=k)

runTouchApp(m)

File ui_widgets_composed_vkeyboard.py

from pymt import *
keyboard = MTVKeyboard()

@keyboard.event
def on_key_down(*largs):
    print 'key down:', largs

@keyboard.event
def on_key_up(*largs):
    print 'key up:', largs

@keyboard.event
def on_text_change(*largs):
    print 'text change', largs

runTouchApp(keyboard)

Table Of Contents

Previous topic

Video widget: provide a video container

Next topic

SpellVKeyboard: Virtual keyboard that provides spelling

This Page