-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmt_eyerest.py
More file actions
executable file
·104 lines (86 loc) · 3.69 KB
/
mt_eyerest.py
File metadata and controls
executable file
·104 lines (86 loc) · 3.69 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
import sys
from PyQt6.QtCore import Qt, QTimer, QUrl
from PyQt6.QtMultimedia import QAudioOutput, QMediaPlayer
from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QWidget
import rumps
def position_changed(position):
"""Callback function for tracking audio position."""
print(f"Position changed: {position}")
class MtEyerestStatusBarApp(rumps.App):
"""Main class for the mt. eyerest application."""
def __init__(self):
"""Initialize the application."""
super().__init__("mt. eyerest", quit_button=None)
self.menu = ["Preferences", "Quit"]
self.timer = rumps.Timer(self.remind_to_close_eyes, 20*60)
self.timer.start()
self.first_time = True
self.app = QApplication.instance() or QApplication(sys.argv)
self.player = QMediaPlayer()
self.audio = QAudioOutput()
self.audio.setVolume(50)
self.audio.setMuted(False)
self.player.setAudioOutput(self.audio)
self.player.positionChanged.connect(position_changed)
def play_mp3(self, filename):
"""Play an MP3 file."""
self.player.stop()
self.player.setPosition(0)
self.player.play()
self.player.setSource(QUrl.fromLocalFile(filename))
self.player.play()
def play_ding(self):
"""Play a bell sound."""
self.play_mp3("bell.mp3")
def remind_to_close_eyes(self, _):
"""Remind the user to close their eyes."""
if self.first_time:
self.first_time = False
return
self.create_overlay()
def skip_and_close_overlay(self):
"""Close the overlay when the skip button is pressed."""
self.skip_pressed = True
def create_overlay(self):
"""Create and show an overlay window."""
overlay = QWidget()
self.skip_pressed = False
screen = self.app.primaryScreen()
screen_geometry = screen.geometry()
screen_width = screen_geometry.width()
screen_height = screen_geometry.height()
overlay.setWindowOpacity(0.6)
overlay.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.FramelessWindowHint)
overlay.setGeometry(0, 0, screen_width, screen_height)
overlay.setStyleSheet("background-color:black;")
text_label = QLabel("Rest your eyes, the bell will call you back.", overlay)
text_label.setStyleSheet("font-size: 24px; color: white;")
text_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
text_label.adjustSize()
label_width = text_label.width()
label_height = text_label.height()
label_x = (screen_width - label_width) // 2
label_y = (screen_height - label_height) // 2
text_label.move(label_x, label_y - 50)
close_button = QPushButton("SKIP", overlay)
close_button.clicked.connect(self.skip_and_close_overlay)
close_button.clicked.connect(overlay.close)
close_button.resize(200, 100)
close_button.setStyleSheet("font-size: 24px; background-color: black; color: white;")
center_x = (screen_width - 200) // 2
center_y = (screen_height - 100) // 2
close_button.move(center_x, center_y + 100)
QTimer.singleShot(10000, lambda: [overlay.close(), self.play_ding() if not self.skip_pressed else None])
overlay.show()
self.app.exec()
@rumps.clicked("Preferences")
def prefs(self, _):
"""Show an alert when Preferences is clicked."""
rumps.alert("jk! No preferences available!")
@rumps.clicked("Quit")
def quit_app(self, _):
"""Quit the application."""
self.app.quit()
rumps.quit_application()
if __name__ == "__main__":
MtEyerestStatusBarApp().run()