summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Keller <tjkeller.xyz>2025-05-10 19:47:31 -0500
committerTim Keller <tjkeller.xyz>2025-05-10 19:47:31 -0500
commite7036d21d5e5c87702724283f55a77d07344f4fe (patch)
tree45d0801042b38ca595c32e7c4a0dd42b96780ede
parentfc570fc38b450b90a2c8da05e5619f19ba8e983d (diff)
downloadimmich-frame-e7036d21d5e5c87702724283f55a77d07344f4fe.tar.xz
immich-frame-e7036d21d5e5c87702724283f55a77d07344f4fe.zip
add flaskapi
-rw-r--r--flaskapi.py24
-rw-r--r--pix.py12
-rw-r--r--window.py19
3 files changed, 48 insertions, 7 deletions
diff --git a/flaskapi.py b/flaskapi.py
new file mode 100644
index 0000000..4b1a259
--- /dev/null
+++ b/flaskapi.py
@@ -0,0 +1,24 @@
+from flask import Flask, Blueprint, request
+
+app = Flask(__name__)
+
+@app.route("/")
+def home():
+ return "Flask is running!"
+
+api = Blueprint("api", __name__)
+
+@api.route("/seek")
+def seek():
+ pd = app.config["pix_display"]
+
+ increment = request.args.get("increment", default=1, type=int)
+ pd.queue.put(lambda: pd.seek(increment))
+ while not pd.queue.empty():
+ pass
+ return {
+ "imageTime": pd.image_time,
+ "imageIndex": pd.current_texture_index,
+ }
+
+app.register_blueprint(api, url_prefix="/api")
diff --git a/pix.py b/pix.py
index 6e53b8d..aa1495f 100644
--- a/pix.py
+++ b/pix.py
@@ -5,6 +5,7 @@ from OpenGL.GLUT import glutLeaveMainLoop
from window import PixDisplay
from immich import ImmichConnector
+from flaskapi import app
def handle_sigint(sig, frame):
@@ -18,9 +19,16 @@ def handle_sigint(sig, frame):
if __name__ == "__main__":
- immichConnector = ImmichConnector("http://192.168.1.13", "m5nqOoBc4uhAba21gZdCP3z8D3JT4GPxDXL2psd52EA")
pd = PixDisplay()
- t1 = Thread(target=immichConnector.idle, daemon=True, args=(pd,))
+ immich_connector = ImmichConnector("http://192.168.1.13", "m5nqOoBc4uhAba21gZdCP3z8D3JT4GPxDXL2psd52EA")
+
+ t1 = Thread(target=immich_connector.idle, daemon=True, args=(pd,))
t1.start()
+
+ app.config["pix_display"] = pd
+ app.config["immich_connector"] = immich_connector
+ flask_thread = Thread(target=app.run, daemon=True, kwargs={ "port": 5000 })
+ flask_thread.start()
+
signal.signal(signal.SIGINT, handle_sigint)
pd.main(sys.argv)
diff --git a/window.py b/window.py
index 8e04225..24320b9 100644
--- a/window.py
+++ b/window.py
@@ -2,6 +2,7 @@ from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from time import time
+from queue import Queue
from renderer import ImageRenderer, TransitionMix
from texture import ImageTexture
@@ -12,6 +13,7 @@ class PixDisplay:
self.last_time = 0
self.start_time = 0
self.image_time = 0
+ self.paused = False
self.textures = []
self.current_texture_index = 0
self.renderer = None
@@ -24,10 +26,11 @@ class PixDisplay:
self.auto_transition = True
self.transition_reverse = False
+ self.text_prev = None
self.tex = None
- self.text_next = None
self._force_redraw = False
+ self.queue = Queue()
@property
def max_framerate(self):
@@ -69,8 +72,14 @@ class PixDisplay:
glutSwapBuffers()
return
+ # Run queue events
+ while not self.queue.empty():
+ f = self.queue.get() # Get the task and its data
+ f()
+
# Progress image time
- self.image_time += delta_time
+ if not self.paused:
+ self.image_time += delta_time
# Get window size
old_win_w, old_win_h = self.win_w, self.win_h
@@ -102,16 +111,16 @@ class PixDisplay:
glutPostRedisplay()
glutTimerFunc(self.frame_time, self.timer, 0) # Schedule next frame
- def skip(self, increment):
+ def seek(self, increment):
self.auto_transition = False
self.increment_texture_index(increment)
self.image_time = self.image_duration
def handle_special_key(self, key, x, y):
if key == GLUT_KEY_LEFT:
- self.skip(-1)
+ self.seek(-1)
elif key == GLUT_KEY_RIGHT:
- self.skip(1)
+ self.seek(1)
def handle_visibility_change(self, state):
if state == GLUT_VISIBLE: