dfd23a44de
Add a new module "layout" that will eventually evolve into the only keyboard layout module. Right now, it uses an external binary (get-kbd-layout) to determine the layout of a keyboard device (because I did not manage to call libX11 with ctypes correctly). see #788 see #790
39 lines
1 KiB
Python
39 lines
1 KiB
Python
# pylint: disable=C0111,R0903
|
|
|
|
"""Displays the current keyboard layout
|
|
|
|
Parameters:
|
|
* layout.device: The device ID of the keyboard (as reported by `xinput -list`), defaults to the core device
|
|
"""
|
|
|
|
import re
|
|
|
|
import core.widget
|
|
import core.module
|
|
|
|
import util.cli
|
|
|
|
from bumblebee_status.discover import utility
|
|
|
|
class Module(core.module.Module):
|
|
def __init__(self, config, theme):
|
|
super().__init__(config=config, theme=theme, widgets=core.widget.Widget(self.get_layout))
|
|
|
|
self._cmd = utility("get-kbd-layout")
|
|
keyboard = self.parameter("device", None)
|
|
if keyboard:
|
|
self._cmd += " {}".format(keyboard)
|
|
|
|
def get_layout(self, widget):
|
|
result = util.cli.execute(self._cmd, ignore_errors=True)
|
|
|
|
m = re.search("([a-zA-Z]+_)?([a-zA-Z]+)(\(([\w-]+)\))?", result)
|
|
|
|
if m:
|
|
layout = m.group(2)
|
|
variant = m.group(3)
|
|
return layout if not variant else "{} {}".format(layout, variant)
|
|
|
|
return "n/a"
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|