diff --git a/src/sakia/core/app.py b/src/sakia/core/app.py index 90afa4158379a908b5c67fb282387fa835ad53e9..b1b922c29d3b762895b6f2690ede0bdca2582cce 100644 --- a/src/sakia/core/app.py +++ b/src/sakia/core/app.py @@ -86,7 +86,7 @@ class Application(QObject): app.get_last_version() if app.preferences["account"] != "": account = app.get_account(app.preferences["account"]) - app.change_current_account(account) + app._current_account = account # no default account... else: # if at least one account exists, set it as default... diff --git a/src/sakia/gui/main_window/controller.py b/src/sakia/gui/main_window/controller.py index a09634f3f9651f512de29d1b3011a38d81af6731..77180d8e5019ae0d6dc92033480f510433ae369d 100644 --- a/src/sakia/gui/main_window/controller.py +++ b/src/sakia/gui/main_window/controller.py @@ -27,13 +27,14 @@ class MainWindowController(AgentController): classdocs """ - def __init__(self, view, model, password_asker, status_bar, toolbar): + def __init__(self, view, model, password_asker, status_bar, toolbar, navigation): """ Init :param MainWindowView view: the ui of the mainwindow agent :param sakia.gui.main_window.model.MainWindowModel: the model of the mainwindow agent - :param sakia.gui.status_bar.controller.StatusBarController: the controller of the status bar agent - :param sakia.gui.toolbar.controller.ToolbarController: the controller of the toolbar agent + :param sakia.gui.status_bar.controller.StatusBarController status_bar: the controller of the status bar agent + :param sakia.gui.toolbar.controller.ToolbarController toolbar: the controller of the toolbar agent + :param sakia.gui.navigation.contoller.NavigationController navigation: the controller of the navigation :param PasswordAsker password_asker: the password asker of the application :type: sakia.core.app.Application @@ -44,6 +45,7 @@ class MainWindowController(AgentController): self.password_asker = password_asker self.status_bar = self.attach(status_bar) self.toolbar = self.attach(toolbar) + self.navigation = self.attach(navigation) QApplication.setWindowIcon(QIcon(":/icons/sakia_logo")) @@ -52,11 +54,13 @@ class MainWindowController(AgentController): view = MainWindowView(None) model = MainWindowModel(None, app) password_asker = PasswordAskerDialog(None) - main_window = cls(view, model, password_asker, None, 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) main_window.toolbar = main_window.attach(ToolbarController.create(main_window, password_asker)) - main_window.toolbar.view.setParent(view.centralwidget) + view.top_layout.addWidget(main_window.toolbar.view) + main_window.navigation = main_window.attach(NavigationController.create(main_window, app)) + view.bottom_layout.addWidget(main_window.navigation.view) #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) diff --git a/src/sakia/gui/main_window/mainwindow.ui b/src/sakia/gui/main_window/mainwindow.ui index 5c334c90944c1df79ce52cad041263aeace39c5e..47a6ed732665c0bcb738dfd657fd4bd7d7572934 100644 --- a/src/sakia/gui/main_window/mainwindow.ui +++ b/src/sakia/gui/main_window/mainwindow.ui @@ -16,11 +16,13 @@ <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout_6"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"/> + <layout class="QHBoxLayout" name="top_layout"/> + </item> + <item> + <layout class="QHBoxLayout" name="bottom_layout"/> </item> </layout> </widget> - <widget class="QStatusBar" name="statusbar"/> <action name="actionManage_accounts"> <property name="text"> <string>Manage accounts</string> diff --git a/src/sakia/gui/main_window/model.py b/src/sakia/gui/main_window/model.py index 32af1551002eed101f94c0f0999ac086ffc1e217..4febb459242150fbd6c27818f71145ac2d4d5eb9 100644 --- a/src/sakia/gui/main_window/model.py +++ b/src/sakia/gui/main_window/model.py @@ -1,5 +1,4 @@ from sakia.gui.agent.model import AgentModel -from sakia.core.money import Referentials class MainWindowModel(AgentModel): @@ -11,5 +10,3 @@ class MainWindowModel(AgentModel): super().__init__(parent) self.app = app - def referentials(self): - return Referentials diff --git a/src/sakia/gui/navigation/controller.py b/src/sakia/gui/navigation/controller.py index 3e94d470e1ea9bbdbe18c0d9fee31734ffdbfcd0..9da1479de45e366444b97383dac75a013e2131f1 100644 --- a/src/sakia/gui/navigation/controller.py +++ b/src/sakia/gui/navigation/controller.py @@ -1,7 +1,7 @@ from PyQt5.QtWidgets import QTreeView from .model import NavigationModel from ..agent.controller import AgentController -from ..agent.model import AgentModel +from .view import NavigationView class NavigationController(AgentController): @@ -9,14 +9,15 @@ class NavigationController(AgentController): The navigation panel """ - def __init__(self, parent, presentation, model): + def __init__(self, parent, view, model): """ Constructor of the navigation agent - :param PyQt5.QtWidgets.QTreeView presentation: the presentation + :param PyQt5.QtWidgets.QTreeView view: the presentation :param sakia.core.gui.navigation.model.NavigationModel model: the model """ - super().__init__(parent, presentation, model) + super().__init__(parent, view, model) + self.view.setModel(model.tree()) @classmethod def create(cls, parent, app): @@ -26,9 +27,9 @@ class NavigationController(AgentController): :return: a new Navigation controller :rtype: NavigationController """ - presentation = QTreeView(parent.presentation) + view = NavigationView(parent.view) model = NavigationModel(None, app) - navigation = cls(presentation, model) + navigation = cls(parent, view, model) model.setParent(navigation) return navigation diff --git a/src/sakia/gui/navigation/model.py b/src/sakia/gui/navigation/model.py index bfe30093d7b51ad1f300470195de005489c2822f..e1c5ab12c963d0b6dc89498eef14dec75e2f8480 100644 --- a/src/sakia/gui/navigation/model.py +++ b/src/sakia/gui/navigation/model.py @@ -1,7 +1,8 @@ -from PyQt5.QtCore import QAbstractItemModel, Qt, QVariant +from ..agent.model import AgentModel +from sakia.models.generic_tree import GenericTreeModel -class NavigationModel(QAbstractItemModel): +class NavigationModel(AgentModel): """ The model of Navigation agent """ @@ -10,66 +11,33 @@ class NavigationModel(QAbstractItemModel): self.app = app def tree(self): - navigation = {'profile': { - 'node': { - 'title': self.account.name + navigation = [{'node': { + 'title': self.app.current_account.name }, - 'children': {} + 'children': [] } - } - for c in self.account.communities: - navigation['profile']['children'].append({ + ] + for c in self.app.current_account.communities: + navigation[0]['children'].append({ 'node': { 'title': c.currency }, - 'children': { - 'transfers': { + 'children': [ + { 'node': { 'title': self.tr('Transfers') } }, - 'network': { + { 'node': { 'title': self.tr('Network') } }, - 'network': { + { 'node': { 'title': self.tr('Network') } } - } + ] }) - - def rowCount(self, parent): - return len(self.nodes_data) - - def columnCount(self, parent): - return len(self.columns_types) - - def headerData(self, section, orientation, role): - if role != Qt.DisplayRole: - return QVariant() - - return self.columns_types[section] - - def data(self, index, role): - row = index.row() - col = index.column() - - if not index.isValid(): - return QVariant() - - node = self.nodes_data[row] - if role == Qt.DisplayRole: - return node[col] - if role == Qt.BackgroundColorRole: - return self.node_colors[node[self.columns_types.index('state')]] - if role == Qt.ToolTipRole: - return self.node_states[node[self.columns_types.index('state')]]() - - return QVariant() - - def flags(self, index): - return Qt.ItemIsSelectable | Qt.ItemIsEnabled - + return GenericTreeModel.create("Navigation", navigation) diff --git a/src/sakia/gui/navigation/view.py b/src/sakia/gui/navigation/view.py new file mode 100644 index 0000000000000000000000000000000000000000..eb1dd54783ecb44007f098ae73695dccbbe8c26f --- /dev/null +++ b/src/sakia/gui/navigation/view.py @@ -0,0 +1,11 @@ +from PyQt5.QtWidgets import QTreeView, QSizePolicy + + +class NavigationView(QTreeView): + """ + The view of navigation panel + """ + + def __init__(self, parent): + super().__init__(parent) + self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) \ No newline at end of file diff --git a/src/sakia/gui/status_bar/controller.py b/src/sakia/gui/status_bar/controller.py index 24c1d7062ddf566a66965f2fb54ed6ac13464206..9cf519ccf500f711e0ab6ec578a029a8765a8643 100644 --- a/src/sakia/gui/status_bar/controller.py +++ b/src/sakia/gui/status_bar/controller.py @@ -64,11 +64,10 @@ class StatusBarController(AgentController): self.view.combo_referential.clear() for ref in self.model.referentials(): self.view.combo_referential.addItem(ref.translated_name()) - logging.debug(self.app.preferences) self.view.combo_referential.setEnabled(True) self.view.combo_referential.blockSignals(False) - self.view.combo_referential.setCurrentIndex(self.app.preferences['ref']) + self.view.combo_referential.setCurrentIndex(self.model.default_referential()) @pyqtSlot(int) def referential_changed(self, index): diff --git a/src/sakia/gui/status_bar/model.py b/src/sakia/gui/status_bar/model.py index b1ef970936ea787d9b1c6adaba2f267880940f30..f3865bbd42afbd356e270af7702d3a9d99f2e79b 100644 --- a/src/sakia/gui/status_bar/model.py +++ b/src/sakia/gui/status_bar/model.py @@ -1,5 +1,6 @@ from sakia.gui.agent.model import AgentModel - +from sakia.core.money import Referentials +import logging class StatusBarModel(AgentModel): """ @@ -9,3 +10,10 @@ class StatusBarModel(AgentModel): def __init__(self, parent, app): super().__init__(parent) self.app = app + + def referentials(self): + return Referentials + + def default_referential(self): + logging.debug(self.app.preferences) + return self.app.preferences['ref'] \ No newline at end of file diff --git a/src/sakia/gui/toolbar/view.py b/src/sakia/gui/toolbar/view.py index 976559ec11df71866e001c49c2ea261f776c6c2d..df1dfd1f487deb17d957c8b55465bee7154e8f0b 100644 --- a/src/sakia/gui/toolbar/view.py +++ b/src/sakia/gui/toolbar/view.py @@ -1,4 +1,4 @@ -from PyQt5.QtWidgets import QFrame, QAction, QMenu, QDialog, QMessageBox +from PyQt5.QtWidgets import QFrame, QAction, QMenu, QSizePolicy, QMessageBox from PyQt5.QtGui import QIcon from PyQt5.QtCore import QObject, QT_TRANSLATE_NOOP, Qt from .toolbar_uic import Ui_SakiaToolbar @@ -42,4 +42,6 @@ class ToolbarView(QFrame, Ui_SakiaToolbar): menu_advanced.addAction(self.action_gen_revokation) tool_menu.addMenu(menu_advanced) tool_menu.addAction(self.action_publish_uid) + self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Minimum) + self.setMaximumHeight(60)