diff --git a/emmental/__init__.py b/emmental/__init__.py index d69ed56..3f552dc 100644 --- a/emmental/__init__.py +++ b/emmental/__init__.py @@ -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.""" diff --git a/emmental/emmental.css b/emmental/emmental.css new file mode 100644 index 0000000..65bce02 --- /dev/null +++ b/emmental/emmental.css @@ -0,0 +1 @@ +/* Copyright 2022 (c) Anna Schumaker. */ diff --git a/emmental/gsetup.py b/emmental/gsetup.py index b102342..7f54579 100644 --- a/emmental/gsetup.py +++ b/emmental/gsetup.py @@ -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): diff --git a/tests/test_gsetup.py b/tests/test_gsetup.py index 1501ac2..e0f0ec4 100644 --- a/tests/test_gsetup.py +++ b/tests/test_gsetup.py @@ -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)