-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragable_counter.py
88 lines (74 loc) · 2.98 KB
/
dragable_counter.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
import sys
from PyQt5.QtWidgets import QApplication, QDialog, QLabel, QPushButton
from PyQt5.QtCore import Qt, QPoint, pyqtSignal
from PyQt5.uic import loadUi
from utiles import PATH
class DragableCounterWindow(QDialog):
escape_pressed = pyqtSignal()
prop_label : QLabel
time_label : QLabel
minus_button : QPushButton
play_pause_button : QPushButton
plus_button : QPushButton
def __init__(self):
super().__init__()
loadUi(PATH + "dragable_counter.ui", self)
self.setContentsMargins(0, 0, 0, 0)
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(1)
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Tool | Qt.FramelessWindowHint)
self.go_top_right() # Initial position
# Set focus policy for buttons
self.minus_button.setFocusPolicy(Qt.NoFocus)
self.play_pause_button.setFocusPolicy(Qt.NoFocus)
self.plus_button.setFocusPolicy(Qt.NoFocus)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Escape:
self.escape_pressed.emit()
elif event.key() == Qt.Key_Plus:
self.adjustOpacity(1) # Increase opacity by 10%
elif event.key() == Qt.Key_Minus:
self.adjustOpacity(-1) # Decrease opacity by 10%
elif event.key() == Qt.Key_Up:
self.move_to_top()
elif event.key() == Qt.Key_Left:
self.move_to_left()
elif event.key() == Qt.Key_Right:
self.move_to_right()
elif event.key() == Qt.Key_Down:
self.move_to_bottom()
def adjustOpacity(self, delta):
opacity = self.windowOpacity() + delta
opacity = max(0.1, min(opacity, 1.0)) # Ensure opacity is between 0.1 and 1.0
self.setWindowOpacity(opacity)
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint(event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
def go_top_right(self):
desktop = QApplication.desktop()
screen_rect = desktop.availableGeometry()
# Set position to top-right corner
window_width = self.width()
self.move(screen_rect.width() - window_width, 0)
def move_to_top(self):
self.move(self.x(), 0)
def move_to_left(self):
self.move(0, self.y())
def move_to_right(self):
desktop = QApplication.desktop()
screen_rect = desktop.availableGeometry()
window_width = self.width()
self.move(screen_rect.width() - window_width, self.y())
def move_to_bottom(self):
desktop = QApplication.desktop()
screen_rect = desktop.availableGeometry()
window_height = self.height()
self.move(self.x(), screen_rect.height() - window_height)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = DragableCounterWindow()
window.show()
sys.exit(app.exec_())