Files

80 lines
2.6 KiB
Python

import subprocess
import threading
import tkinter as tk
from tkinter import messagebox, scrolledtext
SCRIPT_PATH = "../start-stack.sh"
class StackLauncher(tk.Tk):
def __init__(self):
super().__init__()
self.title("Traduttore Stack Helper")
self.geometry("600x360")
self.resizable(False, False)
btn_frame = tk.Frame(self)
btn_frame.pack(padx=12, pady=8, fill=tk.X)
self.start_button = tk.Button(btn_frame, text="Avvia stack completo", command=self.start_stack)
self.start_button.pack(side=tk.LEFT, padx=(0, 8))
self.status_label = tk.Label(btn_frame, text="Stato: inattivo", anchor="w")
self.status_label.pack(side=tk.LEFT, fill=tk.X, expand=True)
self.log_text = scrolledtext.ScrolledText(self, state="disabled", wrap=tk.WORD)
self.log_text.pack(fill=tk.BOTH, expand=True, padx=12, pady=(0, 12))
self.process = None
def start_stack(self):
if self.process and self.process.poll() is None:
messagebox.showinfo("In esecuzione", "Lo stack è già in fase di avvio.")
return
self.start_button.config(state="disabled")
self.status_label.config(text="Stato: avvio");
self.log_text.configure(state="normal")
self.log_text.delete("1.0", tk.END)
self.log_text.configure(state="disabled")
thread = threading.Thread(target=self._run_script, daemon=True)
thread.start()
self.after(200, self._poll_process)
def _run_script(self):
self.process = subprocess.Popen(
["/bin/bash", "start-stack.sh"],
cwd="..",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
)
if not self.process.stdout:
return
for line in self.process.stdout:
self._append_log(line)
self.process.wait()
self._append_log(f"Processo terminato con codice {self.process.returncode}\n")
def _poll_process(self):
if self.process and self.process.poll() is None:
self.after(200, self._poll_process)
else:
self.start_button.config(state="normal")
status = "completato" if self.process and self.process.returncode == 0 else "errore"
self.status_label.config(text=f"Stato: {status}")
def _append_log(self, value: str) -> None:
self.log_text.configure(state="normal")
self.log_text.insert(tk.END, value)
self.log_text.see(tk.END)
self.log_text.configure(state="disabled")
if __name__ == "__main__":
app = StackLauncher()
app.mainloop()