diff --git a/src/sakia/gui/component/controller.py b/src/sakia/gui/component/controller.py index 019c47cf2063a215cbb8f0c89e79eba9cfe0cf75..2a070404674937fb42048d0ac2cd4f1fda79989c 100644 --- a/src/sakia/gui/component/controller.py +++ b/src/sakia/gui/component/controller.py @@ -25,7 +25,6 @@ class ComponentController(QObject): def model(self): raise NotImplementedError("Model property not implemented") - @classmethod def create(cls, parent, app, **kwargs): raise NotImplementedError("Create method not implemented") @@ -39,6 +38,7 @@ class ComponentController(QObject): """ if controller: controller.setParent(self) + #controller.view.setParent(self.view) return controller else: return None diff --git a/src/sakia/gui/contact.py b/src/sakia/gui/contact.py index 0cac15ad5b289543e4e0265b1cf23d7eca2af600..8d3036b91222e6f993f91173a9294fdad1bc6a0b 100644 --- a/src/sakia/gui/contact.py +++ b/src/sakia/gui/contact.py @@ -9,7 +9,7 @@ import logging from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox from ..core.registry import IdentitiesRegistry from ..tools.exceptions import ContactAlreadyExists -from ..presentation.contact_uic import Ui_ConfigureContactDialog +from ..gen_resources.contact_uic import Ui_ConfigureContactDialog class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog): diff --git a/src/sakia/gui/dialogs/account_cfg/controller.py b/src/sakia/gui/dialogs/account_cfg/controller.py index 0083b7c618624bb0a006b2d72558b4114fcb2ca0..f55b55739268c2a5c9def2b2e9864410addadc0d 100644 --- a/src/sakia/gui/dialogs/account_cfg/controller.py +++ b/src/sakia/gui/dialogs/account_cfg/controller.py @@ -8,6 +8,7 @@ from .model import AccountConfigModel from sakia.tools.decorators import asyncify import logging +import asyncio class AccountConfigController(ComponentController): @@ -59,13 +60,14 @@ class AccountConfigController(ComponentController): :return: a new AccountConfigController controller :rtype: AccountConfigController """ - view = AccountConfigView(parent.view) + view = AccountConfigView(parent.view if parent else None) model = AccountConfigModel(None, app, None) account_cfg = cls(parent, view, model) model.setParent(account_cfg) return account_cfg @classmethod + @asyncify def create_account(cls, parent, app): """ Open a dialog to create a new account @@ -168,10 +170,10 @@ class AccountConfigController(ComponentController): self.view.set_communities_list_model(list_model) def handle_next_step(self, init=False): - if self._current_step < len(self._steps) - 1: - if not init: - self._steps[self._current_step]['next']() - self._current_step += 1 + if not init: + self._steps[self._current_step]['next']() + self._current_step += 1 + if self._current_step < len(self._steps): self._steps[self._current_step]['init']() self.view.stacked_pages.setCurrentWidget(self._steps[self._current_step]['page']) @@ -184,13 +186,21 @@ class AccountConfigController(ComponentController): account=self.model.account, password_asker=self.password_asker) - - def accept(self): + @asyncify + async def accept(self): + await self.password_asker.async_exec() if self.password_asker.result() == QDialog.Rejected: return self.model.add_account_to_app() self.view.accept() + def async_exec(self): + future = asyncio.Future() + self.view.finished.connect(lambda r: future.set_result(r)) + self.view.open() + self.refresh() + return future + @property def view(self) -> AccountConfigView: return self._view diff --git a/src/sakia/gui/main_window/controller.py b/src/sakia/gui/main_window/controller.py index e9b250c9d4ae43044940cfd14e53e21626892ae3..a01fccb1c17c61bcc403aad3295151099d8f4779 100644 --- a/src/sakia/gui/main_window/controller.py +++ b/src/sakia/gui/main_window/controller.py @@ -47,34 +47,52 @@ class MainWindowController(ComponentController): self.toolbar = self.attach(toolbar) self.navigation = self.attach(navigation) self.stacked_widgets = {} + self.navigation.community_changed.connect(self.handle_community_change) + self.navigation.account_changed.connect(self.handle_account_change) + self.view.bottom_layout.insertWidget(0, self.navigation.view) + self.view.top_layout.addWidget(self.toolbar.view) + self.view.setStatusBar(self.status_bar.view) QApplication.setWindowIcon(QIcon(":/icons/sakia_logo")) @classmethod - def startup(cls, app): - view = MainWindowView(None) - model = MainWindowModel(None, app) - password_asker = PasswordAskerDialog(None) - main_window = cls(view, model, password_asker, None, None, None) - - main_window.status_bar = main_window.attach(StatusBarController.create(main_window, app)) - view.setStatusBar(main_window.status_bar._view) + def create(cls, parent, app, **kwargs): + """ + Instanciate a navigation component + :param sakia.gui.status_bar.controller.StatusBarController status_bar: the controller of the status bar component + :param sakia.gui.toolbar.controller.ToolbarController toolbar: the controller of the toolbar component + :param sakia.gui.navigation.contoller.NavigationController navigation: the controller of the navigation - main_window.navigation = main_window.attach(NavigationController.create(main_window, app)) - view.bottom_layout.insertWidget(0, main_window.navigation._view) - main_window.navigation.community_changed.connect(main_window.handle_community_change) - main_window.navigation.account_changed.connect(main_window.handle_account_change) + :return: a new Navigation controller + :rtype: MainWindowController + """ + password_asker = kwargs['password_asker'] + status_bar = kwargs['status_bar'] + toolbar = kwargs['toolbar'] + navigation = kwargs['navigation'] + view = MainWindowView() + model = MainWindowModel(None, app) + main_window = cls(view, model, password_asker, status_bar, toolbar, navigation) + model.setParent(main_window) + main_window.navigation.init_navigation() + return main_window - main_window.toolbar = main_window.attach(ToolbarController.create(main_window, app, - app.current_account, None, - password_asker)) - view.top_layout.addWidget(main_window.toolbar._view) + @classmethod + def startup(cls, app): + password_asker = PasswordAskerDialog(None) + main_window = cls.create(None, app, password_asker=password_asker, + status_bar=StatusBarController.create(None, app), + navigation=NavigationController.create(None, app), + toolbar=ToolbarController.create(None, app, + app.current_account, None, + password_asker) + ) #app.version_requested.connect(main_window.latest_version_requested) #app.account_imported.connect(main_window.import_account_accepted) #app.account_changed.connect(main_window.change_account) - view.showMaximized() + main_window.view.showMaximized() main_window.refresh() return main_window diff --git a/src/sakia/gui/main_window/status_bar/controller.py b/src/sakia/gui/main_window/status_bar/controller.py index c5351ba493f10447d5b4f555ef3d7d19341fceb8..bcf2cd1cda0f2ce69df8d14de9fe2443c41b8273 100644 --- a/src/sakia/gui/main_window/status_bar/controller.py +++ b/src/sakia/gui/main_window/status_bar/controller.py @@ -22,14 +22,14 @@ class StatusBarController(ComponentController): self.update_time() @classmethod - def create(cls, parent, app): + def create(cls, parent, app, **kwargs): """ Instanciate a navigation component :param sakia.gui.main_window.controller.MainWindowController parent: :return: a new Navigation controller :rtype: NavigationController """ - view = StatusBarView(parent._view) + view = StatusBarView(None) model = StatusBarModel(None, app) status_bar = cls(parent, view, model) diff --git a/src/sakia/gui/main_window/toolbar/controller.py b/src/sakia/gui/main_window/toolbar/controller.py index 81a0f6490305abe196016ea6ece2cc698112aae1..b4d7c069d1d3846b8626a761affff7e0e27ee463 100644 --- a/src/sakia/gui/main_window/toolbar/controller.py +++ b/src/sakia/gui/main_window/toolbar/controller.py @@ -41,7 +41,7 @@ class ToolbarController(ComponentController): :return: a new Toolbar controller :rtype: ToolbarController """ - view = ToolbarView(parent.view) + view = ToolbarView(None) model = ToolbarModel(None, app, account, community) toolbar = cls(parent, view, model, password_asker) model.setParent(toolbar) diff --git a/src/sakia/gui/main_window/view.py b/src/sakia/gui/main_window/view.py index 2cd838a2ef6982eaa3995d8ea2cbdc2ada0b9446..9ab91913cc567e64504f5d1ca07f2064f3ffaddf 100644 --- a/src/sakia/gui/main_window/view.py +++ b/src/sakia/gui/main_window/view.py @@ -7,6 +7,6 @@ class MainWindowView(QMainWindow, Ui_MainWindow): The model of Navigation component """ - def __init__(self, parent): - super().__init__(parent) + def __init__(self): + super().__init__(None) self.setupUi(self) diff --git a/src/sakia/gui/navigation/controller.py b/src/sakia/gui/navigation/controller.py index 3d3b4aca7677a8bdf9e6ed3ea7706ba82137f0cd..e50487e6e6b31a24ec8f418c3fa43ef19e184658 100644 --- a/src/sakia/gui/navigation/controller.py +++ b/src/sakia/gui/navigation/controller.py @@ -46,7 +46,7 @@ class NavigationController(ComponentController): :return: a new Navigation controller :rtype: NavigationController """ - view = NavigationView(parent.view) + view = NavigationView(None) model = NavigationModel(None, app) navigation = cls(parent, view, model) model.setParent(navigation) diff --git a/src/sakia/gui/password_asker.py b/src/sakia/gui/password_asker.py index ecb926688e3f22bd70acf152ff3a0de6895c9ccc..be1b97c3a64a2e4e09ff76e638f8797f94aeb707 100644 --- a/src/sakia/gui/password_asker.py +++ b/src/sakia/gui/password_asker.py @@ -10,7 +10,7 @@ import asyncio from PyQt5.QtCore import QEvent from PyQt5.QtWidgets import QDialog, QMessageBox -from ..presentation.password_asker_uic import Ui_PasswordAskerDialog +from ..gen_resources.password_asker_uic import Ui_PasswordAskerDialog class PasswordAskerDialog(QDialog, Ui_PasswordAskerDialog): diff --git a/src/sakia/gui/widgets/toast.py b/src/sakia/gui/widgets/toast.py index 2e1aa124b01cc0a594796c1616441006a72a4ba7..fd50cf8f8edcb900778f0b2f87c776ba1d4cad78 100644 --- a/src/sakia/gui/widgets/toast.py +++ b/src/sakia/gui/widgets/toast.py @@ -8,7 +8,7 @@ import logging from PyQt5.QtCore import Qt, QThread from PyQt5.QtWidgets import QMainWindow, QApplication from PyQt5.QtGui import QImage, QPixmap -from ...presentation.toast_uic import Ui_Toast +from ...gen_resources.toast_uic import Ui_Toast window = None # global diff --git a/src/sakia/main.py b/src/sakia/main.py index 5e1c15803b334721788b770bd65fb2bd59b78f38..89a7871ebf73c5edc4b285d208b3cf82cae2d66e 100755 --- a/src/sakia/main.py +++ b/src/sakia/main.py @@ -21,6 +21,7 @@ from quamash import QSelectorEventLoop from PyQt5.QtWidgets import QApplication, QMessageBox from PyQt5.QtCore import Qt from sakia.gui.main_window.controller import MainWindowController +from sakia.gui.dialogs.account_cfg.controller import AccountConfigController from sakia.core.app import Application @@ -97,6 +98,8 @@ if __name__ == '__main__': with loop: app = Application.startup(sys.argv, sakia, loop) + if not app.current_account: + account_cfg = loop.run_until_complete(AccountConfigController.create_account(None, app)) window = MainWindowController.startup(app) loop.run_forever() try: @@ -107,5 +110,4 @@ if __name__ == '__main__': logging.info('CancelledError') logging.debug("Exiting") sys.exit() - logging.debug("Application stopped")