LabelSlider compound element added

labels for sliders added.

all sliders now focusable.

todo: add events/binds for sliders
This commit is contained in:
onyx-and-iris 2023-09-16 23:13:56 +01:00
parent d93f078365
commit c248808c7b
3 changed files with 69 additions and 48 deletions

View File

@ -1,6 +1,7 @@
import PySimpleGUI as psg import PySimpleGUI as psg
from . import util from . import util
from .compound import LabelSlider
class Builder: class Builder:
@ -307,6 +308,7 @@ class Builder:
def add_gain_slider(layout): def add_gain_slider(layout):
layout.append( layout.append(
[ [
psg.Text("Gain"),
psg.Slider( psg.Slider(
range=(-60, 12), range=(-60, 12),
default_value=self.vm.strip[i].gain, default_value=self.vm.strip[i].gain,
@ -316,37 +318,17 @@ class Builder:
enable_events=True, enable_events=True,
orientation="horizontal", orientation="horizontal",
key=f"STRIP {i}||SLIDER GAIN", key=f"STRIP {i}||SLIDER GAIN",
) ),
] ]
) )
def add_param_sliders(layout): def add_param_sliders(layout):
def default_value(i, param): layout.append([LabelSlider(self.window, i, param) for param in util.get_slider_params(i, self.vm)])
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)
]
)
def add_limit_slider(layout): def add_limit_slider(layout):
layout.append( layout.append(
[ [
psg.Text("Limit"),
psg.Slider( psg.Slider(
range=(-40, 12), range=(-40, 12),
default_value=self.vm.strip[i].limit, default_value=self.vm.strip[i].limit,
@ -356,7 +338,7 @@ class Builder:
enable_events=True, enable_events=True,
orientation="horizontal", orientation="horizontal",
key=f"STRIP {i}||SLIDER LIMIT", key=f"STRIP {i}||SLIDER LIMIT",
) ),
] ]
) )
@ -418,6 +400,7 @@ class Builder:
def add_gain_slider(layout): def add_gain_slider(layout):
layout.append( layout.append(
[ [
psg.Text("Gain"),
psg.Slider( psg.Slider(
range=(-60, 12), range=(-60, 12),
default_value=self.vm.strip[i].gain, default_value=self.vm.strip[i].gain,
@ -427,34 +410,26 @@ class Builder:
enable_events=True, enable_events=True,
orientation="horizontal", orientation="horizontal",
key=f"STRIP {i}||SLIDER GAIN", key=f"STRIP {i}||SLIDER GAIN",
) ),
] ]
) )
def add_param_sliders(layout): def add_param_sliders(layout):
def default_value(i, param): if self.kind.name in ("basic", "banana"):
return getattr(self.vm.strip[i], param.lower()) for param in util.get_slider_params(i, self.vm):
layout.append([LabelSlider(self.window, i, param, range_=(-12, 12))])
layout.append( else:
[ layout.append(
psg.Slider( [
range=(0, 10), LabelSlider(self.window, i, param, range_=(-12, 12))
default_value=default_value(i, param), for param in util.get_slider_params(i, self.vm)
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)
]
)
def add_limit_slider(layout): def add_limit_slider(layout):
layout.append( layout.append(
[ [
psg.Text("Limit"),
psg.Slider( psg.Slider(
range=(-40, 12), range=(-40, 12),
default_value=self.vm.strip[i].limit, default_value=self.vm.strip[i].limit,
@ -464,13 +439,16 @@ class Builder:
enable_events=True, enable_events=True,
orientation="horizontal", orientation="horizontal",
key=f"STRIP {i}||SLIDER LIMIT", key=f"STRIP {i}||SLIDER LIMIT",
) ),
] ]
) )
outputs = [] layout = []
[step(outputs) for step in (add_gain_slider, add_param_sliders, add_limit_slider)] steps = (add_gain_slider, add_param_sliders)
return psg.Frame(self.window.cache["labels"][f"STRIP {i}||LABEL"], outputs, key=f"STRIP {i}||LABEL||SLIDER") 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: def make_tab2_slider_rows(self) -> psg.Frame:
layout = [ layout = [

View File

@ -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

View File

@ -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)] [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} slider_opts = {"takefocus": 1, "highlightthickness": 1}
for i in range(self.kind.num_strip): 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) 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): for i in range(self.kind.num_bus):
self[f"BUS {i}||SLIDER GAIN"].Widget.config(**slider_opts) self[f"BUS {i}||SLIDER GAIN"].Widget.config(**slider_opts)