gsetup: Load our application CSS file

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-08-02 13:15:24 -04:00
parent 4072ea97d4
commit 5cd5d2640d
4 changed files with 30 additions and 2 deletions

View File

@ -29,6 +29,7 @@ class Application(Adw.Application):
def do_startup(self) -> None:
"""Handle the Adw.Application::startup signal."""
Adw.Application.do_startup(self)
gsetup.add_style()
def do_activate(self) -> None:
"""Handle the Adw.Application::activate signal."""

1
emmental/emmental.css Normal file
View File

@ -0,0 +1 @@
/* Copyright 2022 (c) Anna Schumaker. */

View File

@ -1,13 +1,29 @@
# Copyright 2022 (c) Anna Schumaker.
"""Set up GObject Introspection."""
"""Set up GObject Introspection and custom styling."""
import pathlib
import sys
import gi
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
gi.importlib.import_module("gi.repository.Gtk")
DEBUG_STR = "-debug" if __debug__ else ""
APPLICATION_ID = f"com.nowheycreamery.emmental{DEBUG_STR}"
APPLICATION_ID = f"com.nowheycreamery.emmental{'-debug' if __debug__ else ''}"
CSS_FILE = pathlib.Path(__file__).parent / "emmental.css"
CSS_PRIORITY = gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
CSS_PROVIDER = gi.repository.Gtk.CssProvider()
CSS_PROVIDER.load_from_path(str(CSS_FILE))
def add_style():
"""Add our stylesheet to the default display."""
style = gi.repository.Gtk.StyleContext
style.add_provider_for_display(gi.repository.Gdk.Display.get_default(),
CSS_PROVIDER, CSS_PRIORITY)
def __print_version(subsystem, major, minor, micro):

View File

@ -1,6 +1,7 @@
# Copyright 2022 (c) Anna Schumaker.
"""Test that the gi.repository has been configured correctly."""
import unittest
import pathlib
import emmental
import gi
@ -28,3 +29,12 @@ class TestGSetup(unittest.TestCase):
self.assertEqual(emmental.gsetup.DEBUG_STR, "-debug")
self.assertEqual(emmental.gsetup.APPLICATION_ID,
"com.nowheycreamery.emmental-debug")
def test_css(self):
"""Check that our custom stylesheet is configured."""
path = pathlib.Path(emmental.__file__).parent / "emmental.css"
self.assertEqual(emmental.gsetup.CSS_FILE, path)
self.assertEqual(emmental.gsetup.CSS_PRIORITY,
gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
self.assertIsInstance(emmental.gsetup.CSS_PROVIDER,
gi.repository.Gtk.CssProvider)