commit
522d691663
@ -94,25 +94,28 @@ class Module(SettingsBase):
|
|||||||
else:
|
else:
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
our_method = is_method_of(cb, self)
|
try:
|
||||||
if callable(cb) and not our_method:
|
our_method = is_method_of(cb, self)
|
||||||
self.__log_button_event(button, cb, args, "Python callback")
|
if callable(cb) and not our_method:
|
||||||
cb(*args)
|
self.__log_button_event(button, cb, args, "Python callback")
|
||||||
elif our_method:
|
cb(*args)
|
||||||
cb(self, *args)
|
elif our_method:
|
||||||
elif hasattr(self, cb):
|
cb(self, *args)
|
||||||
if cb is not "run":
|
elif hasattr(self, cb):
|
||||||
# CommandEndpoint already calls run() after every
|
if cb is not "run":
|
||||||
# callback to instantly update any changed state due
|
# CommandEndpoint already calls run() after every
|
||||||
# to the callback's actions.
|
# callback to instantly update any changed state due
|
||||||
self.__log_button_event(button, cb, args, "Member callback")
|
# to the callback's actions.
|
||||||
getattr(self, cb)(*args)
|
self.__log_button_event(button, cb, args, "Member callback")
|
||||||
else:
|
getattr(self, cb)(*args)
|
||||||
self.__log_button_event(button, cb, args, "External command")
|
else:
|
||||||
if hasattr(self, "data"):
|
self.__log_button_event(button, cb, args, "External command")
|
||||||
args = [arg.format(**self.data) for arg in args]
|
if hasattr(self, "data"):
|
||||||
cb = cb.format(**self.data)
|
args = [arg.format(**self.data) for arg in args]
|
||||||
execute(cb + " " + " ".join(args), detach=True)
|
cb = cb.format(**self.data)
|
||||||
|
execute(cb + " " + " ".join(args), detach=True)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.critical("Exception while processing button callback: {!r}".format(e))
|
||||||
|
|
||||||
# Notify status handler
|
# Notify status handler
|
||||||
try:
|
try:
|
||||||
|
@ -4,8 +4,8 @@ from i3pystatus.core.color import ColorRangeModule
|
|||||||
from i3pystatus.core.util import make_vertical_bar, make_bar
|
from i3pystatus.core.util import make_vertical_bar, make_bar
|
||||||
from .pulse import *
|
from .pulse import *
|
||||||
|
|
||||||
|
from i3pystatus.core.command import execute
|
||||||
from i3pystatus import Module
|
from i3pystatus import Module
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
class PulseAudio(Module, ColorRangeModule):
|
class PulseAudio(Module, ColorRangeModule):
|
||||||
@ -80,7 +80,7 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
self.colors = self.get_hex_color_range(self.color_muted, self.color_unmuted, 100)
|
self.colors = self.get_hex_color_range(self.color_muted, self.color_unmuted, 100)
|
||||||
|
|
||||||
# Check that we have amixer for toggling mute/unmute and incrementing/decrementing volume
|
# Check that we have amixer for toggling mute/unmute and incrementing/decrementing volume
|
||||||
self.has_amixer = shutil.which('alsamixer') is not None
|
self.has_amixer = shutil.which('amixer') is not None
|
||||||
|
|
||||||
def request_update(self, context):
|
def request_update(self, context):
|
||||||
"""Requests a sink info update (sink_info_cb is called)"""
|
"""Requests a sink info update (sink_info_cb is called)"""
|
||||||
@ -172,14 +172,14 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
command += 'unmute'
|
command += 'unmute'
|
||||||
else:
|
else:
|
||||||
command += 'mute'
|
command += 'mute'
|
||||||
subprocess.run(command.split())
|
execute(command)
|
||||||
|
|
||||||
def increase_volume(self):
|
def increase_volume(self):
|
||||||
if self.has_amixer:
|
if self.has_amixer:
|
||||||
command = "amixer -q -D pulse sset Master %s%%+" % self.step
|
command = "amixer -q -D pulse sset Master %s%%+" % self.step
|
||||||
subprocess.run(command.split())
|
execute(command)
|
||||||
|
|
||||||
def decrease_volume(self):
|
def decrease_volume(self):
|
||||||
if self.has_amixer:
|
if self.has_amixer:
|
||||||
command = "amixer -q -D pulse sset Master %s%%-" % self.step
|
command = "amixer -q -D pulse sset Master %s%%-" % self.step
|
||||||
subprocess.run(command.split())
|
execute(command)
|
||||||
|
Loading…
Reference in New Issue
Block a user