-
Notifications
You must be signed in to change notification settings - Fork 1
/
notifier.py
94 lines (73 loc) · 3.14 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from PyQt5 import QtGui
from PyQt5.QtCore import Qt, QPoint, pyqtSignal, QTimer, QPropertyAnimation
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QVBoxLayout, QSizePolicy, QPushButton, \
QApplication
class NotifierWidget(QWidget):
doubleClicked = pyqtSignal()
def __init__(self, informative_text='', detailed_text=''):
super().__init__()
self.__timerVal = 5000
self.__initUi(informative_text, detailed_text)
def __initUi(self, informative_text='', detailed_text=''):
self.setFixedSize(250, 150)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.SubWindow)
self.__informativeTextLabel = QLabel(informative_text) if informative_text else QLabel('Informative')
self.__informativeTextLabel.setFont(QFont('Arial', 15, QFont.Bold))
self.__detailedTextLabel = QLabel(detailed_text) if detailed_text else QLabel('Detailed')
closeBtn = QPushButton()
closeBtn.clicked.connect(self.close)
closeBtn.setIcon(QIcon('ico/close.svg'))
lay = QHBoxLayout()
lay.setContentsMargins(0, 0, 0, 0)
self.__btnWidget = QWidget()
self.__btnWidget.setLayout(lay)
lay = QHBoxLayout()
lay.setAlignment(Qt.AlignTop | Qt.AlignRight)
lay.addWidget(closeBtn)
lay.setContentsMargins(0, 0, 0, 0)
customMenuBar = QWidget()
customMenuBar.setLayout(lay)
lay = QVBoxLayout()
lay.addWidget(customMenuBar)
lay.addWidget(self.__informativeTextLabel)
lay.addWidget(self.__detailedTextLabel)
lay.addWidget(self.__btnWidget)
lay.setContentsMargins(0, 0, 0, 0)
ag = QtGui.QGuiApplication.primaryScreen().availableGeometry()
geo = self.geometry()
geo.moveBottomRight(QPoint(ag.width(), ag.height()))
self.setGeometry(geo)
lay.setContentsMargins(8, 8, 8, 8)
self.setLayout(lay)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.close()
return super().keyPressEvent(e)
def addWidgets(self, widgets: list):
for widget in widgets:
widget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.__btnWidget.layout().addWidget(widget)
def show(self) -> None:
super().show()
QApplication.beep()
self.__timer = QTimer(self)
self.__timer.timeout.connect(self.__checkTimer)
self.__timer.start(1000)
def __checkTimer(self):
self.__timerVal -= 1000
if self.__timerVal == 1000:
self.__showAnimation()
elif self.__timerVal <= 0:
self.close()
def __showAnimation(self):
self.__animation = QPropertyAnimation(self, b"windowOpacity")
self.__animation.finished.connect(self.close)
self.__animation.setDuration(1000)
self.__animation.setStartValue(1.0)
self.__animation.setEndValue(0.0)
self.__animation.start()
def mouseDoubleClickEvent(self, e):
self.doubleClicked.emit()
self.close()
return super().mouseDoubleClickEvent(e)