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 --- lazycachelist.py | 2 ++ manager.py | 12 +++++++++--- settings.py | 4 ++-- window.py | 9 +++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lazycachelist.py b/lazycachelist.py index 5243def..99212ab 100644 --- a/lazycachelist.py +++ b/lazycachelist.py @@ -150,6 +150,8 @@ class LazyCachingTextureList(): return self.asset_count def __getitem__(self, index): + if not self.asset_count: + raise IndexError("Index out of bounds") i = index % self.asset_count if abs(index) > i: raise IndexError("Index out of bounds") diff --git a/manager.py b/manager.py index 8f7ed80..918a0c4 100644 --- a/manager.py +++ b/manager.py @@ -1,6 +1,7 @@ import os import sys import signal +import copy from threading import Thread from OpenGL.GLUT import glutLeaveMainLoop @@ -49,10 +50,10 @@ class PixMan: signal.signal(signal.SIGINT, PixMan.handle_sigint) self.configfile = configfile - config = Config.load(self.configfile) if os.path.exists(self.configfile) else Config() + self.config = Config.load(self.configfile) if os.path.exists(self.configfile) else Config() self.init_web(host, port) - self.update_config(config, replace=True) + self.update_config(self.config, replace=True) def init_web(self, host, port): self.t_flask = Thread(target=self.app.run, kwargs={ "host": host, "port": port }) @@ -67,7 +68,7 @@ class PixMan: # Initialize texture list change_callback = lambda d: self.socketio.emit("seek", d) - album_keys = [ "38617851-6b57-44f1-b5f7-82577606afc4" ] + album_keys = [ ] self.texture_list = LazyCachingTextureList(album_keys, max_cache_items=self.config.max_cache_assets, change_callback=change_callback) # Begin downloading images @@ -79,6 +80,7 @@ class PixMan: self.display.main({}) # TODO glut args def update_config(self, config, replace=False): + oldconfig = copy.deepcopy(self.config) if replace: self.config = config else: @@ -90,6 +92,10 @@ class PixMan: self.display.update_config() + if oldconfig.album_list != self.config.album_list: + self.texture_list = LazyCachingTextureList(album_keys) + self.display.update_textures() + # If all goes well self.config.save(self.configfile) return True diff --git a/settings.py b/settings.py index e6b3df8..69e40ca 100644 --- a/settings.py +++ b/settings.py @@ -18,8 +18,8 @@ class Config: # Albums data album_list: list[str] = field(default_factory=list) - def __dict__(self): - return asdict(self) + #def __dict__(self): + # return asdict(self) @classmethod def load(cls, filepath): 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