From beca08b8335917d3d3d6ed3c94fa21c17e934db3 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 26 Dec 2021 15:24:50 -0500 Subject: [PATCH] Implement the Gtk.Application instance in emmental.py We don't use this during testing, so put it here instead of in a submodule. Implements #26 (Move the EmmentalApplication into emmental.py) Signed-off-by: Anna Schumaker --- emmental.py | 23 ++++++++++++++++++++++- ui/__init__.py | 21 --------------------- ui/test_ui.py | 9 --------- 3 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 ui/test_ui.py diff --git a/emmental.py b/emmental.py index 826fe71..b4c48fd 100755 --- a/emmental.py +++ b/emmental.py @@ -3,5 +3,26 @@ import lib lib.settings.load() +import db import ui -ui.Application.run() +from gi.repository import Gtk + +class Application(Gtk.Application): + def __init__(self, *args, **kwargs): + app_id = f"org.gtk.emmental{'-debug' if __debug__ else ''}" + Gtk.Application.__init__(self, *args, application_id=app_id, **kwargs) + + def do_startup(self): + Gtk.Application.do_startup(self) + self.add_window(ui.window.Window()) + + def do_activate(self): + for window in self.get_windows(): + window.present() + + def do_shutdown(self): + Gtk.Application.do_shutdown(self) + db.sql.optimize() + +if __name__ == "__main__": + Application().run() diff --git a/ui/__init__.py b/ui/__init__.py index 52927a5..8c977a2 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -1,24 +1,3 @@ # Copyright 2021 (c) Anna Schumaker. from . import icons from . import window -from gi.repository import Gtk -import audio -import db - -class EmmentalApplication(Gtk.Application): - def __init__(self, *args, **kwargs): - Gtk.Application.__init__(self, *args, application_id="org.gtk.emmental", **kwargs) - - def do_activate(self): - self.window.present() - - def do_startup(self): - self.window = window.Window() - Gtk.Application.do_startup(self) - self.add_window(self.window) - - def do_shutdown(self): - db.sql.optimize() - Gtk.Application.do_shutdown(self) - -Application = EmmentalApplication() diff --git a/ui/test_ui.py b/ui/test_ui.py deleted file mode 100644 index 7e20802..0000000 --- a/ui/test_ui.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2021 (c) Anna Schumaker. -import unittest -import ui -from gi.repository import Gtk - -class TestEmmentalApplication(unittest.TestCase): - def test_application(self): - app = ui.EmmentalApplication() - self.assertIsInstance(app, Gtk.Application)