From c248808c7b251af5bb6154bc0a0d2585f6d8ba10 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 16 Sep 2023 23:13:56 +0100 Subject: [PATCH] LabelSlider compound element added labels for sliders added. all sliders now focusable. todo: add events/binds for sliders --- src/nvda_voicemeeter/builder.py | 74 +++++++++++--------------------- src/nvda_voicemeeter/compound.py | 35 +++++++++++++++ src/nvda_voicemeeter/window.py | 8 ++++ 3 files changed, 69 insertions(+), 48 deletions(-) create mode 100644 src/nvda_voicemeeter/compound.py diff --git a/src/nvda_voicemeeter/builder.py b/src/nvda_voicemeeter/builder.py index 5ea434a..b1fc5b4 100644 --- a/src/nvda_voicemeeter/builder.py +++ b/src/nvda_voicemeeter/builder.py @@ -1,6 +1,7 @@ import PySimpleGUI as psg from . import util +from .compound import LabelSlider class Builder: @@ -307,6 +308,7 @@ class Builder: def add_gain_slider(layout): layout.append( [ + psg.Text("Gain"), psg.Slider( range=(-60, 12), default_value=self.vm.strip[i].gain, @@ -316,37 +318,17 @@ class Builder: enable_events=True, orientation="horizontal", key=f"STRIP {i}||SLIDER GAIN", - ) + ), ] ) def add_param_sliders(layout): - def default_value(i, param): - target = getattr(self.vm.strip[i], param.lower()) - if param in ("COMP", "GATE", "DENOISER"): - return target.knob - return target - - layout.append( - [ - psg.Slider( - range=(0, 10), - default_value=default_value(i, param), - resolution=0.1, - disable_number_display=True, - size=(12, 10), - expand_x=True, - enable_events=True, - orientation="horizontal", - key=f"STRIP {i}||SLIDER {param}", - ) - for param in util.get_slider_params(i, self.vm) - ] - ) + layout.append([LabelSlider(self.window, i, param) for param in util.get_slider_params(i, self.vm)]) def add_limit_slider(layout): layout.append( [ + psg.Text("Limit"), psg.Slider( range=(-40, 12), default_value=self.vm.strip[i].limit, @@ -356,7 +338,7 @@ class Builder: enable_events=True, orientation="horizontal", key=f"STRIP {i}||SLIDER LIMIT", - ) + ), ] ) @@ -418,6 +400,7 @@ class Builder: def add_gain_slider(layout): layout.append( [ + psg.Text("Gain"), psg.Slider( range=(-60, 12), default_value=self.vm.strip[i].gain, @@ -427,34 +410,26 @@ class Builder: enable_events=True, orientation="horizontal", key=f"STRIP {i}||SLIDER GAIN", - ) + ), ] ) def add_param_sliders(layout): - def default_value(i, param): - return getattr(self.vm.strip[i], param.lower()) - - layout.append( - [ - psg.Slider( - range=(0, 10), - default_value=default_value(i, param), - resolution=0.1, - disable_number_display=True, - size=(12, 10), - expand_x=True, - enable_events=True, - orientation="horizontal", - key=f"STRIP {i}||SLIDER {param}", - ) - for param in util.get_slider_params(i, self.vm) - ] - ) + if self.kind.name in ("basic", "banana"): + for param in util.get_slider_params(i, self.vm): + layout.append([LabelSlider(self.window, i, param, range_=(-12, 12))]) + else: + layout.append( + [ + LabelSlider(self.window, i, param, range_=(-12, 12)) + for param in util.get_slider_params(i, self.vm) + ] + ) def add_limit_slider(layout): layout.append( [ + psg.Text("Limit"), psg.Slider( range=(-40, 12), default_value=self.vm.strip[i].limit, @@ -464,13 +439,16 @@ class Builder: enable_events=True, orientation="horizontal", key=f"STRIP {i}||SLIDER LIMIT", - ) + ), ] ) - outputs = [] - [step(outputs) for step in (add_gain_slider, add_param_sliders, add_limit_slider)] - return psg.Frame(self.window.cache["labels"][f"STRIP {i}||LABEL"], outputs, key=f"STRIP {i}||LABEL||SLIDER") + layout = [] + steps = (add_gain_slider, add_param_sliders) + if self.kind.name in ("banana", "potato"): + steps += (add_limit_slider,) + [step(layout) for step in steps] + return psg.Frame(self.window.cache["labels"][f"STRIP {i}||LABEL"], layout, key=f"STRIP {i}||LABEL||SLIDER") def make_tab2_slider_rows(self) -> psg.Frame: layout = [ diff --git a/src/nvda_voicemeeter/compound.py b/src/nvda_voicemeeter/compound.py new file mode 100644 index 0000000..4110c48 --- /dev/null +++ b/src/nvda_voicemeeter/compound.py @@ -0,0 +1,35 @@ +import PySimpleGUI as psg + + +class LabelSlider(psg.Frame): + """Compound Label Slider element""" + + def __init__(self, parent, i, param, range_=(0, 10), *args, **kwargs): + self.parent = parent + if param in ("AUDIBILITY", "DENOISER"): + size = 7 + else: + size = 4 + layout = [ + [ + psg.Text(param.capitalize(), size=size), + psg.Slider( + range=range_, + default_value=self.default_value(i, param), + resolution=0.1, + disable_number_display=True, + size=(12, 16), + expand_x=True, + enable_events=True, + orientation="horizontal", + key=f"STRIP {i}||SLIDER {param}", + ), + ] + ] + super().__init__(None, layout=layout, border_width=0, pad=0, *args, **kwargs) + + def default_value(self, i, param): + target = getattr(self.parent.vm.strip[i], param.lower()) + if param in ("COMP", "GATE", "DENOISER"): + return target.knob + return target diff --git a/src/nvda_voicemeeter/window.py b/src/nvda_voicemeeter/window.py index f21825c..9170958 100644 --- a/src/nvda_voicemeeter/window.py +++ b/src/nvda_voicemeeter/window.py @@ -48,7 +48,15 @@ class NVDAVMWindow(psg.Window): [self[f"PATCH COMPOSITE||PC{i + 1}"].Widget.config(**buttonmenu_opts) for i in range(self.kind.phys_out)] slider_opts = {"takefocus": 1, "highlightthickness": 1} for i in range(self.kind.num_strip): + if i < self.kind.phys_in: + for param in util.get_slider_params(i, self.vm): + self[f"STRIP {i}||SLIDER {param}"].Widget.config(**slider_opts) + else: + for param in ("BASS", "MID", "TREBLE"): + self[f"STRIP {i}||SLIDER {param}"].Widget.config(**slider_opts) self[f"STRIP {i}||SLIDER GAIN"].Widget.config(**slider_opts) + if self.kind.name != "basic": + self[f"STRIP {i}||SLIDER LIMIT"].Widget.config(**slider_opts) for i in range(self.kind.num_bus): self[f"BUS {i}||SLIDER GAIN"].Widget.config(**slider_opts)