mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 16:58:12 +00:00
Fix issue with client not showing up when no jobs available
This commit is contained in:
@@ -40,6 +40,8 @@ def available_servers():
|
||||
|
||||
class ZordonClient:
|
||||
|
||||
default_image = Image.open("../server/static/images/desktop.png")
|
||||
|
||||
def __init__(self):
|
||||
|
||||
servers = available_servers()
|
||||
@@ -56,6 +58,7 @@ class ZordonClient:
|
||||
photo_pad.pack(fill=tk.BOTH, pady=5, padx=5)
|
||||
self.photo_label = tk.Label(photo_pad, height=500)
|
||||
self.photo_label.pack(fill=tk.BOTH, expand=True)
|
||||
self.set_image(self.default_image)
|
||||
|
||||
server_frame = tk.LabelFrame(self.root, text="Server")
|
||||
server_frame.pack(fill=tk.BOTH, pady=5, padx=5, expand=True)
|
||||
@@ -117,12 +120,15 @@ class ZordonClient:
|
||||
self.root.minsize(width=900, height=1000)
|
||||
make_sortable(self.job_tree)
|
||||
|
||||
# update jobs
|
||||
self.update_jobs()
|
||||
try:
|
||||
selected_job = self.job_tree.get_children()[0]
|
||||
self.job_tree.selection_set(selected_job)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
# update servers
|
||||
self.populate_server_tree()
|
||||
try:
|
||||
selected_server = self.server_tree.get_children()[0]
|
||||
@@ -160,6 +166,12 @@ class ZordonClient:
|
||||
self.server_proxy.request_data(f'job/{job_id}/delete?confirm=true')
|
||||
self.update_jobs(clear_table=True)
|
||||
|
||||
def set_image(self, image):
|
||||
thumb_image = ImageTk.PhotoImage(image)
|
||||
if thumb_image:
|
||||
self.photo_label.configure(image=thumb_image)
|
||||
self.photo_label.image = thumb_image
|
||||
|
||||
def on_row_select(self, event):
|
||||
if self.job_tree.selection():
|
||||
selected_item = self.job_tree.selection()[0] # Get the selected item
|
||||
@@ -167,24 +179,22 @@ class ZordonClient:
|
||||
job_id = row_data['values'][0]
|
||||
|
||||
# update thumb
|
||||
thumb_url = f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/ui/job/{job_id}/thumbnail?size=big'
|
||||
response = requests.get(thumb_url)
|
||||
if response.status_code == 200:
|
||||
response = self.server_proxy.request(f'job/{job_id}/thumbnail?size=big')
|
||||
if response.ok:
|
||||
try:
|
||||
import io
|
||||
image_data = response.content
|
||||
image = Image.open(io.BytesIO(image_data))
|
||||
thumb_image = ImageTk.PhotoImage(image)
|
||||
if thumb_image:
|
||||
self.photo_label.configure(image=thumb_image)
|
||||
self.photo_label.image = thumb_image
|
||||
self.set_image(image)
|
||||
except Exception as e:
|
||||
print(f"error getting image: {e}")
|
||||
|
||||
# update button status
|
||||
job = next((d for d in self.job_cache if d.get('id') == job_id), None)
|
||||
button_state = 'normal' if job['status'] == 'running' else 'disabled'
|
||||
button_state = 'normal' if job and job['status'] == 'running' else 'disabled'
|
||||
self.stop_button.config(state=button_state)
|
||||
else:
|
||||
self.set_image(self.default_image)
|
||||
|
||||
def reveal_in_finder(self):
|
||||
selected_item = self.job_tree.selection()[0] # Get the selected item
|
||||
|
||||
@@ -24,13 +24,16 @@ class RenderServerProxy:
|
||||
|
||||
def request_data(self, payload, timeout=5):
|
||||
try:
|
||||
req = requests.get(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout)
|
||||
req = self.request(payload, timeout)
|
||||
if req.ok:
|
||||
return req.json()
|
||||
except Exception as e:
|
||||
pass
|
||||
return None
|
||||
|
||||
def request(self, payload, timeout=5):
|
||||
return requests.get(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout)
|
||||
|
||||
def get_jobs(self):
|
||||
all_jobs = self.request_data('jobs')
|
||||
sorted_jobs = []
|
||||
|
||||
Reference in New Issue
Block a user