Misc UI work. Colored jobs. Error handling.

This commit is contained in:
Brett Williams
2023-05-31 22:17:47 -05:00
parent 4cb1bff76e
commit f039bfae35
2 changed files with 41 additions and 25 deletions

View File

@@ -49,6 +49,7 @@ class ZordonClient:
# Setup the Tree
self.tree = ttk.Treeview(self.root, show="headings")
self.tree.tag_configure('running', background='lawn green', font=('', 0, 'bold'))
self.tree.bind("<<TreeviewSelect>>", self.on_row_select)
self.tree["columns"] = ("id", "Name", "Renderer", "Priority", "Status", "Time Elapsed", "Frames")
@@ -87,7 +88,6 @@ class ZordonClient:
self.root.geometry("500x600+300+300")
self.root.maxsize(width=2000, height=1200)
self.root.minsize(width=600, height=600)
make_sortable(self.tree)
self.update_jobs()
@@ -95,6 +95,11 @@ class ZordonClient:
self.tree.selection_set(selected_item)
self.start_update_thread()
def server_picked(self, event):
new_hostname = self.server_combo.get()
self.server_proxy.hostname = new_hostname
self.update_jobs(clear_table=True)
def stop_job(self):
selected_item = self.tree.selection()[0] # Get the selected item
row_data = self.tree.item(selected_item) # Get the text of the selected item
@@ -102,26 +107,30 @@ class ZordonClient:
self.server_proxy.request_data(f'job/{job_id}/cancel?confirm=true')
def on_row_select(self, event):
selected_item = self.tree.selection()[0] # Get the selected item
row_data = self.tree.item(selected_item) # Get the text of the selected item
job_id = row_data['values'][0]
if self.tree.selection():
selected_item = self.tree.selection()[0] # Get the selected item
row_data = self.tree.item(selected_item) # Get the text of the selected item
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'
response = requests.get(thumb_url)
if response.status_code == 200:
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
# update thumb
thumb_url = f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/ui/job/{job_id}/thumbnail'
response = requests.get(thumb_url)
if response.status_code == 200:
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
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'
self.stop_button.config(state=button_state)
# 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'
self.stop_button.config(state=button_state)
def reveal_in_finder(self):
selected_item = self.tree.selection()[0] # Get the selected item
@@ -155,19 +164,22 @@ class ZordonClient:
def update_jobs(self, clear_table=False):
def update_row(tree, id, new_values):
def update_row(tree, id, new_values, tags=None):
for item in tree.get_children():
values = tree.item(item, "values")
if values[0] == id:
tree.item(item, values=new_values)
tree.item(item, values=new_values, tags=tags)
break
if clear_table:
self.tree.delete(*self.tree.get_children())
self.job_cache.clear()
job_fetch = self.server_proxy.get_jobs()
if job_fetch:
self.job_cache = job_fetch # update the cache only if its good data
for job in self.job_cache:
display_status = job['status'] if job['status'] != 'running' else job['percent_complete']
display_status = job['status'] if job['status'] != 'running' else \
('%.0f%%' % (job['percent_complete'] * 100)) # if running, show percentage, otherwise just show status
tags = (job['status'],)
values = (job['id'],
job['name'] or os.path.basename(job['input_path']),
job['renderer'] + "-" + job['renderer_version'],
@@ -176,9 +188,9 @@ class ZordonClient:
job['time_elapsed'],
job['total_frames'])
if self.tree.exists(job['id']):
update_row(self.tree, job['id'], new_values=values)
update_row(self.tree, job['id'], new_values=values, tags=tags)
else:
self.tree.insert("", tk.END, iid=job['id'], values=values)
self.tree.insert("", tk.END, iid=job['id'], values=values, tags=tags)
def show_new_job_window(self):
new_window = tk.Toplevel(self.root)

View File

@@ -110,7 +110,11 @@ def get_job_file(job_id, filename):
@server.get('/api/jobs')
def jobs_json():
return [x.json() for x in RenderQueue.all_jobs()]
try:
return [x.json() for x in RenderQueue.all_jobs()]
except Exception as e:
logger.exception(f"Exception fetching all_jobs: {e}")
return [], 500
@server.get('/api/jobs/<status_val>')