From 145de3311cb9f32ac0bc9842b0600fcad84fed16 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Fri, 9 May 2025 21:58:54 -0500 Subject: add support for downloading new images from immich api on a separate thread --- window.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 window.py (limited to 'window.py') diff --git a/window.py b/window.py new file mode 100644 index 0000000..29d0522 --- /dev/null +++ b/window.py @@ -0,0 +1,110 @@ +from OpenGL.GL import * +from OpenGL.GLUT import * +from OpenGL.GLU import * +from time import time + +from transition import Transition +from texture import ImageTexture + + +class PixDisplay: + def __init__(self): + self.last_time = 0 + self.start_time = 0 + self.image_time = 0 + self.textures = [] + self.current_texture_index = 0 + self.transition = Transition() + self.window_width = 0 + self.window_height = 0 + + self.display_duration = 2.0 + self.transition_duration = 0.5 + + @property + def next_texture_index(self): return (self.current_texture_index + 1) % len(self.textures) + + @property + def texture_current(self): return self.textures[self.current_texture_index] + + @property + def texture_next(self): return self.textures[self.next_texture_index] + + # Main display function + def display(self): + # Calculate timings + current_time = time() + alive_time = current_time - self.start_time + delta_time = current_time - self.last_time + self.last_time = current_time + + if not self.textures: + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glLoadIdentity() + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + + glutSwapBuffers() + return + + # Ensure textures are initialized + self.texture_current.gl_init() + self.texture_next.gl_init() + + # Progress image time + self.image_time += delta_time + + # Get window size + window_width, window_height = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) + + if self.image_time < self.display_duration: + if window_width != self.window_width or window_height != self.window_height: + self.window_width, self.window_height = window_width, window_height + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glLoadIdentity() + + self.transition.draw_image(self.texture_current, self.window_width, self.window_height, 1) + + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + glutSwapBuffers() + return + + self.window_width, self.window_height = window_width, window_height + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glLoadIdentity() + + # DRAW + transition_time = self.image_time - self.display_duration + complete = self.transition.draw(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration) + + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + + glutSwapBuffers() + + if complete: + self.image_time = 0 + self.current_texture_index = self.next_texture_index + + # Initialization and main loop + def main(self): + # Initialize the window + glutInit(sys.argv) + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) + glutCreateWindow("Image Viewer with Fade Transition") + glEnable(GL_TEXTURE_2D) + + self.image_time = 0 + self.start_time = time() + self.last_time = time() + + # Set up the OpenGL viewport and projection + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + glOrtho(-1, 1, -1, 1, -1, 1) + glMatrixMode(GL_MODELVIEW) + + glutDisplayFunc(self.display) + glutIdleFunc(self.display) + glutMainLoop() + -- cgit v1.2.3 From 2bd4da7678b027843cac1a03a1b5f6cc70a7cc81 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 11:52:02 -0500 Subject: requirements.txt added, significantly reduced cpu usage using timer func and vertex/fragment shader instead of drawing new quad etc every frame --- window.py | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 29d0522..4c51bd1 100644 --- a/window.py +++ b/window.py @@ -3,7 +3,7 @@ from OpenGL.GLUT import * from OpenGL.GLU import * from time import time -from transition import Transition +from renderer import ImageRenderer, TransitionMix from texture import ImageTexture @@ -14,9 +14,12 @@ class PixDisplay: self.image_time = 0 self.textures = [] self.current_texture_index = 0 - self.transition = Transition() + self.renderer = None self.window_width = 0 self.window_height = 0 + # TODO + self.max_framerate = 60 + self.frame_time = int(1000 / self.max_framerate) # In ms self.display_duration = 2.0 self.transition_duration = 0.5 @@ -39,9 +42,9 @@ class PixDisplay: self.last_time = current_time if not self.textures: - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glLoadIdentity() glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + #glLoadIdentity() glutSwapBuffers() return @@ -60,25 +63,24 @@ class PixDisplay: if window_width != self.window_width or window_height != self.window_height: self.window_width, self.window_height = window_width, window_height + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glLoadIdentity() + #glLoadIdentity() - self.transition.draw_image(self.texture_current, self.window_width, self.window_height, 1) + self.renderer.draw_static(self.texture_current, self.window_width, self.window_height, 1) - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glutSwapBuffers() return self.window_width, self.window_height = window_width, window_height + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glLoadIdentity() + #glLoadIdentity() # DRAW transition_time = self.image_time - self.display_duration - complete = self.transition.draw(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration) - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + complete = self.renderer.draw_transition(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration) glutSwapBuffers() @@ -86,6 +88,10 @@ class PixDisplay: self.image_time = 0 self.current_texture_index = self.next_texture_index + def timer(self, value): + glutPostRedisplay() + glutTimerFunc(self.frame_time, self.timer, 0) # Schedule next frame + # Initialization and main loop def main(self): # Initialize the window @@ -94,6 +100,8 @@ class PixDisplay: glutCreateWindow("Image Viewer with Fade Transition") glEnable(GL_TEXTURE_2D) + self.renderer = ImageRenderer() + self.renderer.set_transition(TransitionMix) self.image_time = 0 self.start_time = time() self.last_time = time() @@ -104,7 +112,12 @@ class PixDisplay: glOrtho(-1, 1, -1, 1, -1, 1) glMatrixMode(GL_MODELVIEW) + # Enable alpha blending + glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + + # Run display glutDisplayFunc(self.display) - glutIdleFunc(self.display) + glutTimerFunc(self.frame_time, self.timer, 0) glutMainLoop() -- cgit v1.2.3 From b823139687f3c55dd3695e11a0cf8f9693524e9b Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 15:26:01 -0500 Subject: max framerate setter getter --- window.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 4c51bd1..e3c9fa2 100644 --- a/window.py +++ b/window.py @@ -17,13 +17,20 @@ class PixDisplay: self.renderer = None self.window_width = 0 self.window_height = 0 - # TODO - self.max_framerate = 60 - self.frame_time = int(1000 / self.max_framerate) # In ms + self.max_framerate = 30 self.display_duration = 2.0 self.transition_duration = 0.5 + @property + def max_framerate(self): + return self._max_fps + + @max_framerate.setter + def max_framerate(self, max_fps): + self._max_fps = max_fps # This is just for the getter since otherwise e.g. int(1000/int(1000/60)) would round to 62 + self.frame_time = int(1000 / 60) # In ms + @property def next_texture_index(self): return (self.current_texture_index + 1) % len(self.textures) @@ -44,8 +51,6 @@ class PixDisplay: if not self.textures: glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - #glLoadIdentity() - glutSwapBuffers() return @@ -65,7 +70,6 @@ class PixDisplay: glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - #glLoadIdentity() self.renderer.draw_static(self.texture_current, self.window_width, self.window_height, 1) @@ -76,7 +80,6 @@ class PixDisplay: glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - #glLoadIdentity() # DRAW transition_time = self.image_time - self.display_duration -- cgit v1.2.3 From 3aed05a6cb265e4f60a17f87eb368fb33c93a562 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 16:26:33 -0500 Subject: cleanup some --- window.py | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index e3c9fa2..ef9e9ee 100644 --- a/window.py +++ b/window.py @@ -15,8 +15,8 @@ class PixDisplay: self.textures = [] self.current_texture_index = 0 self.renderer = None - self.window_width = 0 - self.window_height = 0 + self.win_w = 0 + self.win_h = 0 self.max_framerate = 30 self.display_duration = 2.0 @@ -31,14 +31,17 @@ class PixDisplay: self._max_fps = max_fps # This is just for the getter since otherwise e.g. int(1000/int(1000/60)) would round to 62 self.frame_time = int(1000 / 60) # In ms + @property + def prev_texture_index(self): return self.current_texture_index - 1 + @property def next_texture_index(self): return (self.current_texture_index + 1) % len(self.textures) @property - def texture_current(self): return self.textures[self.current_texture_index] + def tex(self): return self.textures[self.current_texture_index] @property - def texture_next(self): return self.textures[self.next_texture_index] + def tex_next(self): return self.textures[self.next_texture_index] # Main display function def display(self): @@ -48,46 +51,38 @@ class PixDisplay: delta_time = current_time - self.last_time self.last_time = current_time + # Draw black window if no textures are available if not self.textures: - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black + glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glutSwapBuffers() return # Ensure textures are initialized - self.texture_current.gl_init() - self.texture_next.gl_init() + self.tex.gl_init() + self.tex_next.gl_init() # Progress image time self.image_time += delta_time # Get window size - window_width, window_height = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) - - if self.image_time < self.display_duration: - if window_width != self.window_width or window_height != self.window_height: - self.window_width, self.window_height = window_width, window_height - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - - self.renderer.draw_static(self.texture_current, self.window_width, self.window_height, 1) - - glutSwapBuffers() + old_win_w, old_win_h = self.win_w, self.win_h + self.win_w, self.win_h = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) + + # Draw static image except during a transition + if self.image_time <= self.display_duration: + # Avoid redraw unless window size has changed + if self.win_w != old_win_w or self.win_h != old_win_h: + self.renderer.draw_static(self.tex, self.win_w, self.win_h, 1) return - self.window_width, self.window_height = window_width, window_height - - glClearColor(0.0, 0.0, 0.0, 1.0) # Set the background color to black - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - - # DRAW + # Draw transition transition_time = self.image_time - self.display_duration - complete = self.renderer.draw_transition(self.texture_current, self.texture_next, self.window_width, self.window_height, delta_time, transition_time, self.transition_duration) - glutSwapBuffers() + # Draw frame of transition, function will return True if the transition is complete + self.renderer.draw_transition(self.tex, self.tex_next, self.win_w, self.win_h, delta_time, transition_time, self.transition_duration) - if complete: + if transition_time >= self.transition_duration: self.image_time = 0 self.current_texture_index = self.next_texture_index -- cgit v1.2.3 From 9a785dfddad4215672c41396b8554477c18b4066 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 18:22:40 -0500 Subject: transition using arrow keys + skip function --- window.py | 77 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 28 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index ef9e9ee..8b34989 100644 --- a/window.py +++ b/window.py @@ -19,8 +19,13 @@ class PixDisplay: self.win_h = 0 self.max_framerate = 30 - self.display_duration = 2.0 + self.image_duration = 2.0 self.transition_duration = 0.5 + self.auto_transition = True + self.transition_reverse = False + + self.tex = None + self.text_next = None @property def max_framerate(self): @@ -31,17 +36,19 @@ class PixDisplay: self._max_fps = max_fps # This is just for the getter since otherwise e.g. int(1000/int(1000/60)) would round to 62 self.frame_time = int(1000 / 60) # In ms - @property - def prev_texture_index(self): return self.current_texture_index - 1 + def increment_texture_index(self, increment): + if len(self.textures) < 2: + return - @property - def next_texture_index(self): return (self.current_texture_index + 1) % len(self.textures) + self.transition_reverse = increment < 0 - @property - def tex(self): return self.textures[self.current_texture_index] + self.tex_prev = self.textures[self.current_texture_index] + self.current_texture_index = (self.current_texture_index + increment) % len(self.textures) + self.tex = self.textures[self.current_texture_index] - @property - def tex_next(self): return self.textures[self.next_texture_index] + # Ensure textures are initialized + self.tex_prev.gl_init() + self.tex.gl_init() # Main display function def display(self): @@ -51,16 +58,14 @@ class PixDisplay: delta_time = current_time - self.last_time self.last_time = current_time - # Draw black window if no textures are available - if not self.textures: - glClearColor(0.0, 0.0, 0.0, 1.0) - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glutSwapBuffers() - return - - # Ensure textures are initialized - self.tex.gl_init() - self.tex_next.gl_init() + if not self.tex: + self.increment_texture_index(0) + # Draw black window if no textures are available + if not self.tex: + glClearColor(0.0, 0.0, 0.0, 1.0) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glutSwapBuffers() + return # Progress image time self.image_time += delta_time @@ -70,30 +75,45 @@ class PixDisplay: self.win_w, self.win_h = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT) # Draw static image except during a transition - if self.image_time <= self.display_duration: + if self.image_time < self.image_duration: # Avoid redraw unless window size has changed if self.win_w != old_win_w or self.win_h != old_win_h: - self.renderer.draw_static(self.tex, self.win_w, self.win_h, 1) + self.renderer.draw_static(self.tex, self.win_w, self.win_h, 1.0) return - # Draw transition - transition_time = self.image_time - self.display_duration + # Start drawing transition once image_time >= image_duration + if self.auto_transition: + self.increment_texture_index(1) + self.auto_transition = False - # Draw frame of transition, function will return True if the transition is complete - self.renderer.draw_transition(self.tex, self.tex_next, self.win_w, self.win_h, delta_time, transition_time, self.transition_duration) + transition_time = self.image_time - self.image_duration + + self.renderer.draw_transition(self.tex_prev, self.tex, self.win_w, self.win_h, delta_time, transition_time, self.transition_duration, self.transition_reverse) if transition_time >= self.transition_duration: self.image_time = 0 - self.current_texture_index = self.next_texture_index + self.auto_transition = True + # Limit framerate def timer(self, value): glutPostRedisplay() glutTimerFunc(self.frame_time, self.timer, 0) # Schedule next frame + def skip(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) + elif key == GLUT_KEY_RIGHT: + self.skip(1) + # Initialization and main loop - def main(self): + def main(self, glut_args): # Initialize the window - glutInit(sys.argv) + glutInit(glut_args) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutCreateWindow("Image Viewer with Fade Transition") glEnable(GL_TEXTURE_2D) @@ -117,5 +137,6 @@ class PixDisplay: # Run display glutDisplayFunc(self.display) glutTimerFunc(self.frame_time, self.timer, 0) + glutSpecialFunc(self.handle_special_key) glutMainLoop() -- cgit v1.2.3 From fc570fc38b450b90a2c8da05e5619f19ba8e983d Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 18:31:02 -0500 Subject: add force redraw flag and redraw whenever visibility is restored in case framebuffer is destroyed --- window.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 8b34989..8e04225 100644 --- a/window.py +++ b/window.py @@ -27,6 +27,8 @@ class PixDisplay: self.tex = None self.text_next = None + self._force_redraw = False + @property def max_framerate(self): return self._max_fps @@ -76,9 +78,10 @@ class PixDisplay: # Draw static image except during a transition if self.image_time < self.image_duration: - # Avoid redraw unless window size has changed - if self.win_w != old_win_w or self.win_h != old_win_h: + # Avoid unforced-redraw unless window size has changed + if self._force_redraw or self.win_w != old_win_w or self.win_h != old_win_h: self.renderer.draw_static(self.tex, self.win_w, self.win_h, 1.0) + self._force_redraw = False return # Start drawing transition once image_time >= image_duration @@ -110,6 +113,11 @@ class PixDisplay: elif key == GLUT_KEY_RIGHT: self.skip(1) + def handle_visibility_change(self, state): + if state == GLUT_VISIBLE: + self._force_redraw = True + glutPostRedisplay() + # Initialization and main loop def main(self, glut_args): # Initialize the window @@ -137,6 +145,7 @@ class PixDisplay: # Run display glutDisplayFunc(self.display) glutTimerFunc(self.frame_time, self.timer, 0) + glutVisibilityFunc(self.handle_visibility_change) # Redraw in case framebuffer gets destroyed when window is obscured glutSpecialFunc(self.handle_special_key) glutMainLoop() -- cgit v1.2.3 From e7036d21d5e5c87702724283f55a77d07344f4fe Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 10 May 2025 19:47:31 -0500 Subject: add flaskapi --- window.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'window.py') 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: -- cgit v1.2.3 From e1a6fc09afc088dcb67263ed5923f5be41c32c31 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sun, 25 May 2025 21:38:37 -0500 Subject: use lazy caching texture list to limit number of images loaded at one time --- window.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 24320b9..1523f85 100644 --- a/window.py +++ b/window.py @@ -5,16 +5,15 @@ from time import time from queue import Queue from renderer import ImageRenderer, TransitionMix -from texture import ImageTexture class PixDisplay: - def __init__(self): + def __init__(self, textures): self.last_time = 0 self.start_time = 0 self.image_time = 0 self.paused = False - self.textures = [] + self.textures = textures self.current_texture_index = 0 self.renderer = None self.win_w = 0 @@ -42,16 +41,16 @@ class PixDisplay: self.frame_time = int(1000 / 60) # In ms def increment_texture_index(self, increment): - if len(self.textures) < 2: - return - self.transition_reverse = increment < 0 self.tex_prev = self.textures[self.current_texture_index] self.current_texture_index = (self.current_texture_index + increment) % len(self.textures) self.tex = self.textures[self.current_texture_index] - # Ensure textures are initialized + if not self.tex.initialized or not self.tex_prev.initialized: + return + + # Ensure textures are initialized for opengl self.tex_prev.gl_init() self.tex.gl_init() @@ -63,10 +62,10 @@ class PixDisplay: delta_time = current_time - self.last_time self.last_time = current_time - if not self.tex: + if not self.tex or not self.tex.initialized or not self.tex.id: self.increment_texture_index(0) # Draw black window if no textures are available - if not self.tex: + if not self.tex.id: glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glutSwapBuffers() -- cgit v1.2.3 From b8df4605b42d9a61bb4ae4731efabbdc38166063 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 16 Jun 2025 21:50:38 -0500 Subject: add config and add application thread manager --- window.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 1523f85..f422381 100644 --- a/window.py +++ b/window.py @@ -5,7 +5,7 @@ from time import time from queue import Queue from renderer import ImageRenderer, TransitionMix - +from manager import PixMan class PixDisplay: def __init__(self, textures): @@ -18,13 +18,14 @@ class PixDisplay: self.renderer = None self.win_w = 0 self.win_h = 0 - self.max_framerate = 30 - self.image_duration = 2.0 - self.transition_duration = 0.5 - self.auto_transition = True - self.transition_reverse = False + config = PixMan().config + self.max_framerate = config.max_framerate + self.image_duration = config.image_duration + self.transition_duration = config.transition_duration + self.auto_transition = config.auto_transition + self.transition_reverse = False self.text_prev = None self.tex = None @@ -33,12 +34,13 @@ class PixDisplay: @property def max_framerate(self): - return self._max_fps + #return int(1000/int(1000/self.frame_time)) + return self.frame_time @max_framerate.setter def max_framerate(self, max_fps): self._max_fps = max_fps # This is just for the getter since otherwise e.g. int(1000/int(1000/60)) would round to 62 - self.frame_time = int(1000 / 60) # In ms + self.frame_time = int(1000 / max_fps) # In ms def increment_texture_index(self, increment): self.transition_reverse = increment < 0 -- cgit v1.2.3 From 0b0c1978c4f7b57a240575de56b8e40d29c3c219 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 24 Jun 2025 18:34:07 -0500 Subject: live reload window display config --- window.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index f422381..0bb5b3d 100644 --- a/window.py +++ b/window.py @@ -19,12 +19,6 @@ class PixDisplay: self.win_w = 0 self.win_h = 0 - config = PixMan().config - self.max_framerate = config.max_framerate - self.image_duration = config.image_duration - self.transition_duration = config.transition_duration - self.auto_transition = config.auto_transition - self.transition_reverse = False self.text_prev = None self.tex = None @@ -32,6 +26,15 @@ class PixDisplay: self._force_redraw = False self.queue = Queue() + self.update_config() + + def update_config(self): + config = PixMan().config + self.max_framerate = config.max_framerate + self.image_duration = config.image_duration + self.transition_duration = config.transition_duration + self.auto_transition = config.auto_transition + @property def max_framerate(self): #return int(1000/int(1000/self.frame_time)) -- cgit v1.2.3 From 2f03f39e24053377dce108e45fde13ccd1e0ae22 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 24 Jun 2025 18:56:53 -0500 Subject: window can now handle no selected albums --- window.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'window.py') diff --git a/window.py b/window.py index 0bb5b3d..5387930 100644 --- a/window.py +++ b/window.py @@ -35,6 +35,10 @@ class PixDisplay: self.transition_duration = config.transition_duration self.auto_transition = config.auto_transition + def update_textures(self, textures): + self.textures = textures + self.current_texture_index = 0 + @property def max_framerate(self): #return int(1000/int(1000/self.frame_time)) @@ -68,9 +72,10 @@ class PixDisplay: self.last_time = current_time if not self.tex or not self.tex.initialized or not self.tex.id: - self.increment_texture_index(0) + if self.textures.asset_count > 0: + self.increment_texture_index(0) # Draw black window if no textures are available - if not self.tex.id: + if not self.tex or not self.tex.id: glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glutSwapBuffers() -- cgit v1.2.3