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

Working on notifiations (Request #100)

parent c99ea1c2
Branches
No related tags found
No related merge requests found
......@@ -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>
......@@ -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
......
......@@ -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)
......
......@@ -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:
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment