From 53709a92c76493d4f75d5d54d8cfdede792f5845 Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Wed, 2 May 2018 19:15:11 -0700 Subject: [PATCH] Let journal reimplementation accommodate for new API updates --- journal/unix/journal.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/journal/unix/journal.py b/journal/unix/journal.py index f7532cb..b54140b 100644 --- a/journal/unix/journal.py +++ b/journal/unix/journal.py @@ -48,11 +48,28 @@ class WatchPipe(QThread): class AnimationTimer(QThread): next_frame = pyqtSignal() + start_animation = pyqtSignal(int, int) def run(self): while True: - self.next_frame.emit() - time.sleep(1.0 / 60) + while not os.path.exists(pipe_path): time.sleep(0.1) + + pipe = open(pipe_path, 'r') + pipe.flush() + + while os.path.exists(pipe_path): # Make sure the file still exists and wasn't cleaned up by SyngleChance + message = os.read(pipe.fileno(), 256) + if len(message) > 0: + m = message.decode() + if not "," in m: pass + x, y = m.split(",") + self.start_animation.emit(int(x), int(y)) + + while True: + self.next_frame.emit() + time.sleep(1.0 / 60) + + time.sleep(0.05) class Journal(QWidget): def __init__(self, *args, **kwargs): @@ -114,9 +131,9 @@ class Journal(QWidget): class Niko(QWidget): def __init__(self, *args, **kwargs): - self.x, self.y, self.start_y, self.app, self.thread = kwargs['x'], kwargs['y'], kwargs['y'], kwargs['app'], kwargs['thread'] + self.app, self.thread = kwargs['app'], kwargs['thread'] self.screen_height = kwargs['screen_height'] - del kwargs['x'], kwargs['y'], kwargs['screen_height'], kwargs['app'], kwargs['thread'] + del kwargs['screen_height'], kwargs['app'], kwargs['thread'] super().__init__(*args, **kwargs) @@ -129,9 +146,12 @@ class Niko(QWidget): self.frames = [QPixmap(os.path.join(base_path, 'images', 'niko{}.png'.format(n))) for n in range(1,4)] self.label.setPixmap(self.frames[1]) - self.show() + def start(self, x, y): + self.x = x + self.y = y + self.start_y = y - self.thread.start() + self.show() def getFrame(self): if ((self.y - self.start_y) % 32 >= 16): return 1 @@ -152,15 +172,15 @@ class Niko(QWidget): if __name__ == '__main__': app = QApplication(sys.argv) - if len(sys.argv) == 3: + if len(sys.argv) == 2 and sys.argv[1] == "niko": # "Niko-leaves-the-screen" mode - x, y = int(sys.argv[1]), int(sys.argv[2]) - thread = AnimationTimer() - niko = Niko(x = x, y = y, screen_height = app.primaryScreen().size().height(), app = app, thread = thread) + niko = Niko(screen_height = app.primaryScreen().size().height(), app = app, thread = thread) + thread.start_animation.connect(niko.start) thread.next_frame.connect(niko.update) + thread.start() else: # Author's Journal mode