2020-05-03 11:15:52 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
2020-04-18 16:24:26 +02:00
|
|
|
|
|
|
|
"""Displays the indicator status, for numlock, scrolllock and capslock
|
|
|
|
|
2020-07-18 08:23:28 +02:00
|
|
|
Requires the following executable:
|
|
|
|
* xset
|
|
|
|
|
2020-04-18 16:24:26 +02:00
|
|
|
Parameters:
|
2020-04-18 16:34:27 +02:00
|
|
|
* indicator.include: Comma-separated list of interface prefixes to include (defaults to 'numlock,capslock')
|
|
|
|
* indicator.signalstype: If you want the signali type color to be 'critical' or 'warning' (defaults to 'warning')
|
2020-05-08 20:58:35 +02:00
|
|
|
|
|
|
|
contributed by `freed00m <https://github.com/freed00m>`_ - many thanks!
|
2020-04-18 16:24:26 +02:00
|
|
|
"""
|
|
|
|
|
2020-04-18 16:34:27 +02:00
|
|
|
import core.module
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-04-18 16:34:27 +02:00
|
|
|
import util.cli
|
|
|
|
import util.format
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-18 16:34:27 +02:00
|
|
|
class Module(core.module.Module):
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, [])
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
self.__include = tuple(
|
|
|
|
filter(
|
|
|
|
len, util.format.aslist(self.parameter("include", "NumLock,CapsLock"))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.__signalType = (
|
|
|
|
self.parameter("signaltype")
|
|
|
|
if not self.parameter("signaltype") is None
|
|
|
|
else "warning"
|
|
|
|
)
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-04-18 16:34:27 +02:00
|
|
|
def update(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
status_line = ""
|
|
|
|
for line in (
|
|
|
|
util.cli.execute("xset q", ignore_errors=True).replace(" ", "").split("\n")
|
|
|
|
):
|
|
|
|
if "capslock" in line.lower():
|
|
|
|
status_line = line
|
2020-04-18 16:24:26 +02:00
|
|
|
break
|
2020-04-18 16:34:27 +02:00
|
|
|
for indicator in self.__include:
|
2020-04-18 16:24:26 +02:00
|
|
|
widget = self.widget(indicator)
|
|
|
|
if not widget:
|
2020-05-09 10:57:44 +02:00
|
|
|
widget = self.add_widget(name=indicator, full_text=indicator)
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
widget.set(
|
|
|
|
"status",
|
|
|
|
True
|
|
|
|
if "{}:on".format(indicator.lower()) in status_line.lower()
|
|
|
|
else False,
|
|
|
|
)
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-04-18 16:34:27 +02:00
|
|
|
def state(self, widget):
|
|
|
|
states = []
|
2020-05-03 11:15:52 +02:00
|
|
|
if widget.get("status", False):
|
2020-04-18 16:34:27 +02:00
|
|
|
states.append(self.__signalType)
|
|
|
|
else:
|
2020-05-03 11:15:52 +02:00
|
|
|
states.append("normal")
|
2020-04-18 16:34:27 +02:00
|
|
|
return states
|
2020-04-18 16:24:26 +02:00
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-04-18 16:24:26 +02:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|