Skip to content
Snippets Groups Projects
Commit 5454789c authored by inso's avatar inso
Browse files

Show create account controller before the window

parent 8d1e26a1
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,6 @@ class ComponentController(QObject): ...@@ -25,7 +25,6 @@ class ComponentController(QObject):
def model(self): def model(self):
raise NotImplementedError("Model property not implemented") raise NotImplementedError("Model property not implemented")
@classmethod @classmethod
def create(cls, parent, app, **kwargs): def create(cls, parent, app, **kwargs):
raise NotImplementedError("Create method not implemented") raise NotImplementedError("Create method not implemented")
...@@ -39,6 +38,7 @@ class ComponentController(QObject): ...@@ -39,6 +38,7 @@ class ComponentController(QObject):
""" """
if controller: if controller:
controller.setParent(self) controller.setParent(self)
#controller.view.setParent(self.view)
return controller return controller
else: else:
return None return None
...@@ -9,7 +9,7 @@ import logging ...@@ -9,7 +9,7 @@ import logging
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QMessageBox
from ..core.registry import IdentitiesRegistry from ..core.registry import IdentitiesRegistry
from ..tools.exceptions import ContactAlreadyExists 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): class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog):
......
...@@ -8,6 +8,7 @@ from .model import AccountConfigModel ...@@ -8,6 +8,7 @@ from .model import AccountConfigModel
from sakia.tools.decorators import asyncify from sakia.tools.decorators import asyncify
import logging import logging
import asyncio
class AccountConfigController(ComponentController): class AccountConfigController(ComponentController):
...@@ -59,13 +60,14 @@ class AccountConfigController(ComponentController): ...@@ -59,13 +60,14 @@ class AccountConfigController(ComponentController):
:return: a new AccountConfigController controller :return: a new AccountConfigController controller
:rtype: AccountConfigController :rtype: AccountConfigController
""" """
view = AccountConfigView(parent.view) view = AccountConfigView(parent.view if parent else None)
model = AccountConfigModel(None, app, None) model = AccountConfigModel(None, app, None)
account_cfg = cls(parent, view, model) account_cfg = cls(parent, view, model)
model.setParent(account_cfg) model.setParent(account_cfg)
return account_cfg return account_cfg
@classmethod @classmethod
@asyncify
def create_account(cls, parent, app): def create_account(cls, parent, app):
""" """
Open a dialog to create a new account Open a dialog to create a new account
...@@ -168,10 +170,10 @@ class AccountConfigController(ComponentController): ...@@ -168,10 +170,10 @@ class AccountConfigController(ComponentController):
self.view.set_communities_list_model(list_model) self.view.set_communities_list_model(list_model)
def handle_next_step(self, init=False): def handle_next_step(self, init=False):
if self._current_step < len(self._steps) - 1:
if not init: if not init:
self._steps[self._current_step]['next']() self._steps[self._current_step]['next']()
self._current_step += 1 self._current_step += 1
if self._current_step < len(self._steps):
self._steps[self._current_step]['init']() self._steps[self._current_step]['init']()
self.view.stacked_pages.setCurrentWidget(self._steps[self._current_step]['page']) self.view.stacked_pages.setCurrentWidget(self._steps[self._current_step]['page'])
...@@ -184,13 +186,21 @@ class AccountConfigController(ComponentController): ...@@ -184,13 +186,21 @@ class AccountConfigController(ComponentController):
account=self.model.account, account=self.model.account,
password_asker=self.password_asker) password_asker=self.password_asker)
@asyncify
def accept(self): async def accept(self):
await self.password_asker.async_exec()
if self.password_asker.result() == QDialog.Rejected: if self.password_asker.result() == QDialog.Rejected:
return return
self.model.add_account_to_app() self.model.add_account_to_app()
self.view.accept() 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 @property
def view(self) -> AccountConfigView: def view(self) -> AccountConfigView:
return self._view return self._view
......
...@@ -47,34 +47,52 @@ class MainWindowController(ComponentController): ...@@ -47,34 +47,52 @@ class MainWindowController(ComponentController):
self.toolbar = self.attach(toolbar) self.toolbar = self.attach(toolbar)
self.navigation = self.attach(navigation) self.navigation = self.attach(navigation)
self.stacked_widgets = {} 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")) QApplication.setWindowIcon(QIcon(":/icons/sakia_logo"))
@classmethod @classmethod
def startup(cls, app): def create(cls, parent, app, **kwargs):
view = MainWindowView(None) """
model = MainWindowModel(None, app) Instanciate a navigation component
password_asker = PasswordAskerDialog(None) :param sakia.gui.status_bar.controller.StatusBarController status_bar: the controller of the status bar component
main_window = cls(view, model, password_asker, None, None, None) :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.status_bar = main_window.attach(StatusBarController.create(main_window, app))
view.setStatusBar(main_window.status_bar._view)
main_window.navigation = main_window.attach(NavigationController.create(main_window, app)) :return: a new Navigation controller
view.bottom_layout.insertWidget(0, main_window.navigation._view) :rtype: MainWindowController
main_window.navigation.community_changed.connect(main_window.handle_community_change) """
main_window.navigation.account_changed.connect(main_window.handle_account_change) 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, @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, app.current_account, None,
password_asker)) password_asker)
view.top_layout.addWidget(main_window.toolbar._view) )
#app.version_requested.connect(main_window.latest_version_requested) #app.version_requested.connect(main_window.latest_version_requested)
#app.account_imported.connect(main_window.import_account_accepted) #app.account_imported.connect(main_window.import_account_accepted)
#app.account_changed.connect(main_window.change_account) #app.account_changed.connect(main_window.change_account)
view.showMaximized() main_window.view.showMaximized()
main_window.refresh() main_window.refresh()
return main_window return main_window
......
...@@ -22,14 +22,14 @@ class StatusBarController(ComponentController): ...@@ -22,14 +22,14 @@ class StatusBarController(ComponentController):
self.update_time() self.update_time()
@classmethod @classmethod
def create(cls, parent, app): def create(cls, parent, app, **kwargs):
""" """
Instanciate a navigation component Instanciate a navigation component
:param sakia.gui.main_window.controller.MainWindowController parent: :param sakia.gui.main_window.controller.MainWindowController parent:
:return: a new Navigation controller :return: a new Navigation controller
:rtype: NavigationController :rtype: NavigationController
""" """
view = StatusBarView(parent._view) view = StatusBarView(None)
model = StatusBarModel(None, app) model = StatusBarModel(None, app)
status_bar = cls(parent, view, model) status_bar = cls(parent, view, model)
......
...@@ -41,7 +41,7 @@ class ToolbarController(ComponentController): ...@@ -41,7 +41,7 @@ class ToolbarController(ComponentController):
:return: a new Toolbar controller :return: a new Toolbar controller
:rtype: ToolbarController :rtype: ToolbarController
""" """
view = ToolbarView(parent.view) view = ToolbarView(None)
model = ToolbarModel(None, app, account, community) model = ToolbarModel(None, app, account, community)
toolbar = cls(parent, view, model, password_asker) toolbar = cls(parent, view, model, password_asker)
model.setParent(toolbar) model.setParent(toolbar)
......
...@@ -7,6 +7,6 @@ class MainWindowView(QMainWindow, Ui_MainWindow): ...@@ -7,6 +7,6 @@ class MainWindowView(QMainWindow, Ui_MainWindow):
The model of Navigation component The model of Navigation component
""" """
def __init__(self, parent): def __init__(self):
super().__init__(parent) super().__init__(None)
self.setupUi(self) self.setupUi(self)
...@@ -46,7 +46,7 @@ class NavigationController(ComponentController): ...@@ -46,7 +46,7 @@ class NavigationController(ComponentController):
:return: a new Navigation controller :return: a new Navigation controller
:rtype: NavigationController :rtype: NavigationController
""" """
view = NavigationView(parent.view) view = NavigationView(None)
model = NavigationModel(None, app) model = NavigationModel(None, app)
navigation = cls(parent, view, model) navigation = cls(parent, view, model)
model.setParent(navigation) model.setParent(navigation)
......
...@@ -10,7 +10,7 @@ import asyncio ...@@ -10,7 +10,7 @@ import asyncio
from PyQt5.QtCore import QEvent from PyQt5.QtCore import QEvent
from PyQt5.QtWidgets import QDialog, QMessageBox 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): class PasswordAskerDialog(QDialog, Ui_PasswordAskerDialog):
......
...@@ -8,7 +8,7 @@ import logging ...@@ -8,7 +8,7 @@ import logging
from PyQt5.QtCore import Qt, QThread from PyQt5.QtCore import Qt, QThread
from PyQt5.QtWidgets import QMainWindow, QApplication from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QImage, QPixmap from PyQt5.QtGui import QImage, QPixmap
from ...presentation.toast_uic import Ui_Toast from ...gen_resources.toast_uic import Ui_Toast
window = None # global window = None # global
......
...@@ -21,6 +21,7 @@ from quamash import QSelectorEventLoop ...@@ -21,6 +21,7 @@ from quamash import QSelectorEventLoop
from PyQt5.QtWidgets import QApplication, QMessageBox from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from sakia.gui.main_window.controller import MainWindowController from sakia.gui.main_window.controller import MainWindowController
from sakia.gui.dialogs.account_cfg.controller import AccountConfigController
from sakia.core.app import Application from sakia.core.app import Application
...@@ -97,6 +98,8 @@ if __name__ == '__main__': ...@@ -97,6 +98,8 @@ if __name__ == '__main__':
with loop: with loop:
app = Application.startup(sys.argv, sakia, 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) window = MainWindowController.startup(app)
loop.run_forever() loop.run_forever()
try: try:
...@@ -107,5 +110,4 @@ if __name__ == '__main__': ...@@ -107,5 +110,4 @@ if __name__ == '__main__':
logging.info('CancelledError') logging.info('CancelledError')
logging.debug("Exiting") logging.debug("Exiting")
sys.exit() sys.exit()
logging.debug("Application stopped")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment