Source code for jdxi_editor.ui.windows.jdxi.helpers.button_row
from typing import Union, Callable, Any
from PySide6.QtWidgets import QLabel, QPushButton
from jdxi_editor.core.jdxi import JDXi
from jdxi_editor.ui.style.editor_style import (
panel_heading_background_ink,
panel_ink,
)
from jdxi_editor.ui.widgets.label_click import make_label_clickable
from picoui.helpers.layout import create_layout_with_items
from picoui.specs.widgets import ButtonSpec
from picoui.widget.helper import create_button_from_spec
# Fallback tooltips when not using ButtonSpec
[docs]
_TOOLTIP_MAP = {
"Digital Synth 1": "Digital Synth 1: Open the Digital Synth 1 editor",
"Digital Synth 2": "Digital Synth 2: Open the Digital Synth 2 editor",
"Drums": "Drums: Open the Drums editor",
"Analog Synth": "Analog Synth: Open the Analog Synth editor",
"Arpeggiator": "Arpeggiator: Open the Arpeggiator editor",
"Vocoder": "Vocoder: Open the Vocal Effects editor",
"Effects": "Effects: Open the Effects editor",
}
[docs]
def create_button_row(
text_or_spec: Union[str, ButtonSpec],
slot=None,
vertical=False,
spacing=10,
heading=False,
):
"""Create address row with label and circular button.
Accepts either (text, slot) for backward compatibility or a ButtonSpec.
When a ButtonSpec is passed, slot is ignored; use spec.slot.
`heading` marks a row that names a section of the panel rather than one
of the synth's parts. Where a skin letters its headings on bars, such a
row takes the second one: on the Juno the blue bar, which on the machine
carries the part of the panel that is not the synth's parameters.
"""
if isinstance(text_or_spec, ButtonSpec):
spec = text_or_spec
text = spec.label or ""
slot = spec.slot
tooltip = spec.tooltip or _TOOLTIP_MAP.get(text, f"{text}: Click to open")
else:
raise TypeError(f"Should be a ButtonSpec, but is {type(text_or_spec)}")
if not vertical:
vertical = False
else:
vertical = True
label = create_part_label(text, heading)
row = create_layout_with_items(vertical=vertical, spacing=spacing, items=[label])
# Add spacer to push button to right
row.addStretch()
button = create_part_round_button(slot, tooltip)
row.addWidget(button)
# Clicking the part name works like clicking its button
make_label_clickable(label, button)
return row, button
[docs]
def create_part_label(text: str, heading: bool = False) -> QLabel:
"""
Add label for part with color based on text
:param text: str the part's name
:param heading: bool names a section of the panel rather than a part, and
so takes the skin's second bar where it has one
:return: QLabel
"""
label = QLabel(text)
if text == "Analog Synth":
label.setStyleSheet(JDXi.UI.Style.LABEL_ANALOG_SYNTH_PART)
elif heading:
panel_heading_background_ink(label, JDXi.UI.Style.LABEL_SYNTH_PART, alt=True)
else:
panel_ink(label, JDXi.UI.Style.LABEL_SYNTH_PART)
return label
[docs]
def create_part_round_button(slot: Callable[[...], Any] | Any, tooltip: str) -> QPushButton:
"""Create round button per part"""
from jdxi_editor.ui.style.factory import active_round_button_style
part_button_sec = ButtonSpec(tooltip=tooltip, size=30, checkable=True, style=active_round_button_style())
button = create_button_from_spec(part_button_sec)
if slot is not None:
button.clicked.connect(slot)
return button