header: Add a custom Header class
The header currently contains just the title & subtitle information, but will be expanded to add volume controls in the next patch. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
236a1e60c2
commit
50270bd04c
|
@ -2,6 +2,7 @@
|
|||
"""Set up our Application."""
|
||||
from . import gsetup
|
||||
from . import db
|
||||
from . import header
|
||||
from . import mpris2
|
||||
from . import options
|
||||
from . import window
|
||||
|
@ -27,9 +28,15 @@ class Application(Adw.Application):
|
|||
resource_base_path=gsetup.RESOURCE_PATH)
|
||||
self.add_main_option_entries([options.Version])
|
||||
|
||||
def build_header(self) -> header.Header:
|
||||
"""Build a new header instance."""
|
||||
return header.Header(sql=self.db, title=VERSION_STRING)
|
||||
|
||||
def build_window(self) -> window.Window:
|
||||
"""Build a new window instance."""
|
||||
win = window.Window(VERSION_STRING)
|
||||
win = window.Window(VERSION_STRING,
|
||||
header=self.build_header())
|
||||
|
||||
for (setting, property) in [("window.width", "default-width"),
|
||||
("window.height", "default-height")]:
|
||||
self.db.settings.bind_setting(setting, win, property)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright 2022 (c) Anna Schumaker.
|
||||
"""A custom Gtk.HeaderBar configured for our application."""
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Adw
|
||||
from .. import db
|
||||
|
||||
SUBTITLE = "The Cheesy Music Player"
|
||||
|
||||
|
||||
class Header(Gtk.HeaderBar):
|
||||
"""Our custom Gtk.HeaderBar containing window title and volume controls."""
|
||||
|
||||
sql = GObject.Property(type=db.Connection)
|
||||
title = GObject.Property(type=str)
|
||||
subtitle = GObject.Property(type=str)
|
||||
|
||||
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)
|
||||
|
||||
self.bind_property("title", self._title, "title")
|
||||
self.bind_property("subtitle", self._title, "subtitle")
|
||||
|
||||
self.set_title_widget(self._title)
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright 2022 (c) Anna Schumaker.
|
||||
"""Tests our application header."""
|
||||
import emmental
|
||||
import tests.util
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Adw
|
||||
|
||||
|
||||
class TestHeader(tests.util.TestCase):
|
||||
"""Test case for our custom Gtk.HeaderBar."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up common variables."""
|
||||
super().setUp()
|
||||
self.header = emmental.header.Header(sql=self.sql, title="Test Title")
|
||||
|
||||
def test_constants(self):
|
||||
"""Check that constants are set correctly."""
|
||||
self.assertEqual(emmental.header.SUBTITLE, "The Cheesy Music Player")
|
||||
|
||||
def test_title(self):
|
||||
"""Check that the title is set correctly."""
|
||||
self.assertIsInstance(self.header, Gtk.HeaderBar)
|
||||
self.assertIsInstance(self.header._title, Adw.WindowTitle)
|
||||
|
||||
self.assertEqual(self.header.get_title_widget(), self.header._title)
|
||||
self.assertEqual(self.header.title, "Test Title")
|
||||
self.assertEqual(self.header._title.get_title(), "Test Title")
|
||||
|
||||
self.assertEqual(self.header.subtitle, emmental.header.SUBTITLE)
|
||||
self.assertEqual(self.header._title.get_subtitle(),
|
||||
emmental.header.SUBTITLE)
|
|
@ -86,3 +86,5 @@ class TestEmmental(unittest.TestCase):
|
|||
win = self.application.build_window()
|
||||
|
||||
self.assertIsInstance(win, emmental.window.Window)
|
||||
self.assertIsInstance(win.header, emmental.header.Header)
|
||||
self.assertEqual(win.header.title, emmental.VERSION_STRING)
|
||||
|
|
Loading…
Reference in New Issue