-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (57 loc) · 2.11 KB
/
Copy pathmain.py
File metadata and controls
70 lines (57 loc) · 2.11 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
import os
import sys
import signal
import random
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QShortcut
from PyQt5.QtGui import QKeySequence, QMovie
from PyQt5.QtCore import Qt, QTimer
def get_base_path():
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.dirname(__file__)
return base_path
class Window(QMainWindow):
def __init__(self):
super().__init__()
QShortcut(QKeySequence("Ctrl+Q"), self, self.close)
# Setup window
self.setAttribute(Qt.WA_TranslucentBackground)
self.setAttribute(Qt.WA_TransparentForMouseEvents)
self.setWindowFlags(
Qt.WindowType.WindowStaysOnTopHint |
Qt.WindowType.FramelessWindowHint |
Qt.WindowType.X11BypassWindowManagerHint |
Qt.WindowType.Tool
)
self.setGeometry(QApplication.primaryScreen().geometry().adjusted(0,0,0,-40))
self.label = QLabel(self)
self.label.setScaledContents(True)
self.label.setGeometry(self.rect())
self.setup_gif(self.get_next_gif())
def setup_gif(self, gif_path):
self.movie = QMovie(gif_path)
self.label.setMovie(self.movie)
self.movie.frameChanged.connect(self.check_loop_end)
QTimer.singleShot(
random.randint(1000 * 60, 1000 * 60 * 60 * 1),
self.play_gif
)
def play_gif(self):
self.label.show()
self.movie.start()
def get_next_gif(self):
videos_path = os.path.join(get_base_path(), "videos")
gif_files = [f for f in os.listdir(videos_path) if f.lower().endswith('.gif')]
return os.path.join(videos_path, random.choice(gif_files))
def check_loop_end(self, frame_number):
if frame_number == self.movie.frameCount() - 1:
self.movie.stop()
self.label.hide()
self.setup_gif(self.get_next_gif())
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
signal.signal(signal.SIGINT, signal.SIG_DFL) # restore sigint functionality
app.exec()