Skip to main content

Query and change XKB layout state

Project description

https://img.shields.io/badge/python-3.2+-blue.svg https://img.shields.io/badge/license-MIT-blue.svg

Use this library to change the keyboard layout through XKB extension (subsystem) of the X server system.

Dependencies

  • Python 3.2+

  • libX11.so.6 shared library which you must have by default if you use X server

Usage

# Assume we have the following configuration
$ setxkbmap -layout us,ru,ua,fr
$ python
>>> from xkbgroup import XKeyboard
>>> xkb = XKeyboard()
>>> xkb.group_num
1
>>> xkb.group_num = 2
>>> xkb.group_num
2
>>> xkb.group_num -= 2
>>> xkb.group_num
0
>>> xkb.group_name
English (US)
>>> xkb.group_name = 'Ukrainian'
>>> xkb.group_name
Ukrainian
>>> xkb.group_num
2
>>> xkb.group_symbol
ua
>>> xkb.group_symbol = 'fr'
>>> xkb.group_symbol
fr
>>> xkb.group_variant
''
>>> xkb.group_num -= 3
>>> xkb.group_variant
''
>>> xkb.group_num
0
>>>

Naming convention

Throughout the whole XKB subsystem the so-called groups represent actual keyboard layouts. This library follows the same convention and names of the API methods start with group_ or groups_.

Classes

These all reside in xkbgroup/core.py:

  • XKeyboard — the main class:

    • __init__(self, auto_open=True) — if auto_open is True automatically call open_display().

    • open_display() — establishes connection with X server and prepares objects necessary to retrieve and send data.

    • close_display() — closes connection with X server and cleans up objects created on open_display().

    • group_* — properties for accessing current group data:

      • group_num — get/set current group number (e.g. 0, 2, 3).

      • group_name — get/set current group full name (e.g. English (US), Russian, French).

      • group_symbol — get/set current group symbol (e.g. us, ru, fr).

      • group_variant — get (only) current group variant (e.g. `` , ``dos, latin9)

    • groups_* — properties for querying info about all groups set by setxkbmap

      • groups_count — get number of all groups.

      • groups_names — get names of all groups.

      • groups_symbols — get symbols of all groups.

      • groups_variants — get variants of all groups.

  • X11Error — an exception class, raised for errors on X server issues.

Helper files

There are also complementary files:

  • generate_bindings.sh — a shell script which generates Python bindings to X server structures, functions and #define definitions by:

    • converting X11 C headers using h2xml and xml2py;

    • creating ctypes references to functions from libX11.so.6 using xml2py.

  • xkbgroup/xkb.py — the output of the above script, usable for Xlib development under Python.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xkbgroup-0.1.tar.gz (69.7 kB view hashes)

Uploaded Source

Built Distribution

xkbgroup-0.1-py3-none-any.whl (70.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page