From c5867badae3938c964be18426bc2b8d31f45c420 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 24 Jan 2024 10:13:11 -0500 Subject: [PATCH] header: Add a menu button This will be expanded to contain the open file button, the settings dialog, and eventually a listenbrainz configuration option. Signed-off-by: Anna Schumaker --- emmental/header/__init__.py | 14 ++++++++++++-- tests/header/test_header.py | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/emmental/header/__init__.py b/emmental/header/__init__.py index aff2897..efc5b3d 100644 --- a/emmental/header/__init__.py +++ b/emmental/header/__init__.py @@ -44,11 +44,20 @@ class Header(Gtk.HeaderBar): def __init__(self, sql: db.Connection, title: str): """Initialize the HeaderBar.""" super().__init__(title=title, subtitle=SUBTITLE, sql=sql) + self._title = Adw.WindowTitle(title=self.title, subtitle=self.subtitle, + tooltip_text=gsetup.env_string()) + icon = "sidebar-show-symbolic" self._show_sidebar = Gtk.ToggleButton(icon_name=icon, has_frame=False) self._open = open.Button() - self._title = Adw.WindowTitle(title=self.title, subtitle=self.subtitle, - tooltip_text=gsetup.env_string()) + + self._menu_box = Gtk.ListBox(selection_mode=Gtk.SelectionMode.NONE) + self._menu_box.add_css_class("boxed-list") + + icon = "open-menu-symbolic" + self._menu_button = buttons.PopoverButton(popover_child=self._menu_box, + icon_name=icon) + self._volume = volume.VolumeRow() self._volume_icon = Gtk.Image(icon_name=_volume_icon(self.volume)) self._background = volume.BackgroundRow() @@ -92,6 +101,7 @@ class Header(Gtk.HeaderBar): tooltip_text="open settings editor") self._settings.connect("clicked", self.__run_settings) self.pack_start(self._settings) + self.pack_start(self._menu_button) self.pack_end(self._vol_button) self.set_title_widget(self._title) diff --git a/tests/header/test_header.py b/tests/header/test_header.py index 9de318c..b7b4b51 100644 --- a/tests/header/test_header.py +++ b/tests/header/test_header.py @@ -77,6 +77,24 @@ class TestHeader(tests.util.TestCase): self.header._settings.emit("clicked") mock_present.assert_called() + def test_menu_button(self): + """Check that the menu popover button is set up properly.""" + self.assertIsInstance(self.header._menu_button, + emmental.buttons.PopoverButton) + self.assertIsNotNone(self.header._menu_button.props.parent) + + self.assertEqual(self.header._menu_button.props.icon_name, + "open-menu-symbolic") + self.assertEqual(self.header._menu_button.popover_child, + self.header._menu_box) + + def test_menu_popover_child(self): + """Check that the menu popover button child was set up correctly.""" + self.assertIsInstance(self.header._menu_box, Gtk.ListBox) + self.assertEqual(self.header._menu_box.get_selection_mode(), + Gtk.SelectionMode.NONE) + self.assertTrue(self.header._menu_box.has_css_class("boxed-list")) + def test_volume_icons(self): """Check that the volume icons box is set up properly.""" self.assertIsInstance(self.header._icons, Gtk.Box)