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 <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-12-26 15:24:50 -05:00
parent db2d122211
commit beca08b833
3 changed files with 22 additions and 31 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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)