-
Notifications
You must be signed in to change notification settings - Fork 2
/
journal.py
78 lines (57 loc) · 2.26 KB
/
journal.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
import os
import sys
import time
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QRect, QRectF, QTimer
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon, QPixmap, QPainter
pipe_path = '/tmp/oneshot-pipe'
try: base_path = sys._MEIPASS
except AttributeError: base_path = os.path.abspath('.')
class WatchPipe(QThread):
change_image = pyqtSignal(str)
def run(self):
while True:
if os.path.exists(pipe_path): break
else: time.sleep(0.1)
pipe = open(pipe_path, 'r')
pipe.flush()
while True:
message = os.read(pipe.fileno(), 256)
if len(message) > 0:
self.change_image.emit(message.decode())
time.sleep(0.05)
class Journal(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.label = QLabel(self)
self.change_image('default')
self.setWindowFlags(self.windowFlags())
self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowTitle('OneShot Journal')
self.setMinimumSize(800, 600)
self.setMaximumSize(800, 600)
self.setGeometry(0, 0, 800, 600)
self.show()
def change_image(self, name):
self.pixmap = QPixmap(os.path.join(base_path, 'images', '{}.png'.format(name)))
self.label.setPixmap(self.pixmap)
class Niko(QWidget):
def __init__(self, *args, **kwargs):
self.start_x, self.start_y = kwargs['start_x'], kwargs['start_y']
del kwargs['start_x'], kwargs['start_y']
super().__init__(*args, **kwargs)
self.frames = [QPixmap(os.path.join(base_path, 'images', 'niko{}.png'.format(n)) for n in range(1,4))]
self.setBackgroundRole(QPalette.Base)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
if __name__ == '__main__':
app = QApplication(sys.argv)
if len(sys.argv) == 3:
# "Niko-leaves-the-screen" mode
x, y = int(sys.argv[1]), int(sys.argv[2])
else:
# Author's Journal mode
journal = Journal()
thread = WatchPipe()
thread.change_image.connect(journal.change_image)
thread.start()
app.exec_()