Format code

master
Lars Vierbergen 8 years ago
parent 3591ba114d
commit be2bcef6fa
  1. 1
      modules/toggle.py
  2. 18
      modules/volume.py

@ -15,6 +15,7 @@ class ToggleControl(AbstractControl, metaclass=abc.ABCMeta):
The toggle button will show a text in upper or lower case, depending on the activation state of the button. The toggle button will show a text in upper or lower case, depending on the activation state of the button.
A click on the button toggles the button by calling toggle() A click on the button toggles the button by calling toggle()
""" """
def __init__(self, letter: str, initial_state: bool = False): def __init__(self, letter: str, initial_state: bool = False):
""" """
:param letter: The text to show on the toggle control. Will be upper- or lowercased when the button is activated or deactivated. :param letter: The text to show on the toggle control. Will be upper- or lowercased when the button is activated or deactivated.

@ -44,10 +44,10 @@ class AbstractVolumeControl(AbstractControl, metaclass=abc.ABCMeta):
volume = 1.0 volume = 1.0
if self.muted: if self.muted:
self.muted = False self.muted = False
if int(self._volume) != int(volume*90000): if int(self._volume) != int(volume * 90000):
logger.info("Setting volume to %s", volume) logger.info("Setting volume to %s", volume)
if self._set_volume(volume): if self._set_volume(volume):
self._volume = int(volume*90000) self._volume = int(volume * 90000)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -56,7 +56,7 @@ class AbstractVolumeControl(AbstractControl, metaclass=abc.ABCMeta):
def respond_to(self, command): def respond_to(self, command):
if command[0] == '=': if command[0] == '=':
self.volume = int(command[1:])/10.0 self.volume = int(command[1:]) / 10.0
elif command == 'm1': elif command == 'm1':
self.muted = True self.muted = True
elif command == 'm0': elif command == 'm0':
@ -64,11 +64,11 @@ class AbstractVolumeControl(AbstractControl, metaclass=abc.ABCMeta):
elif command == 'mt': elif command == 'mt':
self.muted = not self.muted self.muted = not self.muted
elif command == '+': elif command == '+':
self.volume += 1/30.0 self.volume += 1 / 30.0
elif command == '-': elif command == '-':
self.volume -= 1/30.0 self.volume -= 1 / 30.0
elif command == 'r': elif command == 'r':
self.volume = 1/3.0 self.volume = 1 / 3.0
else: else:
return False return False
return True return True
@ -117,7 +117,7 @@ def partial_bar(bar_size):
class PaCtlVolumeControl(AbstractVolumeControl): class PaCtlVolumeControl(AbstractVolumeControl):
def _set_volume(self, volume: float) -> bool: def _set_volume(self, volume: float) -> bool:
try: try:
self._pactl('set-sink-volume', str(int(volume*90000))) self._pactl('set-sink-volume', str(int(volume * 90000)))
return True return True
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
logger.exception("Error setting volume") logger.exception("Error setting volume")
@ -140,6 +140,7 @@ class PaCtlVolumeControl(AbstractVolumeControl):
try: try:
import pulsectl import pulsectl
class PulseCtlVolumeControl(AbstractVolumeControl): class PulseCtlVolumeControl(AbstractVolumeControl):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -149,7 +150,8 @@ try:
def periodic(self): def periodic(self):
server_info = self.__pulse.server_info() server_info = self.__pulse.server_info()
self.__default_sink = next(filter(lambda sink: sink.name == server_info.default_sink_name, self.__pulse.sink_list())) self.__default_sink = next(
filter(lambda sink: sink.name == server_info.default_sink_name, self.__pulse.sink_list()))
prev_muted = self.muted prev_muted = self.muted
self.muted = bool(self.__default_sink.mute) self.muted = bool(self.__default_sink.mute)
prev_volume = self.volume prev_volume = self.volume

Loading…
Cancel
Save