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

Async message box

parent fa72050f
Branches
Tags
No related merge requests found
......@@ -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):
......
......@@ -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):
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:
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"))
yield from QAsyncMessageBox.information(self, self.tr("Revoke"),
self.tr("Success sending Revoke demand"))
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)
toast.display(self.tr("Revoke"), result[1])
else:
QMessageBox.error(error, strdata)
yield from QAsyncMessageBox.critical(self, self.tr("Revoke"),
result[1])
def showEvent(self, QShowEvent):
"""
......
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)
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment