audio: Add ReplayGainComboBox and ReplayGainControl widgets
For setting the replaygain mode on the player Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
4f4e9efa28
commit
9c5b409d02
|
@ -78,12 +78,40 @@ class VolumeControlBox(ControlScaleBox):
|
|||
icon.set_from_icon_name(f"audio-volume-{name}-symbolic")
|
||||
|
||||
|
||||
class ReplayGainComboBox(Gtk.ComboBoxText):
|
||||
def __init__(self, player):
|
||||
Gtk.ComboBoxText.__init__(self)
|
||||
self.modes = [ "disabled", "track", "album" ]
|
||||
self.player = player
|
||||
|
||||
self.append_text("ReplayGain Disabled")
|
||||
self.append_text("ReplayGain Track Mode")
|
||||
self.append_text("ReplayGain Album Mode")
|
||||
self.set_active(self.modes.index(player.replaygain))
|
||||
self.set_can_focus(False)
|
||||
|
||||
def do_changed(self):
|
||||
self.player.set_property("replaygain", self.modes[self.get_active()])
|
||||
|
||||
|
||||
class ReplayGainControl(Gtk.Box):
|
||||
def __init__(self, player):
|
||||
Gtk.Box.__init__(self)
|
||||
self.icon = Gtk.Image.new_from_icon_name("audio-headphones")
|
||||
self.icon.add_css_class("large-icons")
|
||||
self.rgcombo = ReplayGainComboBox(player)
|
||||
|
||||
self.append(self.icon)
|
||||
self.append(self.rgcombo)
|
||||
|
||||
|
||||
class ControlsPopover(Gtk.Popover):
|
||||
def __init__(self, player, apscale):
|
||||
Gtk.Popover.__init__(self)
|
||||
self.box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
|
||||
self.box.append(AutoPauseControlBox(apscale))
|
||||
self.box.append(VolumeControlBox(player))
|
||||
self.box.append(ReplayGainControl(player))
|
||||
self.set_child(self.box)
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class FakePlayer(GObject.GObject):
|
|||
self.nxt = False
|
||||
self.play = False
|
||||
self.vol = 1.0
|
||||
self.rgain = "disabled"
|
||||
|
||||
@GObject.Property
|
||||
def playing(self): return self.play
|
||||
|
@ -29,6 +30,11 @@ class FakePlayer(GObject.GObject):
|
|||
def playpause(self):
|
||||
self.playing = not self.playing
|
||||
|
||||
@GObject.Property
|
||||
def replaygain(self): return self.rgain
|
||||
@replaygain.setter
|
||||
def replaygain(self, newval): self.rgain = newval
|
||||
|
||||
@GObject.Signal
|
||||
def playback_start(self): pass
|
||||
@GObject.Signal
|
||||
|
@ -126,6 +132,41 @@ class TestVolumeControlbox(unittest.TestCase):
|
|||
self.assertEqual(icon.get_icon_name(), "audio-volume-high-symbolic")
|
||||
|
||||
|
||||
class TestReplayGainComboBox(unittest.TestCase):
|
||||
def test_replay_gain_combobox(self):
|
||||
fake = FakePlayer()
|
||||
combo = controls.ReplayGainComboBox(fake)
|
||||
|
||||
self.assertIsInstance(combo, Gtk.ComboBoxText)
|
||||
self.assertEqual(combo.player, fake)
|
||||
self.assertEqual(combo.modes, [ "disabled", "track", "album" ])
|
||||
self.assertEqual(combo.get_active_text(), "ReplayGain Disabled")
|
||||
|
||||
combo.set_active(1)
|
||||
self.assertEqual(combo.get_active_text(), "ReplayGain Track Mode")
|
||||
self.assertEqual(fake.replaygain, "track")
|
||||
|
||||
combo.set_active(2)
|
||||
self.assertEqual(combo.get_active_text(), "ReplayGain Album Mode")
|
||||
self.assertEqual(fake.replaygain, "album")
|
||||
|
||||
|
||||
class TestReplayGainControl(unittest.TestCase):
|
||||
def test_replay_gain_control(self):
|
||||
fake = FakePlayer()
|
||||
rgc = controls.ReplayGainControl(fake)
|
||||
|
||||
self.assertIsInstance(rgc, Gtk.Box)
|
||||
self.assertIsInstance(rgc.icon, Gtk.Image)
|
||||
self.assertIsInstance(rgc.rgcombo, controls.ReplayGainComboBox)
|
||||
|
||||
self.assertEqual(rgc.get_orientation(), Gtk.Orientation.HORIZONTAL)
|
||||
self.assertEqual(rgc.icon.get_icon_name(), "audio-headphones")
|
||||
self.assertEqual(rgc.get_first_child(), rgc.icon)
|
||||
self.assertEqual(rgc.icon.get_next_sibling(), rgc.rgcombo)
|
||||
self.assertTrue(rgc.icon.has_css_class("large-icons"))
|
||||
|
||||
|
||||
class TestControlsPopover(unittest.TestCase):
|
||||
def test_controls_popover(self):
|
||||
fake = FakePlayer()
|
||||
|
@ -139,6 +180,8 @@ class TestControlsPopover(unittest.TestCase):
|
|||
self.assertIsInstance(child, controls.AutoPauseControlBox)
|
||||
child = child.get_next_sibling()
|
||||
self.assertIsInstance(child, controls.VolumeControlBox)
|
||||
child = child.get_next_sibling()
|
||||
self.assertIsInstance(child, controls.ReplayGainControl)
|
||||
|
||||
self.assertEqual(pop.get_child(), pop.box)
|
||||
self.assertEqual(pop.box.get_orientation(), Gtk.Orientation.VERTICAL)
|
||||
|
|
Loading…
Reference in New Issue