From 21557cf4eda481efc160a3f0e7a9f22f57594daf Mon Sep 17 00:00:00 2001 From: Brett Williams Date: Mon, 5 Jun 2023 10:58:43 -0500 Subject: [PATCH] Client allows stopping / deleting multiple jobs simultaniously --- lib/client/dashboard_window.py | 58 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/client/dashboard_window.py b/lib/client/dashboard_window.py index 437771e..3c074de 100644 --- a/lib/client/dashboard_window.py +++ b/lib/client/dashboard_window.py @@ -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("<>", 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,26 +152,31 @@ 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() - self.server_proxy.request_data(f'job/{job_id}/cancel?confirm=true') + 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) - 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}?") + 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']) + 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: - self.server_proxy.request_data(f'job/{job_id}/delete?confirm=true') + 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,13 +215,15 @@ 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) - output_dir = os.path.dirname(job['output_path']) - launch_url(output_dir) + 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' - launch_url(url) + 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): self.root.mainloop()