-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (62 loc) · 2.37 KB
/
main.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
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import psutil
import sys
class ToolBar(QWidget):
def __init__(self):
super(ToolBar, self).__init__()
# Window size
self.w = 400
self.h = 50
self.resize(self.w, self.h)
# Widget
self.centralwidget = QWidget(self)
self.centralwidget.resize(self.w, self.h)
# Initial
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
radius = self.h / 2
self.centralwidget.setStyleSheet(
'''
background: rgb(0, 0, 0);
border-top-left-radius:{0}px;
border-bottom-left-radius:{0}px;
border-top-right-radius:{0}px;
border-bottom-right-radius:{0}px;
'''.format(radius)
)
self.screenSize = QDesktopWidget().screenGeometry(-1)
self.getCentered = (self.screenSize.width() / 2) - (self.w / 2)
self.setGeometry(self.getCentered, 10, self.w, self.h)
self.label = QLabel(self)
self.label.setStyleSheet("background-color:transparent;color: #FFFFFF;font-family: 'Arial'; font-size: 14px; font-weight: bold; padding: 0;")
self.label.setGeometry(QRect(345,15,300,18))
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(10)
self.checkIfProcessRunning('spotify')
def showTime(self):
current_time = QTime.currentTime()
label_time = current_time.toString('hh:mm')
self.label.setText(label_time)
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.close()
def checkIfProcessRunning(self,processName):
for proc in psutil.process_iter():
try:
if processName.lower() in proc.name().lower():
labelImg = QLabel(self)
pixmap = QPixmap('spotify.ico')
labelImg.setPixmap(pixmap)
labelImg.setGeometry(QRect(15, 15, 18, 18))
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
if __name__ == '__main__':
app = QApplication([])
window = ToolBar()
window.show()
sys.exit(app.exec_())