diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index ca133cad83e7a0a1736e0e32c831def629b6b073..01b8d1aba4a6cef0fb9c4a047ec10f4fdd938522 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -7,7 +7,7 @@ from PyQt5.QtWidgets import QDialog, QMessageBox, QDialogButtonBox, QApplication from PyQt5.QtCore import Qt, pyqtSlot from ..gen_resources.certification_uic import Ui_CertificationDialog from . import toast -from ..core.net.api import bma as bma +from .dialogs import QAsyncMessageBox from ..tools.decorators import asyncify import asyncio import logging @@ -61,12 +61,18 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): result = yield from self.account.certify(password, self.community, pubkey) if result[0]: if self.app.preferences['notifications']: - toast.display(self.tr("Success"), self.tr("Success sending certification")) + toast.display(self.tr("Certification"), self.tr("Success sending certification")) + else: + yield from QAsyncMessageBox.information(self, self.tr("Certification"), + self.tr("Success sending certification")) QApplication.restoreOverrideCursor() super().accept() else: if self.app.preferences['notifications']: - toast.display(self.tr("Error broadcasting"), self.tr("Could not broadcast certification")) + toast.display(self.tr("Certification"), self.tr("Could not broadcast certification")) + else: + yield from QAsyncMessageBox.critical(self, self.tr("Certification"), + self.tr("Could not broadcast certification")) QApplication.restoreOverrideCursor() def change_current_community(self, index): diff --git a/src/cutecoin/gui/community_view.py b/src/cutecoin/gui/community_view.py index 582768cea4e94b8b38a904e41727b3d34ce6fa7f..3c1ebe8ef12bbfddb9c8b10b551d4f75c59a5500 100644 --- a/src/cutecoin/gui/community_view.py +++ b/src/cutecoin/gui/community_view.py @@ -7,7 +7,7 @@ Created on 2 févr. 2014 import time import logging from PyQt5.QtWidgets import QWidget, QMessageBox, QDialog -from PyQt5.QtCore import QModelIndex, pyqtSlot, QDateTime, QLocale, QEvent +from PyQt5.QtCore import pyqtSlot, QDateTime, QLocale, QEvent from PyQt5.QtGui import QIcon from ..core.net.api import bma as bma @@ -15,6 +15,7 @@ from .wot_tab import WotTabWidget from .identities_tab import IdentitiesTabWidget from .transactions_tab import TransactionsTabWidget from .network_tab import NetworkTabWidget +from .dialogs import QAsyncMessageBox from . import toast import asyncio from ..tools.exceptions import MembershipNotFoundError, LookupFailureError, NoPeerAvailable @@ -255,12 +256,20 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): if result[0]: if self.app.preferences['notifications']: toast.display(self.tr("Membership"), self.tr("Success sending Membership demand")) + else: + yield from QAsyncMessageBox.information(self, self.tr("Membership"), + self.tr("Success sending Membership demand")) else: if self.app.preferences['notifications']: toast.display(self.tr("Membership"), result[1]) + else: + yield from QAsyncMessageBox.critical(self, self.tr("Membership"), + result[1]) + @asyncify + @asyncio.coroutine def send_membership_leaving(self): - reply = QMessageBox.warning(self, self.tr("Warning"), + reply = yield from QAsyncMessageBox.warning(self, self.tr("Warning"), self.tr("""Are you sure ? Sending a leaving demand cannot be canceled. The process to join back the community later will have to be done again.""") @@ -269,64 +278,19 @@ The process to join back the community later will have to be done again.""") password = self.password_asker.exec_() if self.password_asker.result() == QDialog.Rejected: return - - asyncio.async(self.account.send_membership(password, self.community, 'OUT')) - - def publish_uid(self): - reply = QMessageBox.warning(self, self.tr("Warning"), - self.tr("""Are you sure ? -Publishing your UID can be canceled by Revoke UID.""") -.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) - if reply == QMessageBox.Ok: - password = self.password_asker.exec_() - if self.password_asker.result() == QDialog.Rejected: - return - - try: - self.account.send_selfcert(password, self.community) - toast.display(self.tr("UID Publishing"), - self.tr("Success publishing your UID")) - except ValueError as e: - QMessageBox.critical(self, self.tr("Publish UID error"), - str(e)) - except NoPeerAvailable as e: - QMessageBox.critical(self, self.tr("Network error"), - self.tr("Couldn't connect to network : {0}").format(e), - QMessageBox.Ok) - except Exception as e: - QMessageBox.critical(self, self.tr("Error"), - "{0}".format(e), - QMessageBox.Ok) - - def revoke_uid(self): - reply = QMessageBox.warning(self, self.tr("Warning"), - self.tr("""Are you sure ? -Revoking your UID can only success if it is not already validated by the network.""") -.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel) - if reply == QMessageBox.Ok: - password = self.password_asker.exec_() - if self.password_asker.result() == QDialog.Rejected: - return - - asyncio.async(self.account.revoke(password, self.community)) - - def handle_revoke_broadcasted(self): - if self.app.preferences['notifications']: - toast.display(self.tr("Revoke"), self.tr("Success sending Revoke demand")) - else: - QMessageBox.information(self, self.tr("Revoke"), self.tr("Success sending Revoke demand")) - - def handle_selfcert_broadcasted(self): - if self.app.preferences['notifications']: - toast.display(self.tr("Self Certification"), self.tr("Success sending Self Certification document")) - else: - QMessageBox.information(self.tr("Self Certification"), self.tr("Success sending Self Certification document")) - - def handle_broadcast_error(self, error, strdata): - if self.app.preferences['notifications']: - toast.display(error, strdata) - else: - QMessageBox.error(error, strdata) + result = yield from self.account.send_membership(password, self.community, 'OUT') + if result[0]: + if self.app.preferences['notifications']: + toast.display(self.tr("Revoke"), self.tr("Success sending Revoke demand")) + else: + yield from QAsyncMessageBox.information(self, self.tr("Revoke"), + self.tr("Success sending Revoke demand")) + else: + if self.app.preferences['notifications']: + toast.display(self.tr("Revoke"), result[1]) + else: + yield from QAsyncMessageBox.critical(self, self.tr("Revoke"), + result[1]) def showEvent(self, QShowEvent): """ diff --git a/src/cutecoin/gui/dialogs.py b/src/cutecoin/gui/dialogs.py new file mode 100644 index 0000000000000000000000000000000000000000..8ddf4188451fc70e1f6f7d3e446c7d3d9367fc7b --- /dev/null +++ b/src/cutecoin/gui/dialogs.py @@ -0,0 +1,31 @@ +from PyQt5.QtWidgets import QMessageBox as QMessageBox +import asyncio + + +def dialog_async_exec(dialog): + future = asyncio.Future() + dialog.finished.connect(lambda r: future.set_result(r)) + dialog.open() + return future + + +class QAsyncMessageBox: + @staticmethod + def critical(parent, title, label, buttons=QMessageBox.Ok): + dialog = QMessageBox(QMessageBox.Critical, title, label, buttons, parent) + return dialog_async_exec(dialog) + + @staticmethod + def information(parent, title, label, buttons=QMessageBox.Ok): + dialog = QMessageBox(QMessageBox.Information, title, label, buttons, parent) + return dialog_async_exec(dialog) + + @staticmethod + def warning(parent, title, label, buttons=QMessageBox.Ok): + dialog = QMessageBox(QMessageBox.Warning, title, label, buttons, parent) + return dialog_async_exec(dialog) + + @staticmethod + def question(parent, title, label, buttons=QMessageBox.Yes|QMessageBox.No): + dialog = QMessageBox(QMessageBox.Question, title, label, buttons, parent) + return dialog_async_exec(dialog) diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index e2b8bb7c0ad4da746c18256c6edcb5226f13ba53..2bdff3c3e05c017395b624181518ab730fd2f5a4 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -3,12 +3,13 @@ Created on 2 févr. 2014 @author: inso """ -from PyQt5.QtWidgets import QDialog, QMessageBox, QApplication +from PyQt5.QtWidgets import QDialog, QApplication from PyQt5.QtCore import QRegExp, Qt, QLocale, pyqtSlot from PyQt5.QtGui import QRegExpValidator from ..gen_resources.transfer_uic import Ui_TransferMoneyDialog from . import toast +from .dialogs import QAsyncMessageBox, QMessageBox from ..tools.decorators import asyncify import asyncio @@ -78,12 +79,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): amount = self.spinbox_amount.value() if not amount: - return - """ - QMessageBox.critical(self, self.tr("Money transfer"), + yield from QAsyncMessageBox.critical(self, self.tr("Money transfer"), self.tr("No amount. Please give the transfert amount"), QMessageBox.Ok) - return""" + return password = yield from self.password_asker.async_exec() if self.password_asker.result() == QDialog.Rejected: @@ -97,11 +96,17 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): if self.app.preferences['notifications']: toast.display(self.tr("Transfer"), self.tr("Success sending money to {0}").format(recipient)) + else: + yield from QAsyncMessageBox.information(self, self.tr("Transfer"), + self.tr("Success sending money to {0}").format(recipient)) QApplication.restoreOverrideCursor() super().accept() else: if self.app.preferences['notifications']: - toast.display(self.tr("Error"), "{0}".format(result[1])) + toast.display(self.tr("Transfer"), "Error : {0}".format(result[1])) + else: + yield from QAsyncMessageBox.critical(self, self.tr("Transfer"), result[1]) + QApplication.restoreOverrideCursor() @asyncify