mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Client allows stopping / deleting multiple jobs simultaniously
This commit is contained in:
@@ -71,10 +71,11 @@ class DashboardWindow:
|
||||
separator.pack(side=tk.LEFT, padx=5, pady=5, fill=tk.Y)
|
||||
|
||||
# Setup the Tree
|
||||
self.job_tree = ttk.Treeview(server_frame, show="headings", height=10)
|
||||
self.job_tree = ttk.Treeview(server_frame, show="headings")
|
||||
self.job_tree.tag_configure('running', background='lawn green', font=('', 0, 'bold'))
|
||||
self.job_tree.bind("<<TreeviewSelect>>", self.on_row_select)
|
||||
self.job_tree["columns"] = ("id", "Name", "Renderer", "Priority", "Status", "Time Elapsed", "Frames", "")
|
||||
self.job_tree["columns"] = ("id", "Name", "Renderer", "Priority", "Status", "Time Elapsed", "Frames",
|
||||
"Date Added", "Owner", "")
|
||||
|
||||
# Format the columns
|
||||
self.job_tree.column("id", width=0, stretch=False)
|
||||
@@ -84,6 +85,8 @@ class DashboardWindow:
|
||||
self.job_tree.column("Status", width=100, stretch=False)
|
||||
self.job_tree.column("Time Elapsed", width=100, stretch=False)
|
||||
self.job_tree.column("Frames", width=50, stretch=False)
|
||||
self.job_tree.column("Date Added", width=150, stretch=True)
|
||||
self.job_tree.column("Owner", width=250, stretch=True)
|
||||
|
||||
# Create the column headings
|
||||
for name in self.job_tree['columns']:
|
||||
@@ -149,25 +152,30 @@ class DashboardWindow:
|
||||
self.job_cache.clear()
|
||||
self.update_jobs(clear_table=True)
|
||||
|
||||
def selected_job_id(self):
|
||||
try:
|
||||
selected_item = self.job_tree.selection()[0] # Get the selected item
|
||||
row_data = self.job_tree.item(selected_item) # Get the text of the selected item
|
||||
job_id = row_data['values'][0]
|
||||
return job_id
|
||||
except Exception as e:
|
||||
return None
|
||||
def selected_job_ids(self):
|
||||
selected_items = self.job_tree.selection() # Get the selected item
|
||||
row_data = [self.job_tree.item(item) for item in selected_items] # Get the text of the selected item
|
||||
job_ids = [row['values'][0] for row in row_data]
|
||||
return job_ids
|
||||
|
||||
def stop_job(self):
|
||||
job_id = self.selected_job_id()
|
||||
job_ids = self.selected_job_ids()
|
||||
for job_id in job_ids:
|
||||
self.server_proxy.request_data(f'job/{job_id}/cancel?confirm=true')
|
||||
self.update_jobs(clear_table=True)
|
||||
|
||||
def delete_job(self):
|
||||
job_id = self.selected_job_id()
|
||||
job = next((d for d in self.job_cache if d.get('id') == job_id), None)
|
||||
job_ids = self.selected_job_ids()
|
||||
if len(job_ids) == 1:
|
||||
job = next((d for d in self.job_cache if d.get('id') == job_ids[0]), None)
|
||||
display_name = job['name'] or os.path.basename(job['input_path'])
|
||||
result = messagebox.askyesno("Confirmation", f"Are you sure you want to delete the job:\n{display_name}?")
|
||||
message = f"Are you sure you want to delete the job:\n{display_name}?"
|
||||
else:
|
||||
message = f"Are you sure you want to delete these {len(job_ids)} jobs?"
|
||||
|
||||
result = messagebox.askyesno("Confirmation", message)
|
||||
if result:
|
||||
for job_id in job_ids:
|
||||
self.server_proxy.request_data(f'job/{job_id}/delete?confirm=true')
|
||||
self.job_cache.clear()
|
||||
self.update_jobs(clear_table=True)
|
||||
@@ -179,7 +187,7 @@ class DashboardWindow:
|
||||
self.photo_label.image = thumb_image
|
||||
|
||||
def on_row_select(self, event):
|
||||
job_id = self.selected_job_id()
|
||||
job_id = self.selected_job_ids()[0] if self.selected_job_ids() else None
|
||||
if job_id:
|
||||
# update thumb
|
||||
def fetch_preview():
|
||||
@@ -190,7 +198,7 @@ class DashboardWindow:
|
||||
import io
|
||||
image_data = response.content
|
||||
image = Image.open(io.BytesIO(image_data))
|
||||
if self.server_proxy.hostname == hostname and job_id == self.selected_job_id():
|
||||
if self.server_proxy.hostname == hostname and job_id == self.selected_job_ids()[0]:
|
||||
self.set_image(image)
|
||||
except Exception as e:
|
||||
logger.error(f"error fetching image: {e}")
|
||||
@@ -207,12 +215,14 @@ class DashboardWindow:
|
||||
self.stop_button.config(state=button_state)
|
||||
|
||||
def reveal_in_finder(self):
|
||||
job = next((d for d in self.job_cache if d.get('id') == self.selected_job_id()), None)
|
||||
if self.selected_job_ids():
|
||||
job = next((d for d in self.job_cache if d.get('id') == self.selected_job_ids()[0]), None)
|
||||
output_dir = os.path.dirname(job['output_path'])
|
||||
launch_url(output_dir)
|
||||
|
||||
def open_logs(self):
|
||||
url = f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/api/job/{self.selected_job_id()}/logs'
|
||||
if self.selected_job_ids():
|
||||
url = f'http://{self.server_proxy.hostname}:{self.server_proxy.port}/api/job/{self.selected_job_ids()[0]}/logs'
|
||||
launch_url(url)
|
||||
|
||||
def mainloop(self):
|
||||
|
||||
Reference in New Issue
Block a user