[modules] Re-enable preconfigured on-click actions
This commit is contained in:
parent
c821deec1c
commit
26f5fd3064
7 changed files with 51 additions and 41 deletions
|
@ -48,7 +48,7 @@ class Module(object):
|
|||
def state(self, widget):
|
||||
return "default"
|
||||
|
||||
def instance(self, widget):
|
||||
return self._alias if self._alias else self.__module__.split(".")[-1]
|
||||
def instance(self, widget=None):
|
||||
return self.__module__.split(".")[-1]
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -15,9 +15,7 @@ class Module(bumblebee.module.Module):
|
|||
super(Module, self).__init__(output, config, alias)
|
||||
self._perc = psutil.cpu_percent(percpu=False)
|
||||
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
# cmd="gnome-system-monitor")
|
||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||
|
||||
def widgets(self):
|
||||
self._perc = psutil.cpu_percent(percpu=False)
|
||||
|
|
|
@ -16,9 +16,7 @@ class Module(bumblebee.module.Module):
|
|||
super(Module, self).__init__(output, config, alias)
|
||||
self._path = self._config.parameter("path", "/")
|
||||
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
# cmd="nautilus {instance}")
|
||||
output.add_callback(module=self.instance(), button=1, cmd="nautilus {instance}")
|
||||
|
||||
def widgets(self):
|
||||
st = os.statvfs(self._path)
|
||||
|
@ -33,6 +31,9 @@ class Module(bumblebee.module.Module):
|
|||
bumblebee.util.bytefmt(self._size), self._perc)
|
||||
)
|
||||
|
||||
def instance(self, widget=None):
|
||||
return self._path
|
||||
|
||||
def warning(self, widget):
|
||||
return self._perc > self._config.parameter("warning", 80)
|
||||
|
||||
|
|
|
@ -16,9 +16,7 @@ class Module(bumblebee.module.Module):
|
|||
super(Module, self).__init__(output, config, alias)
|
||||
self._mem = psutil.virtual_memory()
|
||||
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
# cmd="gnome-system-monitor")
|
||||
output.add_callback(module=self.instance(), button=1, cmd="gnome-system-monitor")
|
||||
|
||||
def widgets(self):
|
||||
self._mem = psutil.virtual_memory()
|
||||
|
|
|
@ -36,15 +36,14 @@ class Module(bumblebee.module.Module):
|
|||
self._mute = False
|
||||
channel = "sink" if self._module == "pasink" else "source"
|
||||
|
||||
# TODO
|
||||
# output.add_callback(module=self.__module__, button=3,
|
||||
# cmd="pavucontrol")
|
||||
# output.add_callback(module=self.__module__, button=1,
|
||||
# cmd="pactl set-{}-mute @DEFAULT_{}@ toggle".format(channel, channel.upper()))
|
||||
# output.add_callback(module=self.__module__, button=4,
|
||||
# cmd="pactl set-{}-volume @DEFAULT_{}@ +2%".format(channel, channel.upper()))
|
||||
# output.add_callback(module=self.__module__, button=5,
|
||||
# cmd="pactl set-{}-volume @DEFAULT_{}@ -2%".format(channel, channel.upper()))
|
||||
output.add_callback(module=self.instance(), button=3,
|
||||
cmd="pavucontrol")
|
||||
output.add_callback(module=self.instance(), button=1,
|
||||
cmd="pactl set-{}-mute @DEFAULT_{}@ toggle".format(channel, channel.upper()))
|
||||
output.add_callback(module=self.instance(), button=4,
|
||||
cmd="pactl set-{}-volume @DEFAULT_{}@ +2%".format(channel, channel.upper()))
|
||||
output.add_callback(module=self.instance(), button=5,
|
||||
cmd="pactl set-{}-volume @DEFAULT_{}@ -2%".format(channel, channel.upper()))
|
||||
|
||||
def widgets(self):
|
||||
res = subprocess.check_output(shlex.split("pactl info"))
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import os
|
||||
import shlex
|
||||
import inspect
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
def output(args):
|
||||
import bumblebee.outputs.i3
|
||||
|
@ -28,15 +32,21 @@ class Widget(object):
|
|||
def module(self):
|
||||
return self._obj.__module__.split(".")[-1]
|
||||
|
||||
def name(self):
|
||||
return self._obj.__module__
|
||||
|
||||
def instance(self):
|
||||
rv = getattr(self._obj, "instance")(self)
|
||||
return getattr(self._obj, "instance")(self)
|
||||
|
||||
def text(self):
|
||||
return self._text
|
||||
|
||||
class Command(object):
|
||||
def __init__(self, command):
|
||||
self._command = command
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
cmd = self._command.format(*args, **kwargs)
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
subprocess.Popen(shlex.split(cmd), stdout=DEVNULL, stderr=DEVNULL)
|
||||
|
||||
class Output(object):
|
||||
def __init__(self, config):
|
||||
self._config = config
|
||||
|
@ -52,22 +62,28 @@ class Output(object):
|
|||
def add_callback(self, cmd, button, module=None):
|
||||
if module:
|
||||
module = module.replace("bumblebee.modules.", "")
|
||||
|
||||
self._callbacks[(
|
||||
button,
|
||||
module,
|
||||
)] = cmd
|
||||
|
||||
def callback(self, event):
|
||||
cb = self._callbacks.get((
|
||||
event.get("button", -1),
|
||||
event.get("name", None),
|
||||
), None)
|
||||
if cb is not None: return cb
|
||||
cb = self._callbacks.get((
|
||||
event.get("button", -1),
|
||||
None,
|
||||
), None)
|
||||
return cb
|
||||
cb = self._callbacks.get((
|
||||
event.get("button", -1),
|
||||
event.get("name", None),
|
||||
), cb)
|
||||
cb = self._callbacks.get((
|
||||
event.get("button", -1),
|
||||
event.get("instance", None),
|
||||
), cb)
|
||||
if inspect.isfunction(cb) or cb is None: return cb
|
||||
|
||||
return Command(cb)
|
||||
|
||||
def wait(self):
|
||||
self._wait.wait(self._config.parameter("interval", 1))
|
||||
|
|
|
@ -19,12 +19,11 @@ def read_input(output):
|
|||
event = json.loads(line)
|
||||
cb = output.callback(event)
|
||||
if cb:
|
||||
cb = cb.format(
|
||||
cb(
|
||||
name=event.get("name", ""),
|
||||
instance=event.get("instance", ""),
|
||||
button=event.get("button", -1)
|
||||
)
|
||||
subprocess.Popen(shlex.split(cb), stdout=DEVNULL, stderr=DEVNULL)
|
||||
output.redraw()
|
||||
|
||||
class Output(bumblebee.output.Output):
|
||||
|
@ -32,12 +31,11 @@ class Output(bumblebee.output.Output):
|
|||
super(Output, self).__init__(args)
|
||||
self._data = []
|
||||
|
||||
# TODO
|
||||
# self.add_callback("i3-msg workspace prev_on_output", 4)
|
||||
# self.add_callback("i3-msg workspace next_on_output", 5)
|
||||
self.add_callback("i3-msg workspace prev_on_output", 4)
|
||||
self.add_callback("i3-msg workspace next_on_output", 5)
|
||||
|
||||
# self._thread = threading.Thread(target=read_input, args=(self,))
|
||||
# self._thread.start()
|
||||
self._thread = threading.Thread(target=read_input, args=(self,))
|
||||
self._thread.start()
|
||||
|
||||
def start(self):
|
||||
print json.dumps({ "version": 1, "click_events": True }) + "["
|
||||
|
@ -61,7 +59,7 @@ class Output(bumblebee.output.Output):
|
|||
),
|
||||
"color": theme.color(widget),
|
||||
"background": theme.background(widget),
|
||||
"name": widget.name(),
|
||||
"name": widget.module(),
|
||||
"instance": widget.instance(),
|
||||
"separator": theme.default_separators(widget),
|
||||
"separator_block_width": theme.separator_block_width(widget),
|
||||
|
|
Loading…
Reference in a new issue