diff --git a/source/core/ui_manager.py b/source/core/ui_manager.py index f717a9c..a85fa14 100644 --- a/source/core/ui_manager.py +++ b/source/core/ui_manager.py @@ -1,5 +1,5 @@ from PySide6.QtGui import QIcon, QAction, QFont -from PySide6.QtWidgets import QMessageBox, QMainWindow +from PySide6.QtWidgets import QMessageBox, QMainWindow, QMenu from PySide6.QtCore import Qt import webbrowser @@ -17,6 +17,8 @@ class UIManager: # 使用getattr获取ui属性,如果不存在则为None self.ui = getattr(main_window, 'ui', None) self.debug_action = None + self.turbo_download_action = None + self.dev_menu = None def setup_ui(self): """设置UI元素,包括窗口图标、标题和菜单""" @@ -60,8 +62,85 @@ class UIManager: if not self.ui or not hasattr(self.ui, 'menu'): return - # 创建菜单项 + # 获取自定义字体和字体族名称 + font_family = "Arial" # 默认字体族 + menu_font = None + + # 尝试从UI中获取字体和字体族 + try: + # 优先从Ui_install.py中获取font_family变量 + import os + from PySide6.QtGui import QFontDatabase + + # 尝试直接加载字体并获取字体族 + font_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "fonts", "SmileySans-Oblique.ttf") + if os.path.exists(font_path): + font_id = QFontDatabase.addApplicationFont(font_path) + if font_id != -1: + font_family = QFontDatabase.applicationFontFamilies(font_id)[0] + # 创建与UI_install.py中完全相同的菜单字体 + menu_font = QFont(font_family, 14) # 字体大小为14 + menu_font.setBold(True) # 设置粗体 + + # 如果以上方法失败,则尝试从ui获取字体 + if not menu_font and hasattr(self.ui, 'menu') and self.ui.menu: + menu_font = self.ui.menu.font() + + # 如果仍然没有获取到,使用默认字体 + if not menu_font: + menu_font = QFont(font_family, 14) + menu_font.setBold(True) + + except: + # 如果出错,使用默认字体 + menu_font = QFont(font_family, 14) + menu_font.setBold(True) + + # 创建开发者选项子菜单 + self.dev_menu = QMenu("开发者选项", self.main_window) + self.dev_menu.setFont(menu_font) # 设置与UI_install.py中相同的字体 + + # 使用和主菜单相同的样式,直接指定字体族、字体大小和粗细 + menu_style = f""" + QMenu {{ + background-color: #E96948; + color: white; + font-family: "{font_family}"; + font-size: 14px; + font-weight: bold; + border: 1px solid #F47A5B; + padding: 8px; + border-radius: 6px; + margin-top: 2px; + }} + QMenu::item {{ + padding: 6px 20px 6px 15px; + background-color: transparent; + min-width: 120px; + color: white; + font-family: "{font_family}"; + font-size: 14px; + font-weight: bold; + }} + QMenu::item:selected {{ + background-color: #F47A5B; + border-radius: 4px; + }} + QMenu::separator {{ + height: 1px; + background-color: #F47A5B; + margin: 5px 15px; + }} + QMenu::item:checked {{ + background-color: #D25A3C; + border-radius: 4px; + }} + """ + self.dev_menu.setStyleSheet(menu_style) + + # 创建Debug模式选项并添加到开发者选项子菜单中 self.debug_action = QAction("Debug模式", self.main_window, checkable=True) + self.debug_action.setFont(menu_font) # 设置相同的字体 # 安全地获取config属性 config = getattr(self.main_window, 'config', {}) @@ -74,17 +153,25 @@ class UIManager: # 安全地连接toggle_debug_mode方法 if hasattr(self.main_window, 'toggle_debug_mode'): self.debug_action.triggered.connect(self.main_window.toggle_debug_mode) - - # 添加到菜单 - self.ui.menu.addAction(self.debug_action) - + + # 创建狂暴下载选项(无功能) + self.turbo_download_action = QAction("狂暴下载", self.main_window) + self.turbo_download_action.setFont(menu_font) # 设置自定义字体 + self.turbo_download_action.setEnabled(False) # 禁用按钮 + + # 添加到开发者选项子菜单 + self.dev_menu.addAction(self.debug_action) + self.dev_menu.addAction(self.turbo_download_action) + # 为未来功能预留的"切换下载源"按钮 self.switch_source_action = QAction("切换下载源", self.main_window) + self.switch_source_action.setFont(menu_font) # 设置自定义字体 self.switch_source_action.setEnabled(False) # 暂时禁用 - self.ui.menu.addAction(self.switch_source_action) - # 添加分隔符 + # 添加到主菜单 + self.ui.menu.addAction(self.switch_source_action) self.ui.menu.addSeparator() + self.ui.menu.addMenu(self.dev_menu) # 添加开发者选项子菜单 # 连接按钮点击事件,如果使用按钮式菜单 if hasattr(self.ui, 'settings_btn'): diff --git a/source/main_window.py b/source/main_window.py index 4eb4b3d..c30d49f 100644 --- a/source/main_window.py +++ b/source/main_window.py @@ -462,7 +462,7 @@ class MainWindow(QMainWindow): if event: event.accept() else: - sys.exit(0) + sys.exit(0) def handle_install_button_click(self): """处理安装按钮点击事件 @@ -612,6 +612,6 @@ class MainWindow(QMainWindow): return # 开始卸载补丁 - self.patch_manager.uninstall_patch(game_dir, game_version) + self.patch_manager.uninstall_patch(game_dir, game_version) \ No newline at end of file diff --git a/source/ui/Ui_install.py b/source/ui/Ui_install.py index e03757e..1586a4a 100644 --- a/source/ui/Ui_install.py +++ b/source/ui/Ui_install.py @@ -215,39 +215,48 @@ class Ui_MainWindows(object): self.menu.setObjectName(u"menu") self.menu.setTitle("设置") self.menu.setFont(menu_font) - self.menu.setStyleSheet(""" - QMenu { + # 创建菜单样式表,直接在样式表中指定字体族 + menu_style = f""" + QMenu {{ background-color: #E96948; color: white; - font-size: 16px; + font-family: "{font_family}"; + font-size: 14px; font-weight: bold; border: 1px solid #F47A5B; padding: 8px; border-radius: 6px; margin-top: 2px; - } - QMenu::item { + }} + QMenu::item {{ padding: 6px 20px 6px 15px; background-color: transparent; min-width: 120px; color: white; - } - QMenu::item:selected { + font-family: "{font_family}"; + font-weight: bold; + }} + QMenu::item:selected {{ background-color: #F47A5B; border-radius: 4px; - } - QMenu::separator { + }} + QMenu::separator {{ height: 1px; background-color: #F47A5B; margin: 5px 15px; - } - """) + }} + QMenu::item:checked {{ + background-color: #D25A3C; + border-radius: 4px; + }} + """ + self.menu.setStyleSheet(menu_style) self.menu_2 = QMenu(self.content_container) self.menu_2.setObjectName(u"menu_2") self.menu_2.setTitle("帮助") self.menu_2.setFont(menu_font) - self.menu_2.setStyleSheet(self.menu.styleSheet()) + self.menu_2.setStyleSheet(menu_style) # 连接按钮点击事件到显示对应菜单 self.settings_btn.clicked.connect(lambda: self.show_menu(self.menu, self.settings_btn)) diff --git a/source/workers/download.py b/source/workers/download.py index 1348214..a745da7 100644 --- a/source/workers/download.py +++ b/source/workers/download.py @@ -49,6 +49,7 @@ class DownloadThread(QThread): aria2c_path, ] + # 将所有的优化参数应用于每个下载任务 command.extend([ '--dir', download_dir, '--out', file_name, @@ -74,8 +75,14 @@ class DownloadThread(QThread): '--timeout=60', '--auto-file-renaming=false', '--allow-overwrite=true', - '--split=16', - '--max-connection-per-server=16' + # 优化参数 - 使用aria2允许的最佳设置 + '--split=128', # 增加分片数到128 + '--max-connection-per-server=16', # 最大允许值16 + '--min-split-size=1M', # 减小最小分片大小 + '--optimize-concurrent-downloads=true', # 优化并发下载 + '--file-allocation=none', # 禁用文件预分配加快开始 + '--async-dns=true', # 使用异步DNS + '--disable-ipv6=true' # 禁用IPv6提高速度 ]) # 证书验证现在总是需要,因为我们依赖hosts文件