2020-04-13 13:27:15 +02:00
|
|
|
#pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Toggle twmn notifications."""
|
|
|
|
|
2020-04-13 13:30:35 +02:00
|
|
|
import core.module
|
|
|
|
import core.widget
|
|
|
|
import core.input
|
|
|
|
import core.decorators
|
2020-04-13 13:27:15 +02:00
|
|
|
|
2020-04-13 13:30:35 +02:00
|
|
|
import util.cli
|
2020-04-13 13:27:15 +02:00
|
|
|
|
2020-04-13 13:30:35 +02:00
|
|
|
class Module(core.module.Module):
|
|
|
|
@core.decorators.every(minutes=60)
|
2020-04-26 16:39:24 +02:00
|
|
|
def __init__(self, config, theme):
|
|
|
|
super().__init__(config, theme, core.widget.Widget(''))
|
2020-04-13 13:30:35 +02:00
|
|
|
|
|
|
|
self.__paused = False
|
2020-04-13 13:27:15 +02:00
|
|
|
# Make sure that twmn is currently not paused
|
2020-04-13 13:30:35 +02:00
|
|
|
util.cli.execute('killall -SIGUSR2 twmnd', ignore_errors=True)
|
|
|
|
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle_status)
|
2020-04-13 13:27:15 +02:00
|
|
|
|
|
|
|
def toggle_status(self, event):
|
2020-04-13 13:30:35 +02:00
|
|
|
self.__paused = not self.__paused
|
2020-04-13 13:27:15 +02:00
|
|
|
|
|
|
|
try:
|
2020-04-13 13:30:35 +02:00
|
|
|
if self.__paused:
|
|
|
|
util.cli.execute('systemctl --user start twmnd')
|
2020-04-13 13:27:15 +02:00
|
|
|
else:
|
2020-04-13 13:30:35 +02:00
|
|
|
util.cli.execute('systemctl --user stop twmnd')
|
2020-04-13 13:27:15 +02:00
|
|
|
except:
|
2020-04-13 13:30:35 +02:00
|
|
|
self.__paused = not self.__paused # toggling failed
|
2020-04-13 13:27:15 +02:00
|
|
|
|
|
|
|
def state(self, widget):
|
2020-04-13 13:30:35 +02:00
|
|
|
if self.__paused:
|
|
|
|
return ['muted']
|
|
|
|
return ['unmuted']
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|