From 9334d1c9b5aab54c9490333191c6ee73cab0ae0b Mon Sep 17 00:00:00 2001 From: Lars Vierbergen Date: Wed, 25 Jan 2017 01:54:55 +0100 Subject: [PATCH] Add togglecontrol that executes shell commands on enable/disable --- daemon.py | 53 ++++++++++++++++++++++++++++------------------- modules/toggle.py | 20 +++++++++++++++++- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/daemon.py b/daemon.py index 10e836c..8c20172 100755 --- a/daemon.py +++ b/daemon.py @@ -4,8 +4,11 @@ import modules import modules.core from modules.audiooutput import PulseCtlDefaultSinkCycleAction from modules.audiooutput import naming_map, sink_filter, sink_input_filter +from modules.cycle import * +from modules.toggle import CommandToggleControl -#logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.DEBUG) +logging.getLogger('modules.core').setLevel(logging.WARNING) modules.Application( modules.GroupedControl( @@ -13,28 +16,36 @@ modules.Application( modules.RedshiftControl(), separator='' ), - modules.ActionWrapperControl( - modules.VolumeControl(), - action='pavucontrol', - buttons=modules.core.Button.RIGHT - ), - CycleControl( - PulseCtlDefaultSinkCycleAction( - naming_map=naming_map.partial( - naming_map.foldr, [ - naming_map.description, - naming_map.partial( - naming_map.drop_kwargs, - naming_map.partial(naming_map.foldr, [ - naming_map.partial(naming_map.drop_first_if_eq, 'Built-in Audio '), - naming_map.first_char - ]) - ) - ] + modules.GroupedControl( + CycleControl( + PulseCtlDefaultSinkCycleAction( + naming_map=naming_map.partial( + naming_map.foldr, [ + naming_map.description, + naming_map.partial( + naming_map.drop_kwargs, + naming_map.partial(naming_map.foldr, [ + naming_map.partial(naming_map.drop_first_if_eq, 'Built-in Audio '), + naming_map.first_char + ]) + ) + ] + ), + sink_filter=sink_filter.hardware_only, + sink_input_filter=sink_input_filter.connected_sink ), - sink_filter=sink_filter.hardware_only, - sink_input_filter=sink_input_filter.connected_sink ), + modules.ActionWrapperControl( + CommandToggleControl('eq', ['pactl', 'load-module', 'module-equalizer-sink'], ['pactl', 'unload-module', 'module-equalizer-sink']), + action='qpaeq', + buttons=modules.core.Button.RIGHT + ), + modules.ActionWrapperControl( + modules.VolumeControl(), + action='pavucontrol', + buttons=modules.core.Button.RIGHT + ), + separator=' ' ) ).run() diff --git a/modules/toggle.py b/modules/toggle.py index b99874b..7b558c9 100644 --- a/modules/toggle.py +++ b/modules/toggle.py @@ -1,8 +1,12 @@ import abc +import subprocess + +from modules.util import process_reaper from .core import AbstractControl, action -__all__ = ['ToggleControl'] +__all__ = ['ToggleControl', 'CommandToggleControl'] + class ToggleControl(AbstractControl, metaclass=abc.ABCMeta): """ @@ -75,3 +79,17 @@ class ToggleControl(AbstractControl, metaclass=abc.ABCMeta): self.create_pipe_command(':toggle'), self.__letter.upper() if self.state else self.__letter.lower() ) + + +class CommandToggleControl(ToggleControl): + def __init__(self, letter: str, enable_command: list, disable_command: list, initial_state: bool = False): + super().__init__(letter, initial_state) + self.__enable_command = enable_command + self.__disable_command = disable_command + + def enable(self): + subprocess.call(self.__enable_command) + + def disable(self): + subprocess.call(self.__disable_command) +