bumblebee-status/bumblebee/modules/caffeine.py

45 lines
1.2 KiB
Python
Raw Normal View History

2019-08-25 20:53:42 +02:00
#pylint: disable=C0111,R0903
"""Enable/disable automatic screen locking.
Requires the following executables:
2019-08-25 20:53:42 +02:00
* xdg-screensaver
* notify-send
"""
import bumblebee.input
import bumblebee.output
import bumblebee.engine
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config,
2019-08-25 20:53:42 +02:00
bumblebee.output.Widget(full_text="")
)
2019-08-25 20:53:42 +02:00
self._active = False
self.interval(1)
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=self._toggle
)
def state(self, widget):
2019-08-25 20:53:42 +02:00
if self._active:
return "activated"
return "deactivated"
2019-08-25 20:53:42 +02:00
def _toggle(self, event):
self._active = not self._active
if self._active:
bumblebee.util.execute("xdg-screensaver reset")
bumblebee.util.execute("notify-send \"Consuming caffeine\"")
2019-08-25 20:53:42 +02:00
else:
bumblebee.util.execute("notify-send \"Out of coffee\"")
def update(self, widgets):
if self._active:
bumblebee.util.execute("xdg-screensaver reset")
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4