[modules/indicator] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-18 16:34:27 +02:00
parent 626ed97fcd
commit aa3d84f8ec

View file

@ -3,49 +3,44 @@
"""Displays the indicator status, for numlock, scrolllock and capslock """Displays the indicator status, for numlock, scrolllock and capslock
Parameters: Parameters:
* indicator.include: Comma-separated list of interface prefixes to include (defaults to "numlock,capslock") * 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") * indicator.signalstype: If you want the signali type color to be 'critical' or 'warning' (defaults to 'warning')
""" """
import core.module
import core.widget
import bumblebee.input import util.cli
import bumblebee.output import util.format
import bumblebee.engine
class Module(bumblebee.engine.Module): class Module(core.module.Module):
def __init__(self, engine, config): def __init__(self, config):
widgets = [] super().__init__(config, [])
self.status = False
super(Module,self).__init__(engine, config, widgets)
self._include = tuple(filter(len, self.parameter("include", "NumLock,CapsLock").split(",")))
self._signalType = self.parameter("signaltype") if not self.parameter("signaltype") is None else "warning"
def update(self, widgets): self.__include = tuple(filter(len, util.format.aslist(self.parameter('include', 'NumLock,CapsLock'))))
self._update_widgets(widgets) self.__signalType = self.parameter('signaltype') if not self.parameter('signaltype') is None else 'warning'
def update(self):
status_line = ''
for line in util.cli.execute('xset q', ignore_errors=True).replace(' ', '').split('\n'):
if 'capslock' in line.lower():
status_line = line
break
for indicator in self.__include:
widget = self.widget(indicator)
if not widget:
widget = core.widget.Widget(name=indicator, module=self)
self.widgets().append(widget)
widget.set('status', True if '{}:on'.format(indicator.lower()) in status_line.lower() else False)
widget.full_text(indicator)
def state(self, widget): def state(self, widget):
states = [] states = []
if widget.status: if widget.get('status', False):
states.append(self._signalType) states.append(self.__signalType)
elif not widget.status: else:
states.append("normal") states.append('normal')
return states return states
def _update_widgets(self, widgets):
status_line = ""
for line in bumblebee.util.execute("xset q").replace(" ", "").split("\n"):
if "capslock" in line.lower():
status_line = line
break
for indicator in self._include:
widget = self.widget(indicator)
if not widget:
widget = bumblebee.output.Widget(name=indicator)
widgets.append(widget)
widget.status = True if indicator.lower()+":on" in status_line.lower() else False
widget.full_text(indicator)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4