diff --git a/res/ui/toast.ui b/res/ui/toast.ui index 73ebaaed438fc6f70d68489ca5d59030cb6d3a5c..61c442e0323f682ec39f0e071a74533a8fa0b25f 100644 --- a/res/ui/toast.ui +++ b/res/ui/toast.ui @@ -13,6 +13,10 @@ <property name="windowTitle"> <string>MainWindow</string> </property> + <property name="windowIcon"> + <iconset resource="../icons/icons.qrc"> + <normaloff>:/icons/cutecoin_logo</normaloff>:/icons/cutecoin_logo</iconset> + </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> <item> @@ -35,6 +39,8 @@ </widget> <widget class="QStatusBar" name="statusbar"/> </widget> - <resources/> + <resources> + <include location="../icons/icons.qrc"/> + </resources> <connections/> </ui> diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index 3893d1438b44325b500998d6da20f8c5a4caeffe..199e2823ca9ac3ef6490fa91cf4aee7a92bb9b50 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -6,11 +6,11 @@ Created on 1 févr. 2014 import os import logging -import json import tarfile import shutil import json import datetime +import sys from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, QUrl from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index c26b2bee44ea3c15ffb78cd23b98ea4b6204cdde..ea57c4998579319b6e32c7acca249f8909949254 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -17,6 +17,7 @@ from .wot_tab import WotTabWidget from .transfer import TransferMoneyDialog from .password_asker import PasswordAskerDialog from .certification import CertificationDialog +from . import toast from ..tools.exceptions import PersonNotFoundError, NoPeerAvailable from ..core.person import Person from ucoinpy.api import bma @@ -172,8 +173,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): try: self.account.send_membership(password, self.community, 'IN') - QMessageBox.information(self, self.tr("Membership"), - self.tr("Success sending membership demand")) + toast.display(self.tr("Membership"), self.tr("Success sending membership demand")) except ValueError as e: QMessageBox.critical(self, self.tr("Join demand error"), str(e)) @@ -204,8 +204,7 @@ The process to join back the community later will have to be done again.""") try: self.account.send_membership(password, self.community, 'OUT') - QMessageBox.information(self, self.tr("Membership"), - self.tr("Success sending leaving demand")) + toast.display(self.tr("Membership"), self.tr("Success sending leaving demand")) except ValueError as e: QMessageBox.critical(self, self.tr("Leaving demand error"), e.message) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 1cc3f3f847c6e6911da54c6b69bd6a524e002cb4..966a3d2412c022d38be434de0d7fe36c9ca36f79 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -16,7 +16,7 @@ from .wallets_tab import WalletsTabWidget from .transactions_tab import TransactionsTabWidget from .network_tab import NetworkTabWidget from .informations_tab import InformationsTabWidget -from .toast import Toast +from . import toast from ..tools.exceptions import MembershipNotFoundError from ..core.person import Person @@ -74,12 +74,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): if will_expire_soon: days = QDateTime().currentDateTime().daysTo(QDateTime.fromTime_t(expiration_date)) if days > 0: - QMessageBox.warning( - self, - self.tr("Membership expiration"), - self.tr("Warning : Membership expiration in {0} days").format(days), - QMessageBox.Ok - ) + toast.display(self.tr("Membership expiration" +"<b>Warning : Membership expiration in {0} days</b>").format(days)) except MembershipNotFoundError as e: pass @@ -188,7 +184,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): text += """{0} """.format(t.metadata['uid']) text.format(amount, currency) - Toast(text) + toast.display(self.tr("New transactions received"), text) def refresh_wallets(self): if self.app.current_account: diff --git a/src/cutecoin/gui/toast.py b/src/cutecoin/gui/toast.py index f3903a69ae42b182b4ff837582f3972255cc46d8..f96cb04a44d519f7024cd631b2e8e31154b884c1 100644 --- a/src/cutecoin/gui/toast.py +++ b/src/cutecoin/gui/toast.py @@ -4,23 +4,58 @@ Created on 1 mai 2015 @author: inso ''' import sys, time +import logging from PyQt5.QtCore import Qt, QThread from PyQt5.QtWidgets import QMainWindow +from PyQt5.QtGui import QImage, QPixmap from ..gen_resources.toast_uic import Ui_Toast window = None # global -class Toast(QMainWindow, Ui_Toast): - def __init__(self, msg): +def display(title, msg): + if sys.platform == "linux": + import notify2 + import dbus + if not notify2.is_initted(): + logging.debug("Initialising notify2") + notify2.init("cutecoin") + n = notify2.Notification(title, + msg) + + # Not working... Empty icon at the moment. + icon = QPixmap(":/icons/cutecoin_logo/").toImage() + if icon.isNull(): + logging.debug("Error converting logo") + else: + icon.convertToFormat(QImage.Format_ARGB32) + icon_bytes = icon.bits().asstring(icon.byteCount()) + icon_struct = ( + icon.width(), + icon.height(), + icon.bytesPerLine(), + icon.hasAlphaChannel(), + 32, + 4, + dbus.ByteArray(icon_bytes) + ) + n.set_hint('icon_data', icon_struct) + n.set_timeout(5000) + n.show() + else: + _Toast(title, msg) + +class _Toast(QMainWindow, Ui_Toast): + def __init__(self, title, msg): global window # some space outside the local stack window = self # save pointer till killed to avoid GC super().__init__() self.setWindowFlags(Qt.FramelessWindowHint) self.setupUi(self) - self.display.setText(msg) + self.display.setText("""<h1>{0}</h1> +<p>{1}</p>""".format(title, msg)) - self.toastThread = ToastThread() # start thread to remove display + self.toastThread = _ToastThread() # start thread to remove display self.toastThread.finished.connect(self.toastDone) self.toastThread.start() self.show() @@ -29,7 +64,7 @@ class Toast(QMainWindow, Ui_Toast): global window window = None # kill pointer to window object to close it and GC -class ToastThread(QThread): +class _ToastThread(QThread): def __init__(self): QThread.__init__(self)