[modules/pulsectl] add default device selection
re-enable functionality to add a popup that allows the user to select the default source/sink. fixes #965
This commit is contained in:
parent
e9696b2150
commit
14f19c897a
2 changed files with 29 additions and 4 deletions
|
@ -68,10 +68,13 @@ def handle_commands(config, update_lock):
|
||||||
|
|
||||||
def handle_events(config, update_lock):
|
def handle_events(config, update_lock):
|
||||||
while True:
|
while True:
|
||||||
line = sys.stdin.readline().strip(",").strip()
|
try:
|
||||||
if line == "[": continue
|
line = sys.stdin.readline().strip(",").strip()
|
||||||
logging.info("input event: {}".format(line))
|
if line == "[": continue
|
||||||
process_event(line, config, update_lock)
|
logging.info("input event: {}".format(line))
|
||||||
|
process_event(line, config, update_lock)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -35,6 +35,8 @@ Requires the following Python module:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pulsectl
|
import pulsectl
|
||||||
|
import logging
|
||||||
|
import functools
|
||||||
|
|
||||||
import core.module
|
import core.module
|
||||||
import core.widget
|
import core.widget
|
||||||
|
@ -45,6 +47,11 @@ import util.cli
|
||||||
import util.graph
|
import util.graph
|
||||||
import util.format
|
import util.format
|
||||||
|
|
||||||
|
try:
|
||||||
|
import util.popup
|
||||||
|
except ImportError as e:
|
||||||
|
logging.warning("Couldn't import util.popup: %s. Popups won't work!", e)
|
||||||
|
|
||||||
class Module(core.module.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, config, theme, type):
|
def __init__(self, config, theme, type):
|
||||||
super().__init__(config, theme, core.widget.Widget(self.display))
|
super().__init__(config, theme, core.widget.Widget(self.display))
|
||||||
|
@ -161,6 +168,21 @@ class Module(core.module.Module):
|
||||||
pulse.event_callback_set(self.process)
|
pulse.event_callback_set(self.process)
|
||||||
pulse.event_listen()
|
pulse.event_listen()
|
||||||
|
|
||||||
|
def select_default_device_popup(self, widget):
|
||||||
|
with pulsectl.Pulse(self.id) as pulse:
|
||||||
|
devs = pulse.sink_list() if self.__type == "sink" else pulse.source_list()
|
||||||
|
menu = util.popup.menu()
|
||||||
|
for dev in devs:
|
||||||
|
menu.add_menuitem(
|
||||||
|
dev.description,
|
||||||
|
callback=functools.partial(self.__on_default_changed, dev),
|
||||||
|
)
|
||||||
|
menu.show(widget)
|
||||||
|
|
||||||
|
def __on_default_changed(self, dev):
|
||||||
|
with pulsectl.Pulse(self.id) as pulse:
|
||||||
|
pulse.default_set(dev)
|
||||||
|
|
||||||
def state(self, _):
|
def state(self, _):
|
||||||
if self.__muted:
|
if self.__muted:
|
||||||
return ["warning", "muted"]
|
return ["warning", "muted"]
|
||||||
|
|
Loading…
Reference in a new issue