# abc **Repository Path**: with-the-flow/abc ## Basic Information - **Project Name**: abc - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-02 - **Last Updated**: 2026-05-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ```python # new_run # 还需改下路径! import tkinter as tk from tkinter import ttk, scrolledtext, messagebox import subprocess import threading import os import re class GradleRunnerApp: def __init__(self, root): self.root = root self.root.title("MCP-Reborn 启动器") self.root.geometry("900x650") self.root.resizable(True, True) # 自动查找 MCP-Reborn 目录 self.mcp_dir = self.find_mcp_dir() self.work_dir = tk.StringVar(value=self.mcp_dir if self.mcp_dir else os.getcwd()) self.command = tk.StringVar(value="gradlew runClient") self.is_running = False self.process = None self.build_ui() def find_mcp_dir(self): """自动查找U盘中的 MCP-Reborn 目录""" for drive in 'DEFGHIJKLMNOPQRSTUVWXYZ': mcp_path = f'{drive}:\\abc\\MCP-Reborn' if os.path.isdir(mcp_path): return mcp_path return None def build_ui(self): # 标题 tk.Label(self.root, text="MCP-Reborn 启动器", font=("微软雅黑", 18, "bold")).pack(pady=8) tk.Label(self.root, text="自动定位U盘中的 MCP-Reborn", font=("微软雅黑", 10), fg='gray').pack() # 工作目录(只读显示) frame_dir = tk.Frame(self.root) frame_dir.pack(fill='x', padx=20, pady=5) tk.Label(frame_dir, text="项目目录:", font=("微软雅黑", 10), width=10, anchor='e').pack(side='left') tk.Entry(frame_dir, textvariable=self.work_dir, font=("Consolas", 10), width=60, state='readonly', fg='green').pack(side='left', padx=5, fill='x', expand=True) tk.Button(frame_dir, text="🔄 刷新", command=self.refresh_dir, font=("微软雅黑", 9), width=8).pack(side='left', padx=5) # 命令输入 frame_cmd = tk.Frame(self.root) frame_cmd.pack(fill='x', padx=20, pady=5) tk.Label(frame_cmd, text="命令:", font=("微软雅黑", 10), width=10, anchor='e').pack(side='left') tk.Entry(frame_cmd, textvariable=self.command, font=("Consolas", 11, "bold"), width=60, fg='#0066cc').pack(side='left', padx=5, fill='x', expand=True) # 按钮区 frame_btn = tk.Frame(self.root) frame_btn.pack(pady=10) self.btn_run = tk.Button(frame_btn, text="▶ 运行", command=self.run_command, font=("微软雅黑", 13, "bold"), bg='#4CAF50', fg='white', width=14, height=2) self.btn_run.pack(side='left', padx=10) self.btn_stop = tk.Button(frame_btn, text="⏹ 停止", command=self.stop_command, font=("微软雅黑", 13), bg='#f44336', fg='white', width=12, height=2, state='disabled') self.btn_stop.pack(side='left', padx=10) self.btn_clear = tk.Button(frame_btn, text="🗑 清空", command=self.clear_output, font=("微软雅黑", 13), bg='#607d8b', fg='white', width=10, height=2) self.btn_clear.pack(side='left', padx=10) # 状态栏 self.status_label = tk.Label(self.root, text="就绪", font=("微软雅黑", 11), fg='gray') self.status_label.pack(pady=3) # 终端输出区域 tk.Label(self.root, text="终端输出:", font=("微软雅黑", 11, "bold")).pack(anchor='w', padx=20, pady=(10,2)) frame_output = tk.Frame(self.root) frame_output.pack(fill='both', expand=True, padx=20, pady=5) self.output_box = scrolledtext.ScrolledText( frame_output, width=100, height=25, font=("Consolas", 10), bg='#1e1e1e', fg='#d4d4d4', insertbackground='white', state='disabled' ) self.output_box.pack(fill='both', expand=True) # 配置颜色标签 self.output_box.tag_config('error', foreground='#f48771') self.output_box.tag_config('success', foreground='#4ec9b0') self.output_box.tag_config('warning', foreground='#dcdcaa') self.output_box.tag_config('info', foreground='#569cd6') def refresh_dir(self): d = self.find_mcp_dir() if d: self.work_dir.set(d) self.status_label.config(text="✓ 已定位项目", fg='green') else: self.status_label.config(text="✗ 未找到 MCP-Reborn", fg='red') messagebox.showwarning("未找到", "U盘中未找到 \\abc\\MCP-Reborn\n请确认路径正确") def append_output(self, text, tag=None): self.output_box.config(state='normal') if tag: self.output_box.insert('end', text, tag) else: self.output_box.insert('end', text) self.output_box.see('end') self.output_box.config(state='disabled') def clear_output(self): self.output_box.config(state='normal') self.output_box.delete(1.0, 'end') self.output_box.config(state='disabled') def detect_tag(self, line): line_lower = line.lower() if any(x in line_lower for x in ['error', 'exception', 'failed', 'fatal']): return 'error' elif any(x in line_lower for x in ['success', 'build successful', 'done', 'complete']): return 'success' elif any(x in line_lower for x in ['warning', 'warn', 'caution']): return 'warning' elif any(x in line_lower for x in ['info:', 'note:', 'debug']): return 'info' return None def run_command(self): work_dir = self.work_dir.get().strip() cmd = self.command.get().strip() if not work_dir or not os.path.isdir(work_dir): messagebox.showerror("错误", "未找到 MCP-Reborn 目录,请检查U盘") return if not cmd: messagebox.showerror("错误", "命令不能为空") return self.is_running = True self.btn_run.config(state='disabled') self.btn_stop.config(state='normal') self.status_label.config(text="运行中...", fg='orange') self.append_output(f"\n{'='*50}\n", 'info') self.append_output(f"[项目目录] {work_dir}\n", 'info') self.append_output(f"[执行命令] {cmd}\n", 'info') self.append_output(f"{'='*50}\n\n", 'info') def execute(): try: if os.name == 'nt': full_cmd = f'cmd /c "{cmd}"' else: full_cmd = cmd self.process = subprocess.Popen( full_cmd, cwd=work_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding='utf-8', errors='replace', shell=True, bufsize=1 ) for line in self.process.stdout: if not self.is_running: break tag = self.detect_tag(line) self.root.after(0, self.append_output, line, tag) self.process.wait() rc = self.process.returncode if rc == 0: self.root.after(0, lambda: self.status_label.config(text="✓ 运行完成", fg='green')) self.root.after(0, self.append_output, f"\n[退出码: {rc}] 运行成功\n", 'success') else: self.root.after(0, lambda: self.status_label.config(text=f"✗ 退出码: {rc}", fg='red')) self.root.after(0, self.append_output, f"\n[退出码: {rc}] 运行异常\n", 'error') except Exception as e: self.root.after(0, self.append_output, f"\n[错误] {str(e)}\n", 'error') self.root.after(0, lambda: self.status_label.config(text="✗ 执行错误", fg='red')) finally: self.is_running = False self.process = None self.root.after(0, lambda: self.btn_run.config(state='normal')) self.root.after(0, lambda: self.btn_stop.config(state='disabled')) threading.Thread(target=execute, daemon=True).start() def stop_command(self): if self.process and self.is_running: try: self.process.terminate() self.append_output("\n[用户] 已发送终止信号\n", 'warning') self.status_label.config(text="已停止", fg='red') except Exception as e: self.append_output(f"\n[错误] 停止失败: {e}\n", 'error') self.is_running = False self.btn_run.config(state='normal') self.btn_stop.config(state='disabled') if __name__ == '__main__': root = tk.Tk() app = GradleRunnerApp(root) root.mainloop() ```