Commit 09eafd1c authored by Nico Alt's avatar Nico Alt

Rework window and startup_container to make them more clean

parent c163231d
Pipeline #3680 passed with stage
in 3 minutes and 16 seconds
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
from gi.repository import GLib, GObject, Gtk
from gi.repository import GLib
from briar.gtk.container import Container
from briar.gtk.define import App
......@@ -13,7 +13,6 @@ class StartupContainer(Container):
def __init__(self):
super().__init__()
self._api = App().api
StartupContainer._register_signals()
self._setup_view()
# pylint: disable=unused-argument
......@@ -29,18 +28,13 @@ class StartupContainer(Container):
"password_confirm_entry").get_text()
if password != password_confirm:
raise Exception("Passwords do not match")
self._api.register((self.username, password), self._startup_finished)
self._api.register((self.username, password),
StartupContainer._startup_completed)
# pylint: disable=unused-argument
def on_login_pressed(self, button):
password = self.builder.get_object("password_entry").get_text()
self._api.login(password, self._startup_finished)
@staticmethod
def _register_signals():
GObject.signal_new("briar_startup_completed", Gtk.Overlay,
GObject.SignalFlags.RUN_LAST, GObject.TYPE_BOOLEAN,
(GObject.TYPE_STRING,))
self._api.login(password, StartupContainer._startup_completed)
def _setup_view(self):
self.set_hexpand(True)
......@@ -53,8 +47,9 @@ class StartupContainer(Container):
self.add(self.builder.get_object("login"))
self.builder.connect_signals(self)
def _startup_finished(self, succeeded):
@staticmethod
def _startup_completed(succeeded):
if succeeded:
GLib.idle_add(self.emit, "briar_startup_completed", (succeeded,))
GLib.idle_add(App().window.on_startup_completed)
return
print("Startup failed")
......@@ -13,10 +13,10 @@ from briar.gtk.toolbar import Toolbar
class Window(Gtk.ApplicationWindow):
DEFAULT_WINDOW_SIZE = (600, 400)
def __init__(self):
Gtk.ApplicationWindow.__init__(self, application=App(),
title=APPLICATION_NAME,
icon_name=APPLICATION_ID)
self._initialize_gtk_application_window()
self._setup_content()
@property
......@@ -27,18 +27,27 @@ class Window(Gtk.ApplicationWindow):
def toolbar(self):
return self._toolbar
def _initialize_gtk_application_window(self):
Gtk.ApplicationWindow.__init__(self, application=App(),
title=APPLICATION_NAME,
icon_name=APPLICATION_ID)
def _setup_content(self):
self._setup_size((600, 400)) # TODO: do properly (constants, save)
self._setup_size(self.DEFAULT_WINDOW_SIZE)
self._setup_toolbar()
self._setup_grid()
self._setup_startup_container()
def _setup_size(self, size):
if len(size) == 2 and\
isinstance(size[0], int) and\
isinstance(size[1], int):
if Window._size_is_valid(size):
self.resize(size[0], size[1])
@staticmethod
def _size_is_valid(size):
return len(size) == 2 and\
isinstance(size[0], int) and\
isinstance(size[1], int)
def _setup_toolbar(self):
self._toolbar = Toolbar()
self._toolbar.show()
......@@ -47,20 +56,15 @@ class Window(Gtk.ApplicationWindow):
def _setup_grid(self):
self._grid = Gtk.Grid()
self._grid.set_orientation(Gtk.Orientation.HORIZONTAL)
self._grid.show()
self.add(self._grid)
def _setup_startup_container(self):
self._container = StartupContainer()
self._container.show()
self._container.connect("briar_startup_completed",
self._on_startup_completed)
self._grid.add(self._container)
# TODO: remove unused arguments
# pylint: disable=unused-argument
def _on_startup_completed(self, inst, obj):
def on_startup_completed(self):
self._grid.destroy()
self._setup_grid()
self._setup_main_container()
......@@ -81,6 +85,7 @@ class Window(Gtk.ApplicationWindow):
self._grid.add(self._container)
self._toolbar.show_back_button(True, self._back_to_main)
# pylint: disable=unused-argument
def _back_to_main(self, widget):
self._grid.destroy()
self._setup_grid()
......
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