emmental/emmental/header/replaygain.py

54 lines
2.3 KiB
Python

# Copyright 2022 (c) Anna Schumaker.
"""A widget for selecting ReplayGain mode."""
from gi.repository import GObject
from gi.repository import Gtk
class Selector(Gtk.Grid):
"""Build up a widget for configuring ReplayGain settings."""
enabled = GObject.Property(type=bool, default=False)
mode = GObject.Property(type=str, default="auto")
def __init__(self):
"""Initialize the ReplayGain selector."""
super().__init__(column_spacing=6, margin_top=8)
self._title = Gtk.Label(label="Volume Normalization", yalign=0.8,
hexpand=True, vexpand=True)
self._switch = Gtk.Switch()
self._auto = Gtk.CheckButton(label="Decide automatically",
sensitive=False, active=True)
self._album = Gtk.CheckButton(label="Albums have the same volume",
sensitive=False, group=self._auto)
self._track = Gtk.CheckButton(label="Tracks have the same volume",
sensitive=False, group=self._auto)
self.attach(self._title, 0, 0, 1, 1)
self.attach(self._switch, 1, 0, 1, 1)
self.attach(self._auto, 0, 1, 2, 1)
self.attach(self._album, 0, 2, 2, 1)
self.attach(self._track, 0, 3, 2, 1)
self.connect("notify::mode", self.__notify_mode)
self._auto.connect("toggled", self.__mode_toggled, "auto")
self._album.connect("toggled", self.__mode_toggled, "album")
self._track.connect("toggled", self.__mode_toggled, "track")
self._switch.bind_property("state", self._auto, "sensitive")
self._switch.bind_property("state", self._album, "sensitive")
self._switch.bind_property("state", self._track, "sensitive")
self.bind_property("enabled", self._switch, "state",
GObject.BindingFlags.BIDIRECTIONAL)
self._title.add_css_class("title-4")
def __notify_mode(self, selector: Gtk.Grid, param) -> None:
match selector.get_property("mode"):
case "album": self._album.set_active(True)
case "track": self._track.set_active(True)
case _: self._auto.set_active(True)
def __mode_toggled(self, check: Gtk.CheckButton, new_mode: str) -> None:
if check.get_active():
self.mode = new_mode