diff --git a/src/fanqie_debug.py b/src/fanqie_debug.py index 46da10a..e6b2a88 100644 --- a/src/fanqie_debug.py +++ b/src/fanqie_debug.py @@ -241,20 +241,66 @@ def fanqie_d(url, encoding, user_agent, path_choice, data_folder, start_chapter_ retry_count += 1 # 否则重试 if retry_count == 4: - from func_timeout import func_timeout, FunctionTimedOut + import tkinter as tk + from tkinter import font, messagebox tqdm.write(Fore.RED + Style.BRIGHT + f"无法获取章节内容: {chapter_title}") - # 请用户在20秒内选择处理方式 - try: - while True: - choice = func_timeout(20, lambda: input("请选择处理方式:1.跳过此章节/2.重试获取章节内容/3.终止下载并保存(1/2/3)" - "(20秒内不选择默认重试)\n")) - if choice in ["1", "2", "3"]: - break - else: - tqdm.write("输入有误,请重新输入") - except FunctionTimedOut: - tqdm.write("超时,默认重试获取章节内容") - choice = "2" + tqdm.write(Fore.YELLOW + Style.BRIGHT + "请在弹出窗口中选择处理方式") + choice = None + + def on_button_click(value): + nonlocal choice + choice = value + window.destroy() + + # 弹窗请用户选择处理方式 + window = tk.Tk() + window.title("番茄下载器 - 选择处理方式") + # 获取屏幕宽度和高度 + screen_width = window.winfo_screenwidth() + screen_height = window.winfo_screenheight() + # 计算窗口宽和高 + x = (screen_width - 400) / 2 + y = (screen_height - 260) / 2 + window.geometry(f"400x260+{int(x)}+{int(y)}") + + # 不允许调整大小 + window.resizable(False, False) + + # 获取默认字体并设置字体大小 + default_font_family = font.nametofont("TkDefaultFont").actual()["family"] + font1 = font.Font(family=default_font_family, size=12) + font2 = font.Font(family=default_font_family, size=8) + + label = tk.Label(window, text=f"无法获取章节内容: \n{chapter_title}", pady=10, font=font1) + label.pack() + + label2 = tk.Label(window, text="已达最大重试次数\n您希望程序如何处理此问题:", font=font2) + label2.pack() + + button1_frame = tk.Frame(window) + button1_frame.pack() + button1 = tk.Button(button1_frame, text="跳过此章节 (1)", command=lambda: on_button_click("1"), + font=font1) + button1.pack(pady=5) + + button2_frame = tk.Frame(window) + button2_frame.pack() + button2 = tk.Button(button2_frame, text="再次重试 (2)", command=lambda: on_button_click("2"), + font=font1) + button2.pack(pady=5) + + button3_frame = tk.Frame(window) + button3_frame.pack() + button3 = tk.Button(button3_frame, text="终止下载并保存 (3)", command=lambda: on_button_click("3"), + font=font1) + button3.pack(pady=5) + + def on_closing(): + messagebox.showwarning("警告", "您必须选择处理方式,程序才能继续运行") + + window.protocol("WM_DELETE_WINDOW", on_closing) + + window.mainloop() if choice == "1": skip = True elif choice == "2":