feat: gui now has "add mark" feature for marking log
This commit is contained in:
@@ -19,10 +19,10 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import filedialog, messagebox, scrolledtext
|
from tkinter import filedialog, messagebox, scrolledtext, simpledialog
|
||||||
|
|
||||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
BRIDGE_PATH = os.path.join(SCRIPT_DIR, "s3_bridge.py")
|
BRIDGE_PATH = os.path.join(SCRIPT_DIR, "s3-bridge", "s3_bridge.py")
|
||||||
|
|
||||||
|
|
||||||
class BridgeGUI(tk.Tk):
|
class BridgeGUI(tk.Tk):
|
||||||
@@ -74,6 +74,8 @@ class BridgeGUI(tk.Tk):
|
|||||||
|
|
||||||
tk.Button(self, text="Start", command=self.start_bridge, width=12).grid(row=5, column=0, columnspan=2, **pad)
|
tk.Button(self, text="Start", command=self.start_bridge, width=12).grid(row=5, column=0, columnspan=2, **pad)
|
||||||
tk.Button(self, text="Stop", command=self.stop_bridge, width=12).grid(row=5, column=2, columnspan=2, **pad)
|
tk.Button(self, text="Stop", command=self.stop_bridge, width=12).grid(row=5, column=2, columnspan=2, **pad)
|
||||||
|
self.mark_btn = tk.Button(self, text="Add Mark", command=self.add_mark, width=12, state="disabled")
|
||||||
|
self.mark_btn.grid(row=5, column=4, **pad)
|
||||||
|
|
||||||
# Row 6: Log view
|
# Row 6: Log view
|
||||||
self.log_view = scrolledtext.ScrolledText(self, height=20, width=90, state="disabled")
|
self.log_view = scrolledtext.ScrolledText(self, height=20, width=90, state="disabled")
|
||||||
@@ -135,6 +137,7 @@ class BridgeGUI(tk.Tk):
|
|||||||
args,
|
args,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
|
stdin=subprocess.PIPE,
|
||||||
text=True,
|
text=True,
|
||||||
bufsize=1,
|
bufsize=1,
|
||||||
)
|
)
|
||||||
@@ -145,6 +148,7 @@ class BridgeGUI(tk.Tk):
|
|||||||
threading.Thread(target=self._reader_thread, daemon=True).start()
|
threading.Thread(target=self._reader_thread, daemon=True).start()
|
||||||
self.status_var.set("Running...")
|
self.status_var.set("Running...")
|
||||||
self._append_log("== Bridge started ==\n")
|
self._append_log("== Bridge started ==\n")
|
||||||
|
self.mark_btn.configure(state="normal")
|
||||||
|
|
||||||
def stop_bridge(self) -> None:
|
def stop_bridge(self) -> None:
|
||||||
if self.process and self.process.poll() is None:
|
if self.process and self.process.poll() is None:
|
||||||
@@ -155,6 +159,7 @@ class BridgeGUI(tk.Tk):
|
|||||||
self.process.kill()
|
self.process.kill()
|
||||||
self.status_var.set("Stopped")
|
self.status_var.set("Stopped")
|
||||||
self._append_log("== Bridge stopped ==\n")
|
self._append_log("== Bridge stopped ==\n")
|
||||||
|
self.mark_btn.configure(state="disabled")
|
||||||
|
|
||||||
def _reader_thread(self) -> None:
|
def _reader_thread(self) -> None:
|
||||||
if not self.process or not self.process.stdout:
|
if not self.process or not self.process.stdout:
|
||||||
@@ -163,12 +168,28 @@ class BridgeGUI(tk.Tk):
|
|||||||
self.stdout_q.put(line)
|
self.stdout_q.put(line)
|
||||||
self.stdout_q.put("<<process-exit>>")
|
self.stdout_q.put("<<process-exit>>")
|
||||||
|
|
||||||
|
def add_mark(self) -> None:
|
||||||
|
if not self.process or not self.process.stdin or self.process.poll() is not None:
|
||||||
|
return
|
||||||
|
label = simpledialog.askstring("Mark", "Enter label for mark:", parent=self)
|
||||||
|
if label is None or label.strip() == "":
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
# Mimic CLI behavior: send 'm' + Enter, then label + Enter
|
||||||
|
self.process.stdin.write("m\n")
|
||||||
|
self.process.stdin.write(label.strip() + "\n")
|
||||||
|
self.process.stdin.flush()
|
||||||
|
self._append_log(f"[GUI] Mark sent: {label.strip()}\n")
|
||||||
|
except Exception as e:
|
||||||
|
messagebox.showerror("Error", f"Failed to send mark: {e}")
|
||||||
|
|
||||||
def _poll_stdout(self) -> None:
|
def _poll_stdout(self) -> None:
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
line = self.stdout_q.get_nowait()
|
line = self.stdout_q.get_nowait()
|
||||||
if line == "<<process-exit>>":
|
if line == "<<process-exit>>":
|
||||||
self.status_var.set("Stopped")
|
self.status_var.set("Stopped")
|
||||||
|
self.mark_btn.configure(state="disabled")
|
||||||
break
|
break
|
||||||
self._append_log(line)
|
self._append_log(line)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
|
|||||||
Reference in New Issue
Block a user