mirror of
https://github.com/muziing/Py2exe-GUI.git
synced 2025-01-27 17:02:55 +08:00
Move pyinstaller_option_table
into CenterWidget
通过将选项详情表格从 `MainWindow` 移动至 `CenterWidget` 中来实现避免重复调用耗时的 `load_pyinst_options()` 函数;
This commit is contained in:
parent
e37711efb1
commit
5ce25f0c99
@ -42,7 +42,7 @@ from .dialog_widgets import (
|
||||
)
|
||||
from .multi_item_edit_widget import MultiPkgEditWindow
|
||||
from .pyenv_combobox import PyEnvComboBox
|
||||
from .pyinstaller_option_widget import load_pyinst_options
|
||||
from .pyinstaller_option_widget import PyinstallerOptionTable
|
||||
|
||||
|
||||
class CenterWidget(QWidget):
|
||||
@ -66,8 +66,8 @@ class CenterWidget(QWidget):
|
||||
|
||||
self.parent_widget = parent
|
||||
|
||||
# 读取PyInstaller选项详细描述,用于各控件ToolTip
|
||||
self.option_dict = load_pyinst_options() # TODO 待优化:避免重复加载
|
||||
# 显示 PyInstaller 选项详细描述的控件
|
||||
self.pyinstaller_option_table = PyinstallerOptionTable()
|
||||
|
||||
# 展示已安装的包
|
||||
self.pkg_browser_dlg = PkgBrowserDlg()
|
||||
@ -157,8 +157,8 @@ class CenterWidget(QWidget):
|
||||
self.run_packaging_btn.setEnabled(False)
|
||||
|
||||
# 将 PyInstaller 选项详情设置成各控件的 ToolTip
|
||||
if self.option_dict:
|
||||
opt = self.option_dict
|
||||
if self.pyinstaller_option_table.option_dict:
|
||||
opt = self.pyinstaller_option_table.option_dict
|
||||
# TODO: 解绑文本文档中的option字符和此处opt的键
|
||||
self.project_name_label.setToolTip(opt["-n NAME, --name NAME"])
|
||||
self.one_dir_btn.setToolTip(opt["-D, --onedir"])
|
||||
@ -434,6 +434,7 @@ class CenterWidget(QWidget):
|
||||
|
||||
# 但在该环境中没有安装 PyInstaller,询问用户是否继续操作
|
||||
if not new_pyenv.pkg_installed("pyinstaller"):
|
||||
# TODO 自实现 MessageBox,包含"仍要使用"、"取消"、"尝试安装PyInstaller"三个按钮
|
||||
result = QMessageBox.warning(
|
||||
self,
|
||||
"警告",
|
||||
@ -501,8 +502,8 @@ class WinMacCenterWidget(CenterWidget):
|
||||
self.console_checkbox.setChecked(True) # 默认值
|
||||
|
||||
# 将 PyInstaller 选项详情设置成各控件的 ToolTip
|
||||
if self.option_dict:
|
||||
opt = self.option_dict
|
||||
if self.pyinstaller_option_table.option_dict:
|
||||
opt = self.pyinstaller_option_table.option_dict
|
||||
self.icon_path_label.setToolTip(
|
||||
opt[
|
||||
'-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">, '
|
||||
|
@ -43,7 +43,6 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.menu_bar = QMenuBar(self)
|
||||
self.status_bar = QStatusBar(self)
|
||||
self.pyinstaller_option_table = PyinstallerOptionTable()
|
||||
|
||||
self.setCentralWidget(self.center_widget)
|
||||
self.setMenuBar(self.menu_bar)
|
||||
@ -79,7 +78,9 @@ class MainWindow(QMainWindow):
|
||||
"PyInstaller官方文档",
|
||||
lambda: open_url(APP_URLs["Pyinstaller_doc"]),
|
||||
)
|
||||
help_menu.addAction("PyInstaller选项详情", self.pyinstaller_option_table.show)
|
||||
help_menu.addAction(
|
||||
"PyInstaller选项详情", self.center_widget.pyinstaller_option_table.show
|
||||
)
|
||||
help_menu.addSeparator()
|
||||
help_menu.addAction("报告Bug", lambda: open_url(APP_URLs["BugTracker"]))
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
__all__ = ["load_pyinst_options", "PyinstallerOptionTable"]
|
||||
|
||||
import warnings
|
||||
from typing import Optional
|
||||
|
||||
import yaml
|
||||
from PySide6.QtGui import QPixmap
|
||||
@ -72,22 +71,13 @@ class PyinstallerOptionTable(QTableWidget):
|
||||
self.setHorizontalHeaderLabels(["选项", "描述"])
|
||||
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
|
||||
|
||||
# 存储选项信息的字典,懒加载,实际在显示窗口时才为此实例属性赋值
|
||||
self.option_dict: Optional[dict[str, str]] = None
|
||||
# 存储选项信息的字典
|
||||
self.option_dict = load_pyinst_options()
|
||||
self._set_option_items()
|
||||
|
||||
def show(self) -> None:
|
||||
"""重写show()方法,实现只有在显示窗口时才加载选项信息的效果,提高主程序启动速度"""
|
||||
|
||||
self._load_and_set_option_items()
|
||||
super().show()
|
||||
|
||||
def _load_and_set_option_items(self) -> None:
|
||||
def _set_option_items(self) -> None:
|
||||
"""加载选项信息、为表格控件中填充条目"""
|
||||
|
||||
# 加载选项信息
|
||||
if self.option_dict is None:
|
||||
self.option_dict = load_pyinst_options()
|
||||
|
||||
# 填充条目
|
||||
self.setRowCount(len(self.option_dict))
|
||||
for index, (option, description) in enumerate(self.option_dict.items()):
|
||||
|
Loading…
x
Reference in New Issue
Block a user