-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown_widget.py
More file actions
107 lines (85 loc) · 3.23 KB
/
countdown_widget.py
File metadata and controls
107 lines (85 loc) · 3.23 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
import keyboard
from datetime import date
from PyQt5.QtCore import Qt, QTimer, QPoint
from PyQt5.QtWidgets import QApplication, QLabel, QWidget
# ==== CONFIGURE YOUR MILESTONE HERE ====
# Example: 15 May 2027
TARGET_DATE = date(2027, 5, 15)
TITLE_TEXT = "Days until Forever Home"
# =======================================
# ======= THE REST OF THE CODE =========
def days_until(target: date) -> int:
today = date.today()
counter = target - today
# ===== IF You WANT THE COUNTER TO GO TO NEGATIVE AFTER THE DAY HAS PASSED REMOVE max(...) =======
return max(counter.days, 0)
class CountdownWidget(QWidget):
def __init__(self):
super().__init__()
# Basic window setup
self.setWindowTitle("Countdown Widget")
self.setGeometry(100, 100, 250, 120)
# Frameless + transparent background for “widget” feel
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Tool | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# Track offset for dragging
self.offset = QPoint()
# Title label
self.title_label = QLabel(TITLE_TEXT, self)
self.title_label.setGeometry(10, 5, 230, 30)
self.title_label.setStyleSheet("""
color: white;
font-size: 14px;
font-weight: bold;
""")
self.title_label.setAlignment(Qt.AlignCenter)
# Countdown label
self.count_label = QLabel("", self)
self.count_label.setGeometry(10, 40, 230, 70)
self.count_label.setStyleSheet("""
color: white;
font-size: 32px;
font-weight: bold;
""")
self.count_label.setAlignment(Qt.AlignCenter)
# Background style (rounded dark rectangle)
self.setStyleSheet("""
QWidget {
background-color: rgba(30, 30, 30, 200);
border-radius: 15px;
}
""")
# Initial update
self.update_countdown()
# Timer to refresh once every minute (60000 ms).
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_countdown)
self.timer.start(60000) # Update every minute, change to 3600000 for hourly
def update_countdown(self):
remaining_days = days_until(TARGET_DATE)
self.count_label.setText(f"{remaining_days} days")
# ===========Draggable window =============
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.offset = event.pos()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
counter = event.pos() - self.offset
self.move(self.pos() + counter)
def toggle_visibility(self):
if self.isVisible():
self.hide()
else:
self.show()
def close_app(self):
QApplication.quit()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CountdownWidget()
window.show()
# ===== SET YOUR GLOBAL HOTKEYs TO TOGGLE VISIBILITY and close app=======
keyboard.add_hotkey('ctrl+alt+s', window.toggle_visibility)
keyboard.add_hotkey('ctrl+alt+c', window.close_app)
# =========================================================
sys.exit(app.exec_())