emmental: Wire up the show-sidebar properties

Allowing us to show and hide the sidebar by clicking the button in the
header. I also save the current state of the sidebar, although the
Adw.OverlaySplitView might override this when the window is shown.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2023-10-24 11:19:12 -04:00
parent ae1c611959
commit a08273535c
3 changed files with 28 additions and 1 deletions

View File

@ -206,11 +206,14 @@ class Application(Adw.Application):
now_playing=self.build_now_playing(),
sidebar=self.build_sidebar(),
tracklist=self.build_tracklist())
win.bind_property("show-sidebar", win.header, "show-sidebar",
GObject.BindingFlags.BIDIRECTIONAL)
win.bind_property("user-editing", win.now_playing, "editing")
for (setting, property) in [("window.width", "default-width"),
("window.height", "default-height"),
("now-playing.size", "now-playing-size")]:
("now-playing.size", "now-playing-size"),
("sidebar.show", "show-sidebar")]:
self.db.settings.bind_setting(setting, win, property)
self.__add_accelerators(win.accelerators)

View File

@ -292,3 +292,17 @@ class TestEmmental(unittest.TestCase):
win.header.bg_volume = 0.5
self.assertTrue(player.bg_enabled)
self.assertEqual(player.bg_volume, 0.5)
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_show_sidebar(self, mock_stdout: io.StringIO):
"""Test showing the sidebar."""
self.application.db = emmental.db.Connection()
self.application.factory = emmental.playlist.Factory(
self.application.db)
self.application.player = emmental.audio.Player()
win = self.application.build_window()
win.show_sidebar = True
self.assertTrue(win.header.show_sidebar)
win.header.show_sidebar = False
self.assertFalse(win.show_sidebar)

View File

@ -38,6 +38,16 @@ class TestSettings(unittest.TestCase):
win = self.app.build_window()
self.assertEqual(win.get_default_size(), (100, 200))
def test_save_show_sidebar(self, mock_stdout: io.StringIO):
"""Check saving and loading the show-sidebar property."""
self.assertFalse(self.settings["sidebar.show"])
self.win.show_sidebar = True
self.assertTrue(self.settings["sidebar.show"])
win = self.app.build_window()
self.assertTrue(win.show_sidebar)
def test_save_volume(self, mock_stdout: io.StringIO):
"""Check saving and loading volume from the database."""
self.assertEqual(self.settings["audio.volume"], 1.0)