[modules/layout] add a new - generic - layout module
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
This commit is contained in:
parent
902288f30d
commit
dfd23a44de
5 changed files with 93 additions and 0 deletions
39
bumblebee_status/modules/core/layout.py
Normal file
39
bumblebee_status/modules/core/layout.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# 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
|
Loading…
Add table
Add a link
Reference in a new issue