mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Fetch preview images on separate thread
This commit is contained in:
@@ -14,7 +14,7 @@ from lib.server.server_proxy import RenderServerProxy
|
|||||||
sys.path.append("../")
|
sys.path.append("../")
|
||||||
from lib.server.zeroconf_server import ZeroconfServer
|
from lib.server.zeroconf_server import ZeroconfServer
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def sort_column(tree, col, reverse=False):
|
def sort_column(tree, col, reverse=False):
|
||||||
@@ -32,8 +32,8 @@ def make_sortable(tree):
|
|||||||
class DashboardWindow:
|
class DashboardWindow:
|
||||||
|
|
||||||
lib_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
lib_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
image_path = os.path.join(lib_path, 'server', 'static', 'images', 'desktop.png')
|
image_path = os.path.join(lib_path, 'server', 'static', 'images')
|
||||||
default_image = Image.open(image_path)
|
default_image = Image.open(os.path.join(image_path, 'desktop.png'))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
@@ -183,15 +183,22 @@ class DashboardWindow:
|
|||||||
job_id = self.selected_job_id()
|
job_id = self.selected_job_id()
|
||||||
if job_id:
|
if job_id:
|
||||||
# update thumb
|
# update thumb
|
||||||
|
def fetch_preview():
|
||||||
|
hostname = self.server_proxy.hostname
|
||||||
response = self.server_proxy.request(f'job/{job_id}/thumbnail?size=big')
|
response = self.server_proxy.request(f'job/{job_id}/thumbnail?size=big')
|
||||||
if response.ok:
|
if response.ok:
|
||||||
try:
|
try:
|
||||||
import io
|
import io
|
||||||
image_data = response.content
|
image_data = response.content
|
||||||
image = Image.open(io.BytesIO(image_data))
|
image = Image.open(io.BytesIO(image_data))
|
||||||
|
if self.server_proxy.hostname == hostname:
|
||||||
self.set_image(image)
|
self.set_image(image)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"error getting image: {e}")
|
logger.error(f"error fetching image: {e}")
|
||||||
|
|
||||||
|
fetch_thread = threading.Thread(target=fetch_preview)
|
||||||
|
fetch_thread.daemon = True
|
||||||
|
fetch_thread.start()
|
||||||
else:
|
else:
|
||||||
self.set_image(self.default_image)
|
self.set_image(self.default_image)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user