header: Add a show sidebar button to the header
The user will be able to click on this to show and hide the sidebar. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e73b6c09e7
commit
ae1c611959
|
@ -34,6 +34,7 @@ class Header(Gtk.HeaderBar):
|
||||||
sql = GObject.Property(type=db.Connection)
|
sql = GObject.Property(type=db.Connection)
|
||||||
title = GObject.Property(type=str)
|
title = GObject.Property(type=str)
|
||||||
subtitle = GObject.Property(type=str)
|
subtitle = GObject.Property(type=str)
|
||||||
|
show_sidebar = GObject.Property(type=bool, default=False)
|
||||||
bg_enabled = GObject.Property(type=bool, default=False)
|
bg_enabled = GObject.Property(type=bool, default=False)
|
||||||
bg_volume = GObject.Property(type=float, default=0.5)
|
bg_volume = GObject.Property(type=float, default=0.5)
|
||||||
rg_enabled = GObject.Property(type=bool, default=False)
|
rg_enabled = GObject.Property(type=bool, default=False)
|
||||||
|
@ -43,6 +44,8 @@ class Header(Gtk.HeaderBar):
|
||||||
def __init__(self, sql: db.Connection, title: str):
|
def __init__(self, sql: db.Connection, title: str):
|
||||||
"""Initialize the HeaderBar."""
|
"""Initialize the HeaderBar."""
|
||||||
super().__init__(title=title, subtitle=SUBTITLE, sql=sql)
|
super().__init__(title=title, subtitle=SUBTITLE, sql=sql)
|
||||||
|
icon = "sidebar-show-symbolic"
|
||||||
|
self._show_sidebar = Gtk.ToggleButton(icon_name=icon, has_frame=False)
|
||||||
self._open = open.Button()
|
self._open = open.Button()
|
||||||
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())
|
||||||
|
@ -68,6 +71,8 @@ class Header(Gtk.HeaderBar):
|
||||||
|
|
||||||
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")
|
||||||
|
self.bind_property("show-sidebar", self._show_sidebar, "active",
|
||||||
|
GObject.BindingFlags.BIDIRECTIONAL)
|
||||||
self.bind_property("bg-enabled", self._background, "enabled",
|
self.bind_property("bg-enabled", self._background, "enabled",
|
||||||
GObject.BindingFlags.BIDIRECTIONAL)
|
GObject.BindingFlags.BIDIRECTIONAL)
|
||||||
self.bind_property("bg-volume", self._background, "volume",
|
self.bind_property("bg-volume", self._background, "volume",
|
||||||
|
@ -79,6 +84,7 @@ class Header(Gtk.HeaderBar):
|
||||||
self.bind_property("volume", self._volume, "volume",
|
self.bind_property("volume", self._volume, "volume",
|
||||||
GObject.BindingFlags.BIDIRECTIONAL)
|
GObject.BindingFlags.BIDIRECTIONAL)
|
||||||
|
|
||||||
|
self.pack_start(self._show_sidebar)
|
||||||
self.pack_start(self._open)
|
self.pack_start(self._open)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._window = settings.Window(sql)
|
self._window = settings.Window(sql)
|
||||||
|
|
|
@ -36,6 +36,21 @@ class TestHeader(tests.util.TestCase):
|
||||||
self.assertEqual(self.header._title.get_tooltip_text(),
|
self.assertEqual(self.header._title.get_tooltip_text(),
|
||||||
emmental.gsetup.env_string())
|
emmental.gsetup.env_string())
|
||||||
|
|
||||||
|
def test_show_sidebar(self):
|
||||||
|
"""Check that the show sidebar button works as expected."""
|
||||||
|
self.assertIsInstance(self.header._show_sidebar, Gtk.ToggleButton)
|
||||||
|
self.assertEqual(self.header._show_sidebar.props.icon_name,
|
||||||
|
"sidebar-show-symbolic")
|
||||||
|
self.assertFalse(self.header._show_sidebar.props.has_frame)
|
||||||
|
self.assertFalse(self.header._show_sidebar.props.active)
|
||||||
|
|
||||||
|
self.assertFalse(self.header.show_sidebar)
|
||||||
|
self.header.show_sidebar = True
|
||||||
|
self.assertTrue(self.header._show_sidebar.props.active)
|
||||||
|
|
||||||
|
self.header._show_sidebar.props.active = False
|
||||||
|
self.assertFalse(self.header.show_sidebar)
|
||||||
|
|
||||||
def test_open(self):
|
def test_open(self):
|
||||||
"""Check that the Open button works as expected."""
|
"""Check that the Open button works as expected."""
|
||||||
self.assertIsInstance(self.header._open, emmental.header.open.Button)
|
self.assertIsInstance(self.header._open, emmental.header.open.Button)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user