From cd3aaa9e9fb1cd661e76638f7cb78e47a88e8cde Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 10 Aug 2018 23:55:30 +0200 Subject: Stuff --- TODO.txt | 3 +++ inter.py | 23 ++++++++++++++++------- main.py | 31 +++++++++++++++++-------------- pacmd.py | 2 +- 4 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 TODO.txt diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..c8173e5 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,3 @@ +- Interface showing sinks, sink-inputs, and their connections + - Should show volume (+mutedness) and state (i.e. whether it's playing anything) + - User can change volume and connections diff --git a/inter.py b/inter.py index 109950d..4a4cd5b 100644 --- a/inter.py +++ b/inter.py @@ -1,8 +1,17 @@ from collections import namedtuple import pacmd -Sink = namedtuple("Sink", ["name", "description", "index", "state", "muted"]) -SinkInput = namedtuple("SinkInput", ["name", "driver", "sink"]) +Sink = namedtuple("Sink", + ["name", # string + "description", # string + "index", # int + "state", # string + "muted", # bool + "volume"]) # string +SinkInput = namedtuple("SinkInput", + ["name", # string + "driver", # string + "sink"]) # int def list_sinks(): res = pacmd.list_sinks() @@ -12,17 +21,17 @@ def list_sinks(): ret = [] for item in res.sections[0].items: muted = item.children["muted"].value - if type(muted) == str: - if muted == "yes": muted = True - elif muted == "no": muted = False - else: assert False + if muted == "yes": muted = True + elif muted == "no": muted = False + else: assert False sink = Sink( item.children["name"].value, item.children["properties"].children["device.description"].value, item.index, item.children["state"].value, - muted) + muted, + item.children["volume"].value) ret.append(sink) return ret diff --git a/main.py b/main.py index 92da31d..8be5f9c 100755 --- a/main.py +++ b/main.py @@ -2,20 +2,23 @@ import pacmd, inter -# res = pacmd.list_sink_inputs() -# print("Infos:") -# for info in res.infos: -# print(info) -# print("Sections:") -# for sect in res.sections: -# pacmd.dump_section(sect) -res = inter.list_sinks() -for sink in res: - print(sink) +def low_query(func): + res = func() + print("Infos:") + for info in res.infos: + print(info) + print("Sections:") + for sect in res.sections: + pacmd.dump_section(sect) + +def high_query(func): + res = func() + for x in res: + print(x) -print() -res = inter.list_sink_inputs() -for si in res: - print(si) +# low_query(pacmd.list_sinks) +high_query(inter.list_sinks) +print() +high_query(inter.list_sink_inputs) diff --git a/pacmd.py b/pacmd.py index e9e019e..42d3ce8 100644 --- a/pacmd.py +++ b/pacmd.py @@ -1,6 +1,6 @@ import subprocess, re -from collections import namedtuple +# These are not namedtuples because we want them mutable class PacmdSection: def __init__(self, name, items): self.name = name # string -- cgit v1.2.3