header: Add an icon for background mode to the Header
I also update the button tooltip to display the background listening status along with the current volume level. Implements: #50 ("Background Music Mode") Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0e40e6a4e8
commit
7155fa9db5
|
@ -46,18 +46,24 @@ class Header(Gtk.HeaderBar):
|
||||||
self._title = Adw.WindowTitle(title=self.title, subtitle=self.subtitle,
|
self._title = Adw.WindowTitle(title=self.title, subtitle=self.subtitle,
|
||||||
tooltip_text=gsetup.env_string())
|
tooltip_text=gsetup.env_string())
|
||||||
self._volume = volume.VolumeRow()
|
self._volume = volume.VolumeRow()
|
||||||
|
self._volume_icon = Gtk.Image(icon_name=_volume_icon(self.volume))
|
||||||
self._background = volume.BackgroundRow()
|
self._background = volume.BackgroundRow()
|
||||||
|
self._background_icon = Gtk.Image(icon_name="sound-wave")
|
||||||
self._replaygain = replaygain.ReplayGainRow()
|
self._replaygain = replaygain.ReplayGainRow()
|
||||||
|
|
||||||
|
self._icons = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 6)
|
||||||
|
self._icons.append(self._volume_icon)
|
||||||
|
self._icons.append(self._background_icon)
|
||||||
|
|
||||||
self._box = Gtk.ListBox(selection_mode=Gtk.SelectionMode.NONE)
|
self._box = Gtk.ListBox(selection_mode=Gtk.SelectionMode.NONE)
|
||||||
self._box.add_css_class("boxed-list")
|
self._box.add_css_class("boxed-list")
|
||||||
self._box.append(self._volume)
|
self._box.append(self._volume)
|
||||||
self._box.append(self._background)
|
self._box.append(self._background)
|
||||||
self._box.append(self._replaygain)
|
self._box.append(self._replaygain)
|
||||||
|
|
||||||
icon = _volume_icon(self.volume)
|
|
||||||
self._button = buttons.PopoverButton(popover_child=self._box,
|
self._button = buttons.PopoverButton(popover_child=self._box,
|
||||||
icon_name=icon)
|
child=self._icons,
|
||||||
|
has_frame=False, margin_end=6)
|
||||||
|
|
||||||
self.bind_property("title", self._title, "title")
|
self.bind_property("title", self._title, "title")
|
||||||
self.bind_property("subtitle", self._title, "subtitle")
|
self.bind_property("subtitle", self._title, "subtitle")
|
||||||
|
@ -92,11 +98,19 @@ class Header(Gtk.HeaderBar):
|
||||||
|
|
||||||
def __notify(self, header: typing.Self, param: GObject.ParamSpec) -> None:
|
def __notify(self, header: typing.Self, param: GObject.ParamSpec) -> None:
|
||||||
match param.name:
|
match param.name:
|
||||||
|
case "bg-enabled":
|
||||||
|
icon = "sound-wave-alt" if self.bg_enabled else "sound-wave"
|
||||||
|
self._background_icon.set_from_icon_name(icon)
|
||||||
case "volume":
|
case "volume":
|
||||||
self._button.set_icon_name(_volume_icon(self.volume))
|
self._volume_icon.set_from_icon_name(_volume_icon(self.volume))
|
||||||
|
|
||||||
|
bg_status = "off"
|
||||||
|
if self.bg_enabled:
|
||||||
|
bg_status = f"{round(self.bg_volume * 100)}%"
|
||||||
|
|
||||||
rg_status = f"{self.rg_mode} mode" if self.rg_enabled else "off"
|
rg_status = f"{self.rg_mode} mode" if self.rg_enabled else "off"
|
||||||
status = (f"volume: {round(self.volume * 100)}%\n"
|
status = (f"volume: {round(self.volume * 100)}%\n"
|
||||||
|
f"background listening: {bg_status}\n"
|
||||||
f"normalizing: {rg_status}")
|
f"normalizing: {rg_status}")
|
||||||
self._button.set_tooltip_text(status)
|
self._button.set_tooltip_text(status)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 0 16 16" width="16px"><path d="m 5.5 4 c -0.277344 0 -0.5 0.222656 -0.5 0.5 v 8 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -8 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 z m 4 1 c -0.277344 0 -0.5 0.222656 -0.5 0.5 v 6 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -6 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 z m -2 1 c -0.277344 0 -0.5 0.222656 -0.5 0.5 v 4 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -4 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 z m 4 0 c -0.277344 0 -0.5 0.222656 -0.5 0.5 v 4 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -4 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 z m -8 1 c -0.277344 0 -0.5 0.222656 -0.5 0.5 v 3 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -3 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 z m -2.027344 1 c -0.261718 0.011719 -0.472656 0.230469 -0.472656 0.5 v 1 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -1 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 c -0.007812 0 -0.015625 0 -0.027344 0 z m 12 0 c -0.261718 0.011719 -0.472656 0.230469 -0.472656 0.5 v 1 c 0 0.277344 0.222656 0.5 0.5 0.5 s 0.5 -0.222656 0.5 -0.5 v -1 c 0 -0.277344 -0.222656 -0.5 -0.5 -0.5 c -0.007812 0 -0.015625 0 -0.027344 0 z m 0 0"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 0 16 16" width="16px"><path d="m 8 2 c -0.554688 0 -1 0.445312 -1 1 v 10 c 0 0.554688 0.445312 1 1 1 s 1 -0.445312 1 -1 v -10 c 0 -0.554688 -0.445312 -1 -1 -1 z m 6 2 c -0.554688 0 -1 0.445312 -1 1 v 6 c 0 0.554688 0.445312 1 1 1 s 1 -0.445312 1 -1 v -6 c 0 -0.554688 -0.445312 -1 -1 -1 z m -9 1 c -0.554688 0 -1 0.445312 -1 1 v 4 c 0 0.554688 0.445312 1 1 1 s 1 -0.445312 1 -1 v -4 c 0 -0.554688 -0.445312 -1 -1 -1 z m 6 1 c -0.554688 0 -1 0.445312 -1 1 v 2 c 0 0.554688 0.445312 1 1 1 s 1 -0.445312 1 -1 v -2 c 0 -0.554688 -0.445312 -1 -1 -1 z m -9 1 c -0.554688 0 -1 0.445312 -1 1 s 0.445312 1 1 1 s 1 -0.445312 1 -1 s -0.445312 -1 -1 -1 z m 0 0"/></svg>
|
After Width: | Height: | Size: 762 B |
|
@ -62,6 +62,19 @@ class TestHeader(tests.util.TestCase):
|
||||||
self.header._settings.emit("clicked")
|
self.header._settings.emit("clicked")
|
||||||
mock_present.assert_called()
|
mock_present.assert_called()
|
||||||
|
|
||||||
|
def test_volume_icons(self):
|
||||||
|
"""Check that the volume icons box is set up properly."""
|
||||||
|
self.assertIsInstance(self.header._icons, Gtk.Box)
|
||||||
|
self.assertIsInstance(self.header._volume_icon, Gtk.Image)
|
||||||
|
self.assertIsInstance(self.header._background_icon, Gtk.Image)
|
||||||
|
|
||||||
|
self.assertEqual(self.header._icons.get_spacing(), 6)
|
||||||
|
|
||||||
|
self.assertEqual(self.header._icons.get_first_child(),
|
||||||
|
self.header._volume_icon)
|
||||||
|
self.assertEqual(self.header._volume_icon.get_next_sibling(),
|
||||||
|
self.header._background_icon)
|
||||||
|
|
||||||
def test_volume(self):
|
def test_volume(self):
|
||||||
"""Check that volume widgets work as expected."""
|
"""Check that volume widgets work as expected."""
|
||||||
self.assertIsInstance(self.header._volume,
|
self.assertIsInstance(self.header._volume,
|
||||||
|
@ -80,27 +93,46 @@ class TestHeader(tests.util.TestCase):
|
||||||
widget.volume = vol
|
widget.volume = vol
|
||||||
self.assertEqual(self.header.volume, vol)
|
self.assertEqual(self.header.volume, vol)
|
||||||
self.assertEqual(self.header._volume.volume, vol)
|
self.assertEqual(self.header._volume.volume, vol)
|
||||||
self.assertEqual(self.header._button.get_icon_name(),
|
self.assertEqual(self.header._volume_icon.get_icon_name(),
|
||||||
f"audio-volume-{icon}-symbolic")
|
f"audio-volume-{icon}-symbolic")
|
||||||
self.assertEqual(self.header._button.get_tooltip_text(),
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
f"volume: {i*10}%\nnormalizing: off")
|
f"volume: {i*10}%\n"
|
||||||
|
"background listening: off\nnormalizing: off")
|
||||||
|
|
||||||
def test_background_listening(self):
|
def test_background_listening(self):
|
||||||
"""Test the background listening mode."""
|
"""Test the background listening mode."""
|
||||||
self.assertIsInstance(self.header._background,
|
self.assertIsInstance(self.header._background,
|
||||||
emmental.header.volume.BackgroundRow)
|
emmental.header.volume.BackgroundRow)
|
||||||
|
self.assertEqual(self.header._background_icon.get_icon_name(),
|
||||||
|
"sound-wave")
|
||||||
|
|
||||||
self.assertFalse(self.header.bg_enabled)
|
self.assertFalse(self.header.bg_enabled)
|
||||||
|
self.assertEqual(self.header.bg_volume, 0.5)
|
||||||
|
|
||||||
self.header.bg_enabled = True
|
self.header.bg_enabled = True
|
||||||
self.assertTrue(self.header._background.enabled)
|
self.assertTrue(self.header._background.enabled)
|
||||||
self.header._background.enabled = False
|
self.assertEqual(self.header._background_icon.get_icon_name(),
|
||||||
self.assertFalse(self.header.bg_enabled)
|
"sound-wave-alt")
|
||||||
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
|
"volume: 100%\nbackground listening: 50%\n"
|
||||||
|
"normalizing: off")
|
||||||
|
|
||||||
self.assertEqual(self.header.bg_volume, 0.5)
|
|
||||||
self.header.bg_volume = 0.75
|
self.header.bg_volume = 0.75
|
||||||
self.assertEqual(self.header._background.volume, 0.75)
|
self.assertEqual(self.header._background.volume, 0.75)
|
||||||
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
|
"volume: 100%\nbackground listening: 75%\n"
|
||||||
|
"normalizing: off")
|
||||||
|
|
||||||
self.header._background.volume = 0.25
|
self.header._background.volume = 0.25
|
||||||
self.assertEqual(self.header.bg_volume, 0.25)
|
self.assertEqual(self.header.bg_volume, 0.25)
|
||||||
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
|
"volume: 100%\nbackground listening: 25%\n"
|
||||||
|
"normalizing: off")
|
||||||
|
|
||||||
|
self.header._background.enabled = False
|
||||||
|
self.assertFalse(self.header.bg_enabled)
|
||||||
|
self.assertEqual(self.header._background_icon.get_icon_name(),
|
||||||
|
"sound-wave")
|
||||||
|
|
||||||
def test_replaygain(self):
|
def test_replaygain(self):
|
||||||
"""Test that we can configure ReplayGain as expected."""
|
"""Test that we can configure ReplayGain as expected."""
|
||||||
|
@ -114,23 +146,27 @@ class TestHeader(tests.util.TestCase):
|
||||||
self.assertTrue(self.header._replaygain.enabled)
|
self.assertTrue(self.header._replaygain.enabled)
|
||||||
self.assertEqual(self.header._replaygain.mode, "track")
|
self.assertEqual(self.header._replaygain.mode, "track")
|
||||||
self.assertEqual(self.header._button.get_tooltip_text(),
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
"volume: 100%\nnormalizing: track mode")
|
"volume: 100%\nbackground listening: off\n"
|
||||||
|
"normalizing: track mode")
|
||||||
|
|
||||||
self.header._replaygain.enabled = False
|
self.header._replaygain.enabled = False
|
||||||
self.header._replaygain.mode = "album"
|
self.header._replaygain.mode = "album"
|
||||||
self.assertFalse(self.header.rg_enabled)
|
self.assertFalse(self.header.rg_enabled)
|
||||||
self.assertEqual(self.header.rg_mode, "album")
|
self.assertEqual(self.header.rg_mode, "album")
|
||||||
self.assertEqual(self.header._button.get_tooltip_text(),
|
self.assertEqual(self.header._button.get_tooltip_text(),
|
||||||
"volume: 100%\nnormalizing: off")
|
"volume: 100%\nbackground listening: off\n"
|
||||||
|
"normalizing: off")
|
||||||
|
|
||||||
def test_popover_button(self):
|
def test_popover_button(self):
|
||||||
"""Check that the menu popover button was set up correctly."""
|
"""Check that the menu popover button was set up correctly."""
|
||||||
self.assertIsInstance(self.header._button,
|
self.assertIsInstance(self.header._button,
|
||||||
emmental.buttons.PopoverButton)
|
emmental.buttons.PopoverButton)
|
||||||
self.assertEqual(self.header._button.get_icon_name(),
|
|
||||||
"audio-volume-high-symbolic")
|
|
||||||
self.assertEqual(self.header._button.popover_child, self.header._box)
|
self.assertEqual(self.header._button.popover_child, self.header._box)
|
||||||
|
|
||||||
|
self.assertEqual(self.header._button.get_child(), self.header._icons)
|
||||||
|
self.assertEqual(self.header._button.get_margin_end(), 6)
|
||||||
|
self.assertFalse(self.header._button.get_has_frame())
|
||||||
|
|
||||||
def test_popover_child(self):
|
def test_popover_child(self):
|
||||||
"""Check that the menu popover button child was set up correctly."""
|
"""Check that the menu popover button child was set up correctly."""
|
||||||
self.assertIsInstance(self.header._box, Gtk.ListBox)
|
self.assertIsInstance(self.header._box, Gtk.ListBox)
|
||||||
|
|
Loading…
Reference in New Issue