[core] restructure to allow PIP packaging
OK - so I have to admit I *hate* the fact that PIP seems to require a subdirectory named like the library. But since the PIP package is something really nifty to have (thanks to @tony again!!!), I updated the codebase to hopefully conform with what PIP expects. Testruns so far look promising...
This commit is contained in:
parent
1d25be2059
commit
320827d577
146 changed files with 2509 additions and 2 deletions
71
bumblebee_status/modules/core/layout-xkb.py
Normal file
71
bumblebee_status/modules/core/layout-xkb.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays the current keyboard layout using libX11
|
||||
|
||||
Requires the following library:
|
||||
* libX11.so.6
|
||||
and python module:
|
||||
* xkbgroup
|
||||
|
||||
Parameters:
|
||||
* layout-xkb.showname: Boolean that indicate whether the full name should be displayed. Defaults to false (only the symbol will be displayed)
|
||||
* layout-xkb.show_variant: Boolean that indecates whether the variant name should be displayed. Defaults to true.
|
||||
"""
|
||||
|
||||
from xkbgroup import *
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
import core.input
|
||||
|
||||
import util.format
|
||||
|
||||
|
||||
class Module(core.module.Module):
|
||||
def __init__(self, config, theme):
|
||||
super().__init__(config, theme, core.widget.Widget(self.current_layout))
|
||||
|
||||
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.__next_keymap)
|
||||
core.input.register(self, button=core.input.RIGHT_MOUSE, cmd=self.__prev_keymap)
|
||||
self.__show_variant = util.format.asbool(self.parameter("show_variant", True))
|
||||
|
||||
def __next_keymap(self, event):
|
||||
self.__set_keymap(1)
|
||||
|
||||
def __prev_keymap(self, event):
|
||||
self.__set_keymap(-1)
|
||||
|
||||
def __set_keymap(self, rotation):
|
||||
xkb = XKeyboard()
|
||||
if xkb.groups_count < 2:
|
||||
return # nothing to do
|
||||
layouts = xkb.groups_symbols
|
||||
idx = layouts.index(xkb.group_symbol)
|
||||
xkb.group_symbol = str(layouts[(idx + rotation) % len(layouts)])
|
||||
|
||||
def current_layout(self, widget):
|
||||
try:
|
||||
xkb = XKeyboard()
|
||||
log.debug("group num: {}".format(xkb.group_num))
|
||||
name = (
|
||||
xkb.group_name
|
||||
if util.format.asbool(self.parameter("showname"), False)
|
||||
else xkb.group_symbol
|
||||
)
|
||||
if self.__show_variant:
|
||||
return (
|
||||
"{} ({})".format(name, xkb.group_variant)
|
||||
if xkb.group_variant
|
||||
else name
|
||||
)
|
||||
return name
|
||||
except Exception as e:
|
||||
print("got exception: {}".format(e))
|
||||
return "n/a"
|
||||
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue