进行文件的逻辑拆分

初步对ui.py以及novel_generator.py进行了拆分
This commit is contained in:
YILING0013
2025-02-16 22:32:32 +08:00
parent 0be413236b
commit ba10e6dd66
24 changed files with 4410 additions and 1823 deletions
+45
View File
@@ -0,0 +1,45 @@
# ui/summary_tab.py
# -*- coding: utf-8 -*-
import os
import customtkinter as ctk
from tkinter import messagebox
from utils import read_file, save_string_to_txt, clear_file_content
from ui.context_menu import TextWidgetContextMenu
def build_summary_tab(self):
self.summary_tab = self.tabview.add("Global Summary")
self.summary_tab.rowconfigure(0, weight=0)
self.summary_tab.rowconfigure(1, weight=1)
self.summary_tab.columnconfigure(0, weight=1)
load_btn = ctk.CTkButton(self.summary_tab, text="加载 global_summary.txt", command=self.load_global_summary, font=("Microsoft YaHei", 12))
load_btn.grid(row=0, column=0, padx=5, pady=5, sticky="w")
save_btn = ctk.CTkButton(self.summary_tab, text="保存修改", command=self.save_global_summary, font=("Microsoft YaHei", 12))
save_btn.grid(row=0, column=0, padx=5, pady=5, sticky="e")
self.summary_text = ctk.CTkTextbox(self.summary_tab, wrap="word", font=("Microsoft YaHei", 12))
TextWidgetContextMenu(self.summary_text)
self.summary_text.grid(row=1, column=0, sticky="nsew", padx=5, pady=5)
def load_global_summary(self):
filepath = self.filepath_var.get().strip()
if not filepath:
messagebox.showwarning("警告", "请先设置保存文件路径")
return
filename = os.path.join(filepath, "global_summary.txt")
content = read_file(filename)
self.summary_text.delete("0.0", "end")
self.summary_text.insert("0.0", content)
self.log("已加载 global_summary.txt 到编辑区。")
def save_global_summary(self):
filepath = self.filepath_var.get().strip()
if not filepath:
messagebox.showwarning("警告", "请先设置保存文件路径")
return
content = self.summary_text.get("0.0", "end").strip()
filename = os.path.join(filepath, "global_summary.txt")
clear_file_content(filename)
save_string_to_txt(content, filename)
self.log("已保存对 global_summary.txt 的修改。")