Commit 30513d8a authored by Nico Alt's avatar Nico Alt

Rework application.py to make it more clean

parent 73436621
......@@ -50,7 +50,7 @@ def prepare():
def start_application():
from briar.gtk.application import Application
sys.exit(Application("@VERSION@").run(sys.argv))
sys.exit(Application().run(sys.argv))
if __name__ == '__main__':
prepare()
......
......@@ -10,45 +10,56 @@ from gi.repository import Gdk, Gio, GLib, Gtk
from briar.api.api import Api
from briar.gtk.define import APPLICATION_ID, APPLICATION_NAME
from briar.gtk.define import BRIAR_HEADLESS_JAR
from briar.gtk.window import Window
class Application(Gtk.Application):
def __init__(self, version):
GLib.set_application_name("Briar")
GLib.set_prgname("Briar")
super().__init__(application_id='app.briar.gtk')
self.window = None
self._set_version(version)
def __init__(self):
Application._set_application_name()
super().__init__(application_id=APPLICATION_ID)
# pylint: disable=arguments-differ
def do_startup(self):
Gtk.Application.do_startup(self)
Application._setup_styling()
self._setup_api()
# pylint: disable=arguments-differ
def do_activate(self):
self._setup_window()
# pylint: disable=arguments-differ
def quit(self):
self.api.stop()
self.window.hide()
Gio.Application.quit(self)
@staticmethod
def _set_application_name():
GLib.set_application_name(APPLICATION_NAME)
GLib.set_prgname(APPLICATION_NAME)
@staticmethod
def _setup_styling():
css_provider_file = Gio.File.new_for_uri(
"resource:///app/briar/gtk/ui/application.css")
css_provider = Gtk.CssProvider()
css_provider.load_from_file(css_provider_file)
screen = Gdk.Screen.get_default()
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(screen, css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.api = Api('/app/briar/briar-headless.jar')
def _setup_api(self):
self.api = Api(BRIAR_HEADLESS_JAR)
# pylint: disable=arguments-differ
def do_activate(self):
if self.window is None:
# pylint: disable=access-member-before-definition
def _setup_window(self):
if not hasattr(self, "window") or self.window is None:
self.window = Window()
self.window.show()
self.window.present()
# pylint: disable=arguments-differ
def quit(self):
self.api.stop()
self.window.hide()
Gio.Application.quit(self)
def _set_version(self, version):
self._version = version
......@@ -8,4 +8,8 @@
from gi.repository import Gio
APPLICATION_ID = "app.briar.gtk"
APPLICATION_NAME = "Briar"
BRIAR_HEADLESS_JAR = "/app/briar/briar-headless.jar"
App = Gio.Application.get_default # pylint: disable=invalid-name
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment