diff --git a/res/ui/mainwindow.ui b/res/ui/mainwindow.ui index 6d97872b2c0f6bce6f167d4a5cd2427f710555c7..86165ad429ff846a126108fc7e36b3ba97221ef3 100644 --- a/res/ui/mainwindow.ui +++ b/res/ui/mainwindow.ui @@ -66,8 +66,15 @@ </property> <addaction name="actionAbout"/> </widget> + <widget class="QMenu" name="menuDuniter"> + <property name="title"> + <string>Dunit&er</string> + </property> + <addaction name="actionManage_local_node"/> + </widget> <addaction name="menu_file"/> <addaction name="menu_account"/> + <addaction name="menuDuniter"/> <addaction name="menu_help"/> </widget> <widget class="QStatusBar" name="statusbar"/> @@ -176,6 +183,11 @@ <string>&Add account</string> </property> </action> + <action name="actionManage_local_node"> + <property name="text"> + <string>Manage local node</string> + </property> + </action> </widget> <resources> <include location="../icons/icons.qrc"/> diff --git a/res/ui/node_manager.ui b/res/ui/node_manager.ui new file mode 100644 index 0000000000000000000000000000000000000000..e4f1b7e4a70a8a35de3e306ceef21ef19598723c --- /dev/null +++ b/res/ui/node_manager.ui @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>NodeManager</class> + <widget class="QDialog" name="NodeManager"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1024</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>Node manager</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QWebView" name="web_view"> + <property name="url"> + <url> + <string>about:blank</string> + </url> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>QWebView</class> + <extends>QWidget</extends> + <header>QtWebKitWidgets/QWebView</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/src/sakia/gui/mainwindow.py b/src/sakia/gui/mainwindow.py index 342191e7ecffad23515dfe57094df6aa6429a0ba..9fa92233e6fb2200d9162d50d1c3f86f1b77d566 100644 --- a/src/sakia/gui/mainwindow.py +++ b/src/sakia/gui/mainwindow.py @@ -3,12 +3,12 @@ Created on 1 févr. 2014 @author: inso """ -import asyncio +import aiohttp import logging from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, QMessageBox, QLabel, QComboBox, QDialog, QApplication from PyQt5.QtCore import QLocale, QEvent, \ - pyqtSlot, QDateTime, QTimer, Qt, QObject + pyqtSlot, QDateTime, QTimer, Qt, QObject, QUrl from PyQt5.QtGui import QIcon from ..gen_resources.mainwindow_uic import Ui_MainWindow @@ -23,6 +23,7 @@ from .password_asker import PasswordAskerDialog from .preferences import PreferencesDialog from .process_cfg_community import ProcessConfigureCommunity from .homescreen import HomeScreenWidget +from .node_manager import NodeManager from ..core import money from ..core.community import Community from ..tools.decorators import asyncify @@ -35,7 +36,8 @@ class MainWindow(QObject): classdocs """ - def __init__(self, app, account, homescreen, community_view, widget, ui, + def __init__(self, app, account, homescreen, community_view, node_manager, + widget, ui, label_icon, label_status, label_time, combo_referential, password_asker): """ @@ -44,6 +46,7 @@ class MainWindow(QObject): :param sakia.core.Account account: the account :param HomeScreenWidgetcreen homescreen: the homescreen :param CommunityView community_view: the community view + :param NodeManager node_manager: the local node manager dialog :param QMainWindow widget: the widget of the main window :param Ui_MainWindow ui: the ui of the widget :param QLabel label_icon: the label of the icon in the statusbar @@ -82,6 +85,9 @@ class MainWindow(QObject): self.community_view = community_view + self.node_manager = node_manager + + def _init_ui(self): """ Connects elements of the UI to the local slots @@ -102,6 +108,8 @@ class MainWindow(QObject): self.ui.actionPreferences.triggered.connect(self.open_preferences_dialog) self.ui.actionAbout.triggered.connect(self.open_about_popup) + self.ui.actionManage_local_node.triggered.connect(self.open_duniter_ui) + def _init_homescreen(self): """ Initialize homescreen signals/slots and data @@ -132,8 +140,10 @@ class MainWindow(QObject): @classmethod def startup(cls, app): qmainwindow = QMainWindow() + main_window = cls(app, None, HomeScreenWidget(app, None), CommunityWidget(app, None, None), + NodeManager.create(qmainwindow), qmainwindow, Ui_MainWindow(), QLabel("", qmainwindow), QLabel("", qmainwindow), QLabel("", qmainwindow), QComboBox(qmainwindow), @@ -347,6 +357,11 @@ class MainWindow(QObject): delete_action.setData(contact) delete_action.triggered.connect(self.delete_contact) + @asyncify + async def open_duniter_ui(self, checked=False): + if not self.node_manager.widget.isVisible(): + self.node_manager.open_home_page() + def refresh(self): """ Refresh main window diff --git a/src/sakia/gui/node_manager.py b/src/sakia/gui/node_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..f962d682faff562e0770f83382f77c6c7151160c --- /dev/null +++ b/src/sakia/gui/node_manager.py @@ -0,0 +1,57 @@ +import aiohttp + +from PyQt5.QtCore import QObject, QEvent, QUrl +from PyQt5.QtWidgets import QDialog + +from ..gen_resources.node_manager_uic import Ui_NodeManager +from .widgets.dialogs import QAsyncMessageBox +from ..tools.decorators import asyncify + + +class NodeManager(QObject): + """ + A widget showing informations about a member + """ + + def __init__(self, widget, ui): + """ + Init MemberDialog + + :param PyQt5.QtWidget widget: The class of the widget + :param sakia.gen_resources.member_uic.Ui_DialogMember ui: the class of the ui applyed to the widget + :return: + """ + super().__init__() + self.widget = widget + self.ui = ui + self.ui.setupUi(self.widget) + self.widget.installEventFilter(self) + + @classmethod + def create(cls, parent): + dialog = cls(QDialog(parent), Ui_NodeManager()) + return dialog + + @asyncify + async def open_home_page(self): + try: + with aiohttp.ClientSession() as session: + response = await session.get("http://127.0.0.1:9220") + if response.status == 200: + self.ui.web_view.load(QUrl("http://127.0.0.1:9220")) + self.ui.web_view.show() + self.widget.show() + else: + await QAsyncMessageBox.critical(self.widget, "Local node manager", + "Could not access to local node ui.") + except aiohttp.ClientError: + await QAsyncMessageBox.critical(self.widget, "Local node manager", + "Could not connect to node. Please make sure it's running.") + + def eventFilter(self, source, event): + if event.type() == QEvent.Resize: + self.widget.resizeEvent(event) + return self.widget.eventFilter(source, event) + + def exec(self): + self.widget.exec()