diff --git a/.gitignore b/.gitignore index e0c7a94..f1d1daa 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.txt *.patch PKGBUILD +emmental.gresource* diff --git a/Makefile b/Makefile index efa2a93..e080595 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,10 @@ export EMMENTAL_LIB = ${PREFIX}/lib/emmental export EMMENTAL_BIN = ${PREFIX}/bin export EMMENTAL_SHARE = ${PREFIX}/share -all: flake8 +all: emmental.gresource flake8 clean: + find . -type f -name "*gresource*" -exec rm {} \+ find . -type d -name __pycache__ -exec rm -r {} \+ find data/ -type d -name "Test Album" -exec rm -r {} \+ find data/ -type d -name "Test Library" -exec rm -r {} \+ @@ -17,8 +18,16 @@ clean: flake8: flake8 emmental/ tests/ +.PHONY: emmental.gresource.xml +emmental.gresource.xml: + exec tools/find-resources.py + +.PHONY: emmental.gresource +emmental.gresource: emmental.gresource.xml + glib-compile-resources emmental.gresource.xml + .PHONY: install -install: +install: emmental.gresource exec tools/install.sh .PHONY: uninstall @@ -40,7 +49,7 @@ pkgbuild: cd aur && makepkg --printsrcinfo > .SRCINFO .PHONY: pytest -pytest: +pytest: emmental.gresource pytest .PHONY: tests diff --git a/emmental/__init__.py b/emmental/__init__.py index 3f552dc..0615e3c 100644 --- a/emmental/__init__.py +++ b/emmental/__init__.py @@ -15,7 +15,8 @@ class Application(Adw.Application): def __init__(self): """Initialize an Application.""" - super().__init__(application_id=gsetup.APPLICATION_ID) + super().__init__(application_id=gsetup.APPLICATION_ID, + resource_base_path=gsetup.RESOURCE_PATH) self.add_main_option_entries([options.Version]) def do_handle_local_options(self, opts: GLib.VariantDict) -> int: diff --git a/emmental/gsetup.py b/emmental/gsetup.py index 7f54579..ce73cee 100644 --- a/emmental/gsetup.py +++ b/emmental/gsetup.py @@ -1,5 +1,5 @@ # Copyright 2022 (c) Anna Schumaker. -"""Set up GObject Introspection and custom styling.""" +"""Set up GObject Introspection, and custom styling, and icons.""" import pathlib import sys import gi @@ -8,6 +8,7 @@ gi.require_version("Gdk", "4.0") gi.require_version("Gtk", "4.0") gi.require_version("Adw", "1") +gi.importlib.import_module("gi.repository.Gio") gi.importlib.import_module("gi.repository.Gtk") DEBUG_STR = "-debug" if __debug__ else "" @@ -18,6 +19,12 @@ CSS_PRIORITY = gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION CSS_PROVIDER = gi.repository.Gtk.CssProvider() CSS_PROVIDER.load_from_path(str(CSS_FILE)) +RESOURCE_PATH = "/com/nowheycreamery/emmental" +RESOURCE_ICONS = f"{RESOURCE_PATH}/icons/scalable/apps" +RESOURCE_FILE = pathlib.Path(__file__).parent.parent / "emmental.gresource" +RESOURCE = gi.repository.Gio.Resource.load(str(RESOURCE_FILE)) +gi.repository.Gio.resources_register(RESOURCE) + def add_style(): """Add our stylesheet to the default display.""" diff --git a/icons/scalable/apps/emmental.svg b/icons/scalable/apps/emmental.svg new file mode 100644 index 0000000..5b25897 --- /dev/null +++ b/icons/scalable/apps/emmental.svg @@ -0,0 +1,118 @@ + + + + + + + music-note + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/tests/test_emmental.py b/tests/test_emmental.py index 46012d4..71ae52a 100644 --- a/tests/test_emmental.py +++ b/tests/test_emmental.py @@ -23,3 +23,5 @@ class TestEmmental(unittest.TestCase): self.assertIsInstance(self.application, gi.repository.Adw.Application) self.assertEqual(self.application.get_application_id(), "com.nowheycreamery.emmental-debug") + self.assertEqual(self.application.get_property("resource-base-path"), + "/com/nowheycreamery/emmental") diff --git a/tests/test_gsetup.py b/tests/test_gsetup.py index e0f0ec4..7a9f2fb 100644 --- a/tests/test_gsetup.py +++ b/tests/test_gsetup.py @@ -38,3 +38,18 @@ class TestGSetup(unittest.TestCase): gi.repository.Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) self.assertIsInstance(emmental.gsetup.CSS_PROVIDER, gi.repository.Gtk.CssProvider) + + def test_resource(self): + """Check that emmental.resource has been loaded.""" + path = pathlib.Path(emmental.__file__).parent.parent + path = path / "emmental.gresource" + + self.assertEqual(emmental.gsetup.RESOURCE_PATH, + "/com/nowheycreamery/emmental") + icons = f"{emmental.gsetup.RESOURCE_PATH}/icons/scalable/apps" + self.assertEqual(emmental.gsetup.RESOURCE_ICONS, icons) + self.assertEqual(emmental.gsetup.RESOURCE_FILE, path) + self.assertTrue(emmental.gsetup.RESOURCE_FILE.is_file()) + + self.assertIsInstance(emmental.gsetup.RESOURCE, + gi.repository.Gio.Resource) diff --git a/tools/find-resources.py b/tools/find-resources.py new file mode 100755 index 0000000..e9dab35 --- /dev/null +++ b/tools/find-resources.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# Copyright 2022 (c) Anna Schumaker. +"""Generate the emmental.gresource.xml file.""" +from xml.dom import minidom +import pathlib + +project_dir = pathlib.Path(__file__).parent.parent +resource_file = project_dir / "emmental.gresource.xml" + +xml = minidom.Document() + +gresources = xml.createElement("gresources") +xml.appendChild(gresources) + +gresource = xml.createElement("gresource") +gresource.setAttribute("prefix", "/com/nowheycreamery/emmental") +gresources.appendChild(gresource) + +for f in (project_dir / "icons").glob("**/*"): + if f.is_file(): + file = xml.createElement("file") + text = xml.createTextNode(str(f.relative_to(project_dir))) + file.appendChild(text) + gresource.appendChild(file) + +with open(project_dir / "emmental.gresource.xml", "w") as f: + f.write(xml.toprettyxml())