From fbf3b8f1efdaec42907527497c7ec347c7dbac83 Mon Sep 17 00:00:00 2001 From: UnCLAS-Prommer Date: Thu, 29 May 2025 20:14:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=82=B8=E9=A3=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/experimental/only_message_process.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/experimental/only_message_process.py b/src/experimental/only_message_process.py index 8fb1e3bf2..6dd70ca7f 100644 --- a/src/experimental/only_message_process.py +++ b/src/experimental/only_message_process.py @@ -2,7 +2,11 @@ from src.common.logger_manager import get_logger from src.chat.message_receive.message import MessageRecv from src.chat.message_receive.storage import MessageStorage from src.config.config import global_config +from src.chat.message_receive.chat_stream import ChatStream + +from maim_message import UserInfo from datetime import datetime +import re logger = get_logger("pfc") @@ -14,7 +18,7 @@ class MessageProcessor: self.storage = MessageStorage() @staticmethod - def _check_ban_words(text: str, chat, userinfo) -> bool: + def _check_ban_words(text: str, chat: ChatStream, userinfo: UserInfo) -> bool: """检查消息中是否包含过滤词""" for word in global_config.message_receive.ban_words: if word in text: @@ -26,13 +30,12 @@ class MessageProcessor: return False @staticmethod - def _check_ban_regex(text: str, chat, userinfo) -> bool: + def _check_ban_regex(text: str, chat: ChatStream, userinfo: UserInfo) -> bool: """检查消息是否匹配过滤正则表达式""" - for pattern in global_config.chat.ban_msgs_regex: - if pattern.search(text): - logger.info( - f"[{chat.group_info.group_name if chat.group_info else '私聊'}]{userinfo.user_nickname}:{text}" - ) + for pattern in global_config.message_receive.ban_msgs_regex: + if re.search(pattern, text): + chat_name = chat.group_info.group_name if chat.group_info else "私聊" + logger.info(f"[{chat_name}]{userinfo.user_nickname}:{text}") logger.info(f"[正则表达式过滤]消息匹配到{pattern},filtered") return True return False From 162f7965720d842a2db0ef0a63975270ec9a4c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Thu, 29 May 2025 20:20:33 +0800 Subject: [PATCH 2/3] fix: Ruff --- scripts/070configexe.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/070configexe.py b/scripts/070configexe.py index a6cd5b51d..956905ec2 100644 --- a/scripts/070configexe.py +++ b/scripts/070configexe.py @@ -3,7 +3,7 @@ from tkinter import ttk, messagebox import tomli import tomli_w import os -from typing import Any, Dict, List, Union +from typing import Any, Dict, List import threading import time @@ -615,7 +615,8 @@ class ConfigEditor: "type": widget_type }) # 保存到configexe.toml - import tomli_w, os + import tomli_w + import os config_path = os.path.join(os.path.dirname(__file__), "configexe.toml") with open(config_path, "wb") as f: tomli_w.dump(self.editor_config, f) @@ -631,7 +632,7 @@ class ConfigEditor: def main(): root = tk.Tk() - app = ConfigEditor(root) + _app = ConfigEditor(root) root.mainloop() if __name__ == "__main__": From 3996d8623ca8fb1b2fd7c6645357d0df19fe6d10 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 29 May 2025 12:20:47 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/070configexe.py | 263 ++++++++++++++++++++++------------------ 1 file changed, 142 insertions(+), 121 deletions(-) diff --git a/scripts/070configexe.py b/scripts/070configexe.py index 956905ec2..88871aaf2 100644 --- a/scripts/070configexe.py +++ b/scripts/070configexe.py @@ -7,46 +7,47 @@ from typing import Any, Dict, List import threading import time + class ConfigEditor: def __init__(self, root): self.root = root self.root.title("麦麦配置编辑器") - + # 加载编辑器配置 self.load_editor_config() - + # 设置窗口大小 self.root.geometry(f"{self.window_width}x{self.window_height}") - + # 加载配置 self.load_config() - + # 自动保存相关 self.last_save_time = time.time() self.save_timer = None self.save_lock = threading.Lock() self.current_section = None # 当前编辑的节 self.pending_save = False # 是否有待保存的更改 - + # 存储控件的字典 self.widgets = {} - + # 创建主框架 self.main_frame = ttk.Frame(self.root, padding="10") self.main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) - + # 创建版本号显示 self.create_version_label() - + # 创建左侧导航栏 self.create_navbar() - + # 创建右侧编辑区 self.create_editor() - + # 创建底部按钮 self.create_buttons() - + # 配置网格权重 self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=1) @@ -59,21 +60,21 @@ class ConfigEditor: editor_config_path = os.path.join(os.path.dirname(__file__), "configexe.toml") with open(editor_config_path, "rb") as f: self.editor_config = tomli.load(f) # 保存整个配置对象 - + # 设置配置路径 self.config_path = self.editor_config["config"]["bot_config_path"] # 如果路径是相对路径,转换为绝对路径 if not os.path.isabs(self.config_path): self.config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), self.config_path) - + # 设置编辑器参数 self.window_width = self.editor_config["editor"]["window_width"] self.window_height = self.editor_config["editor"]["window_height"] self.save_delay = self.editor_config["editor"]["save_delay"] - + # 加载翻译 self.translations = self.editor_config.get("translations", {}) - + except Exception as e: messagebox.showerror("错误", f"加载编辑器配置失败: {str(e)}") # 使用默认值 @@ -97,7 +98,7 @@ class ConfigEditor: version = self.config.get("inner", {}).get("version", "未知版本") version_frame = ttk.Frame(self.main_frame) version_frame.grid(row=0, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=(0, 10)) - + version_label = ttk.Label(version_frame, text=f"麦麦版本:{version}", font=("", 10, "bold")) version_label.pack(side=tk.LEFT, padx=5) @@ -105,14 +106,14 @@ class ConfigEditor: # 创建左侧导航栏 self.nav_frame = ttk.Frame(self.main_frame, padding="5") self.nav_frame.grid(row=1, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) - + # 创建导航树 self.tree = ttk.Treeview(self.nav_frame) self.tree.pack(fill=tk.BOTH, expand=True) - + # 添加快捷设置节 self.tree.insert("", "end", text="快捷设置", values=("quick_settings",)) - + # 添加配置项到树 for section in self.config: if section != "inner": # 跳过inner部分 @@ -120,7 +121,7 @@ class ConfigEditor: section_trans = self.translations.get("sections", {}).get(section, {}) section_name = section_trans.get("name", section) self.tree.insert("", "end", text=section_name, values=(section,)) - + # 绑定选择事件 self.tree.bind("<>", self.on_section_select) @@ -128,28 +129,28 @@ class ConfigEditor: # 创建右侧编辑区 self.editor_frame = ttk.Frame(self.main_frame, padding="5") self.editor_frame.grid(row=1, column=1, sticky=(tk.W, tk.E, tk.N, tk.S)) - + # 创建编辑区标题 self.editor_title = ttk.Label(self.editor_frame, text="") self.editor_title.pack(fill=tk.X) - + # 创建编辑区内容 self.editor_content = ttk.Frame(self.editor_frame) self.editor_content.pack(fill=tk.BOTH, expand=True) - + # 创建滚动条 self.scrollbar = ttk.Scrollbar(self.editor_content) self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y) - + # 创建画布和框架 self.canvas = tk.Canvas(self.editor_content, yscrollcommand=self.scrollbar.set) self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) self.scrollbar.config(command=self.canvas.yview) - + # 创建内容框架 self.content_frame = ttk.Frame(self.canvas) self.canvas.create_window((0, 0), window=self.content_frame, anchor=tk.NW) - + # 绑定画布大小变化事件 self.content_frame.bind("", self.on_frame_configure) self.canvas.bind("", self.on_canvas_configure) @@ -165,7 +166,7 @@ class ConfigEditor: # 创建底部按钮区 self.button_frame = ttk.Frame(self.main_frame, padding="5") self.button_frame.grid(row=2, column=0, columnspan=2, sticky=(tk.W, tk.E)) - + # 刷新按钮 self.refresh_button = ttk.Button(self.button_frame, text="刷新", command=self.refresh_config) self.refresh_button.pack(side=tk.RIGHT, padx=5) @@ -174,12 +175,12 @@ class ConfigEditor: """为不同类型的值创建对应的编辑控件""" frame = ttk.Frame(parent) frame.pack(fill=tk.X, padx=5, pady=2) - + # --- 修改开始: 改进翻译查找逻辑 --- full_config_path_key = ".".join(path + [key]) # 例如 "chinese_typo.enable" - + item_name_to_display = key # 默认显示原始键名 - item_desc_to_display = "" # 默认无描述 + item_desc_to_display = "" # 默认无描述 # 1. 尝试使用完整路径的特定翻译 specific_translation = self.translations.get("items", {}).get(full_config_path_key) @@ -193,28 +194,33 @@ class ConfigEditor: item_name_to_display = generic_translation.get("name") item_desc_to_display = generic_translation.get("description", "") # --- 修改结束 --- - + # 配置名(大号字体) label = ttk.Label(frame, text=item_name_to_display, font=("", 20, "bold")) label.grid(row=0, column=0, sticky=tk.W, padx=5, pady=(0, 0)) - + # 星星图标快捷设置(与配置名同一行) - content_col_offset_for_star = 1 # 星标按钮占一列 + content_col_offset_for_star = 1 # 星标按钮占一列 quick_settings = self.editor_config.get("editor", {}).get("quick_settings", {}).get("items", []) already_in_quick = any(item.get("path") == full_config_path_key for item in quick_settings) icon = "★" if already_in_quick else "☆" icon_fg = "#FFD600" # 始终金色 + def on_star_click(): - self.toggle_quick_setting(full_config_path_key, widget_type, item_name_to_display, item_desc_to_display, already_in_quick) + self.toggle_quick_setting( + full_config_path_key, widget_type, item_name_to_display, item_desc_to_display, already_in_quick + ) # 立即刷新本分组 for widget in parent.winfo_children(): widget.destroy() self.widgets.clear() # 重新渲染本分组 - if hasattr(self, 'current_section') and self.current_section and self.current_section != "quick_settings": - self.create_section_widgets(parent, self.current_section, self.config[self.current_section], [self.current_section]) - elif hasattr(self, 'current_section') and self.current_section == "quick_settings": - self.create_quick_settings_widgets() # 如果当前是快捷设置,也刷新它 + if hasattr(self, "current_section") and self.current_section and self.current_section != "quick_settings": + self.create_section_widgets( + parent, self.current_section, self.config[self.current_section], [self.current_section] + ) + elif hasattr(self, "current_section") and self.current_section == "quick_settings": + self.create_quick_settings_widgets() # 如果当前是快捷设置,也刷新它 pin_btn = ttk.Button(frame, text=icon, width=2, command=on_star_click) pin_btn.grid(row=0, column=content_col_offset_for_star, sticky=tk.W, padx=5) @@ -229,70 +235,76 @@ class ConfigEditor: desc_row = 1 if item_desc_to_display: desc_label = ttk.Label(frame, text=item_desc_to_display, foreground="gray", font=("", 16)) - desc_label.grid(row=desc_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5, pady=(0, 4)) - widget_row = desc_row + 1 # 内容控件在描述下方 + desc_label.grid( + row=desc_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5, pady=(0, 4) + ) + widget_row = desc_row + 1 # 内容控件在描述下方 else: - widget_row = desc_row # 内容控件直接在第二行 + widget_row = desc_row # 内容控件直接在第二行 # 配置内容控件(第三行或第二行) if path[0] == "inner": value_label = ttk.Label(frame, text=str(value), font=("", 20)) - value_label.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W, padx=5) + value_label.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5) return - + if isinstance(value, bool): # 布尔值使用复选框 var = tk.BooleanVar(value=value) checkbox = ttk.Checkbutton(frame, variable=var, command=lambda: self.on_value_changed()) - checkbox.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W, padx=5) + checkbox.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W, padx=5) self.widgets[tuple(path + [key])] = var widget_type = "bool" - + elif isinstance(value, (int, float)): # 数字使用数字输入框 var = tk.StringVar(value=str(value)) entry = ttk.Entry(frame, textvariable=var, font=("", 20)) - entry.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W+tk.E, padx=5) + entry.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W + tk.E, padx=5) var.trace_add("write", lambda *args: self.on_value_changed()) self.widgets[tuple(path + [key])] = var widget_type = "number" - + elif isinstance(value, list): # 列表使用每行一个输入框的形式 frame_list = ttk.Frame(frame) - frame_list.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W+tk.E, padx=5) - + frame_list.grid( + row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W + tk.E, padx=5 + ) + # 创建添加和删除按钮 button_frame = ttk.Frame(frame_list) button_frame.pack(side=tk.RIGHT, padx=5) - - add_button = ttk.Button(button_frame, text="+", width=3, command=lambda p=path + [key]: self.add_list_item(frame_list, p)) + + add_button = ttk.Button( + button_frame, text="+", width=3, command=lambda p=path + [key]: self.add_list_item(frame_list, p) + ) add_button.pack(side=tk.TOP, pady=2) - + # 创建列表项框架 items_frame = ttk.Frame(frame_list) items_frame.pack(side=tk.LEFT, fill=tk.X, expand=True) - + # 存储所有输入框的变量 entry_vars = [] - + # 为每个列表项创建输入框 for i, item in enumerate(value): self.create_list_item(items_frame, item, i, entry_vars, path + [key]) - + # 存储控件引用 self.widgets[tuple(path + [key])] = (items_frame, entry_vars) widget_type = "list" - + else: # 其他类型(字符串等)使用普通文本框 var = tk.StringVar(value=str(value)) entry = ttk.Entry(frame, textvariable=var, font=("", 20)) - entry.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star +1, sticky=tk.W+tk.E, padx=5) + entry.grid(row=widget_row, column=0, columnspan=content_col_offset_for_star + 1, sticky=tk.W + tk.E, padx=5) var.trace_add("write", lambda *args: self.on_value_changed()) self.widgets[tuple(path + [key])] = var widget_type = "text" - + def create_section_widgets(self, parent: ttk.Frame, section: str, data: Dict, path=None) -> None: """为配置节创建编辑控件""" if path is None: @@ -301,20 +313,20 @@ class ConfigEditor: section_trans = self.translations.get("sections", {}).get(section, {}) section_name = section_trans.get("name", section) section_desc = section_trans.get("description", "") - + # 创建节的标签框架 section_frame = ttk.Frame(parent) section_frame.pack(fill=tk.X, padx=5, pady=10) - + # 创建节的名称标签 section_label = ttk.Label(section_frame, text=f"[{section_name}]", font=("", 12, "bold")) section_label.pack(side=tk.LEFT, padx=5) - + # 创建节的描述标签 if section_desc: desc_label = ttk.Label(section_frame, text=f"({section_desc})", foreground="gray") desc_label.pack(side=tk.LEFT, padx=5) - + # 为每个配置项创建对应的控件 for key, value in data.items(): if isinstance(value, dict): @@ -335,14 +347,14 @@ class ConfigEditor: # 如果有待保存的更改,先保存 if self.pending_save: self.save_config() - + selection = self.tree.selection() if not selection: return - + section = self.tree.item(selection[0])["values"][0] # 使用values中的原始节名 self.current_section = section - + # 获取节的中文名称 if section == "quick_settings": section_name = "快捷设置" @@ -350,14 +362,14 @@ class ConfigEditor: section_trans = self.translations.get("sections", {}).get(section, {}) section_name = section_trans.get("name", section) self.editor_title.config(text=f"编辑 {section_name}") - + # 清空编辑器 for widget in self.content_frame.winfo_children(): widget.destroy() - + # 清空控件字典 self.widgets.clear() - + # 创建编辑控件 if section == "quick_settings": self.create_quick_settings_widgets() @@ -368,75 +380,80 @@ class ConfigEditor: """创建快捷设置编辑界面""" # 获取快捷设置配置 quick_settings = self.editor_config.get("editor", {}).get("quick_settings", {}).get("items", []) - + # 创建快捷设置控件 for setting in quick_settings: frame = ttk.Frame(self.content_frame) frame.pack(fill=tk.X, padx=5, pady=2) - + # 获取当前值 path = setting["path"].split(".") current = self.config for key in path[:-1]: # 除了最后一个键 current = current.get(key, {}) value = current.get(path[-1]) # 获取最后一个键的值 - + # 创建名称标签 name_label = ttk.Label(frame, text=setting["name"], font=("", 18)) name_label.pack(fill=tk.X, padx=5, pady=(2, 0)) - + # 创建描述标签 if setting.get("description"): - desc_label = ttk.Label(frame, text=setting['description'], foreground="gray", font=("", 16)) + desc_label = ttk.Label(frame, text=setting["description"], foreground="gray", font=("", 16)) desc_label.pack(fill=tk.X, padx=5, pady=(0, 2)) - + # 根据类型创建不同的控件 setting_type = setting.get("type", "bool") - + if setting_type == "bool": value = bool(value) if value is not None else False var = tk.BooleanVar(value=value) - checkbox = ttk.Checkbutton(frame, text="", - variable=var, - command=lambda p=path, v=var: self.on_quick_setting_changed(p, v)) - checkbox.pack(anchor=tk.W, padx=5, pady=(0,5)) - + checkbox = ttk.Checkbutton( + frame, text="", variable=var, command=lambda p=path, v=var: self.on_quick_setting_changed(p, v) + ) + checkbox.pack(anchor=tk.W, padx=5, pady=(0, 5)) + elif setting_type == "text": value = str(value) if value is not None else "" var = tk.StringVar(value=value) entry = ttk.Entry(frame, textvariable=var, width=40, font=("", 18)) - entry.pack(fill=tk.X, padx=5, pady=(0,5)) + entry.pack(fill=tk.X, padx=5, pady=(0, 5)) var.trace_add("write", lambda *args, p=path, v=var: self.on_quick_setting_changed(p, v)) - + elif setting_type == "number": value = str(value) if value is not None else "0" var = tk.StringVar(value=value) entry = ttk.Entry(frame, textvariable=var, width=10, font=("", 18)) - entry.pack(fill=tk.X, padx=5, pady=(0,5)) + entry.pack(fill=tk.X, padx=5, pady=(0, 5)) var.trace_add("write", lambda *args, p=path, v=var: self.on_quick_setting_changed(p, v)) - + elif setting_type == "list": # 对于列表类型,创建一个按钮来打开编辑窗口 - button = ttk.Button(frame, text="编辑列表", - command=lambda p=path, s=setting: self.open_list_editor(p, s)) - button.pack(anchor=tk.W, padx=5, pady=(0,5)) + button = ttk.Button( + frame, text="编辑列表", command=lambda p=path, s=setting: self.open_list_editor(p, s) + ) + button.pack(anchor=tk.W, padx=5, pady=(0, 5)) def create_list_item(self, parent, value, index, entry_vars, path): """创建单个列表项的输入框""" item_frame = ttk.Frame(parent) item_frame.pack(fill=tk.X, pady=1) - + # 创建输入框 var = tk.StringVar(value=str(value)) entry = ttk.Entry(item_frame, textvariable=var) entry.pack(side=tk.LEFT, fill=tk.X, expand=True, padx=5) var.trace_add("write", lambda *args: self.on_value_changed()) - + # 创建删除按钮 - del_button = ttk.Button(item_frame, text="-", width=3, - command=lambda: self.remove_list_item(parent, item_frame, entry_vars, index, path)) + del_button = ttk.Button( + item_frame, + text="-", + width=3, + command=lambda: self.remove_list_item(parent, item_frame, entry_vars, index, path), + ) del_button.pack(side=tk.RIGHT, padx=5) - + # 存储变量引用 entry_vars.append(var) @@ -444,7 +461,7 @@ class ConfigEditor: """添加新的列表项""" items_frame = parent.winfo_children()[1] # 获取列表项框架 entry_vars = self.widgets[tuple(path)][1] # 获取变量列表 - + # 创建新的列表项 self.create_list_item(items_frame, "", len(entry_vars), entry_vars, path) self.on_value_changed() @@ -478,7 +495,7 @@ class ConfigEditor: """保存配置到文件""" if not self.pending_save: return - + with self.save_lock: try: # 获取所有控件的值 @@ -490,15 +507,17 @@ class ConfigEditor: current = current[key] final_key = path[-1] # 直接用最后一个key current[final_key] = value - + # 保存到文件 with open(self.config_path, "wb") as f: tomli_w.dump(self.config, f) - + self.last_save_time = time.time() self.pending_save = False self.editor_title.config(text=f"{self.editor_title.cget('text')} (已保存)") - self.root.after(2000, lambda: self.editor_title.config(text=self.editor_title.cget('text').replace(" (已保存)", ""))) + self.root.after( + 2000, lambda: self.editor_title.config(text=self.editor_title.cget("text").replace(" (已保存)", "")) + ) except Exception as e: messagebox.showerror("错误", f"保存配置失败: {str(e)}") @@ -506,7 +525,7 @@ class ConfigEditor: # 如果有待保存的更改,先保存 if self.pending_save: self.save_config() - + self.load_config() self.tree.delete(*self.tree.get_children()) for section in self.config: @@ -522,47 +541,47 @@ class ConfigEditor: dialog = tk.Toplevel(self.root) dialog.title(f"编辑 {setting['name']}") dialog.geometry("400x300") - + # 获取当前值 current = self.config for key in path[:-1]: current = current.get(key, {}) value = current.get(path[-1], []) - + # 创建编辑区 frame = ttk.Frame(dialog, padding="10") frame.pack(fill=tk.BOTH, expand=True) - + # 创建列表项框架 items_frame = ttk.Frame(frame) items_frame.pack(fill=tk.BOTH, expand=True) - + # 存储所有输入框的变量 entry_vars = [] - + # 为每个列表项创建输入框 for i, item in enumerate(value): self.create_list_item(items_frame, item, i, entry_vars, path) - + # 创建按钮框架 button_frame = ttk.Frame(frame) button_frame.pack(fill=tk.X, pady=10) - + # 添加按钮 - add_button = ttk.Button(button_frame, text="添加", - command=lambda: self.add_list_item(items_frame, path)) + add_button = ttk.Button(button_frame, text="添加", command=lambda: self.add_list_item(items_frame, path)) add_button.pack(side=tk.LEFT, padx=5) - + # 保存按钮 - save_button = ttk.Button(button_frame, text="保存", - command=lambda: self.save_list_editor(dialog, path, entry_vars)) + save_button = ttk.Button( + button_frame, text="保存", command=lambda: self.save_list_editor(dialog, path, entry_vars) + ) save_button.pack(side=tk.RIGHT, padx=5) def save_list_editor(self, dialog, path, entry_vars): """保存列表编辑窗口的内容""" # 获取所有非空输入框的值 values = [var.get() for var in entry_vars if var.get().strip()] - + # 更新配置 current = self.config for key in path[:-1]: @@ -570,10 +589,10 @@ class ConfigEditor: current[key] = {} current = current[key] current[path[-1]] = values - + # 触发保存 self.on_value_changed() - + # 关闭窗口 dialog.destroy() @@ -602,21 +621,21 @@ class ConfigEditor: self.on_value_changed() def toggle_quick_setting(self, full_path, widget_type, name, desc, already_in_quick): - quick_settings = self.editor_config.setdefault("editor", {}).setdefault("quick_settings", {}).setdefault("items", []) + quick_settings = ( + self.editor_config.setdefault("editor", {}).setdefault("quick_settings", {}).setdefault("items", []) + ) if already_in_quick: # 移除 - self.editor_config["editor"]["quick_settings"]["items"] = [item for item in quick_settings if item.get("path") != full_path] + self.editor_config["editor"]["quick_settings"]["items"] = [ + item for item in quick_settings if item.get("path") != full_path + ] else: # 添加 - quick_settings.append({ - "name": name, - "description": desc, - "path": full_path, - "type": widget_type - }) + quick_settings.append({"name": name, "description": desc, "path": full_path, "type": widget_type}) # 保存到configexe.toml import tomli_w import os + config_path = os.path.join(os.path.dirname(__file__), "configexe.toml") with open(config_path, "wb") as f: tomli_w.dump(self.editor_config, f) @@ -630,10 +649,12 @@ class ConfigEditor: self.widgets.clear() self.create_quick_settings_widgets() + def main(): root = tk.Tk() _app = ConfigEditor(root) root.mainloop() + if __name__ == "__main__": main()