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