Here's the entire updated code with the "Set Workspace" button added and all previous changes:
import os
import uuid
import json
import tkinter as tk
from tkinter import Frame, Button, Listbox, Tk, filedialog, messagebox, simpledialog, Toplevel, Label, BOTH, DISABLED, NORMAL
import webbrowser
class Pipeline:
def __init__(self, workspace, pipeline_id=None):
self.id = pipeline_id or str(uuid.uuid4())
self.workspace = os.path.join(workspace, self.id)
os.makedirs(self.workspace, exist_ok=True)
self.status = 'Not started'
def save_pipeline(self):
with open(os.path.join(self.workspace, 'pipeline.json'), 'w') as f:
json.dump({'id': self.id, 'workspace': self.workspace, 'status': self.status}, f)
class OutputDirectoriesWindow(Toplevel):
def __init__(self, master, pipeline):
super().__init__(master)
self.title("Output Directories")
self.pipeline = pipeline
self.init_ui()
def init_ui(self):
directory_names = ['raw_data', 'processed_data', 'associated_data', 'combined_data', 'package']
for name in directory_names:
directory_path = os.path.join(self.pipeline.workspace, name)
label = Label(self, text=directory_path, fg="blue", cursor="hand2")
label.pack(padx=(10, 10), pady=(5, 5))
label.bind("<Button-1>", lambda event, path=directory_path: self.open_directory(path))
def open_directory(self, path):
webbrowser.open(f'file://{path}')
class PipelineManager(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.workspace = None
self.pipelines = []
self.init_ui()
def init_ui(self):
self.set_workspace_button = Button(self, text="Set Workspace", command=self.set_workspace)
self.set_workspace_button.pack(pady=(10, 10))
self.create_pipeline_button = Button(self, text="Create Pipeline", command=self.create_pipeline, state=DISABLED)
self.create_pipeline_button.pack(pady=(10, 10))
self.pipeline_listbox = Listbox(self)
self.pipeline_listbox.pack(fill=BOTH, expand=True, padx=(10, 10), pady=(10, 10))
self.show_outputs_button = Button(self, text="Show Output Directories", command=self.show_output_directories)
self.show_outputs_button.pack(pady=(10, 10))
def set_workspace(self):
workspace = filedialog.askdirectory(title='Select Workspace')
if workspace:
self.workspace = workspace
self.create_pipeline_button.config(state=NORMAL)
def create_pipeline(self):
if not self.workspace:
messagebox.showwarning("Warning", "Workspace not set")
return
pipeline_id = simpledialog.askstring("Pipeline ID", "Enter a human-readable ID for the pipeline:")
if not pipeline_id:
return
pipeline = Pipeline(self.workspace, pipeline_id)
pipeline.save_pipeline()
self.pipelines.append(pipeline)
self.add_pipeline_to_listbox(pipeline)
def add_pipeline_to_listbox(self, pipeline):
self.pipeline_listbox.insert(tk.END, f"{pipeline.id} - {pipeline.workspace}")
def show_output_directories(self):
selected_index = self.pipeline_listbox.curselection()
if not selected_index:
messagebox.showwarning("Warning", "No pipeline selected")
return
pipeline = self.pipelines[selected_index[0]]
OutputDirectoriesWindow(self.master, pipeline)
if __name__ == '__main__':
root = Tk()
root.geometry("800x600")
app = PipelineManager(master=root)
app.mainloop()
This complete code includes the "Set Workspace" button, the option to provide a custom pipeline ID, and the ability to view and open output directories for the selected pipeline.
Here's the entire updated code with the "Set Workspace" button added and all previous changes:
This complete code includes the "Set Workspace" button, the option to provide a custom pipeline ID, and the ability to view and open output directories for the selected pipeline.