Skip to content

Commit 26a7f8b

Browse files
committed
Fine-tune code
一些代码微调小修改;
1 parent 707d4d3 commit 26a7f8b

5 files changed

Lines changed: 71 additions & 28 deletions

File tree

src/py2exe_gui/Core/packaging.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
from .subprocess_tool import SubProcessTool
66

7+
pyinstaller_args: list = [
8+
"script_path",
9+
"icon_path",
10+
"FD",
11+
"console",
12+
"out_name",
13+
]
14+
715

816
class Packaging(QtCore.QObject):
917
"""
@@ -19,17 +27,12 @@ def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
1927
"""
2028

2129
super(Packaging, self).__init__(parent)
22-
pyinstaller_args: list = [
23-
"script_path",
24-
"icon_path",
25-
"FD",
26-
"console",
27-
"out_name",
28-
]
30+
2931
self.args_dict: dict = dict.fromkeys(pyinstaller_args, "")
3032
self._args: List[str] = []
3133
self.subprocess: SubProcessTool = SubProcessTool(self, program="pyinstaller")
3234

35+
@QtCore.Slot(tuple)
3336
def set_pyinstaller_args(self, arg: tuple[str, str]) -> None:
3437
"""
3538
解析传递来的PyInstaller运行参数,并添加至命令参数字典 \n

src/py2exe_gui/Core/packaging_task.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from PySide6 import QtCore
55

6-
from .validators import FilePathValidator, InterpreterValidator
6+
from .validators import FilePathValidator
77

88

99
class PackagingTask(QtCore.QObject):
@@ -26,6 +26,7 @@ def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
2626
self.script_path: Optional[Path] = None
2727
self.icon_path: Optional[Path] = None
2828
self.out_name: Optional[str] = None
29+
# TODO 在实例属性中保存该次打包的所有选项详情
2930

3031
def handle_option(self, option: tuple[str, str]):
3132
"""
@@ -70,4 +71,5 @@ def write_to_file(self):
7071
将打包任务保存至文件
7172
"""
7273

74+
# TODO 实现将打包任务信息保存至文件的功能
7375
pass

src/py2exe_gui/Resources/About.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Py2exe-GUI 是一个基于 [PyInstaller](https://pyinstaller.org/) 的图形化跨平台打包工具,便于将 Python 代码打包为可执行文件。
44

5-
本程序为开源软件:所有源代码托管于 [GitHub](https://github.com/muziing/Py2exe-GUI),并通过 [PyPI](https://pypi.org/project/py2exe-gui/) 提供分发。
5+
本程序为**开源软件**:所有源代码托管于 [GitHub](https://github.com/muziing/Py2exe-GUI),并通过 [PyPI](https://pypi.org/project/py2exe-gui/) 提供分发。
66

7-
本程序为自由软件:在自由软件联盟发布的 GNU 通用公共许可协议(第3版或更新的版本)的约束下,你可以对其进行再发布和/或修改。
7+
本程序为**自由软件**:在自由软件联盟发布的 *GNU 通用公共许可协议(第3版或更新的版本)* 的约束下,你可以对其进行再发布和/或修改。
88

99
版权所有 © 2022 [Muzing (muzi2001@foxmail.com)](https://muzing.top/about)

src/py2exe_gui/Widgets/dialog_widgets.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, parent: QWidget = None) -> None:
2424
"""
2525

2626
super(ScriptFileDlg, self).__init__(parent)
27+
2728
self._setup()
2829

2930
def _setup(self) -> None:
@@ -32,8 +33,8 @@ def _setup(self) -> None:
3233
"""
3334

3435
self.setAcceptMode(QFileDialog.AcceptOpen)
35-
self.setDefaultSuffix("py")
36-
self.setNameFilters(("Python脚本文件 (*.py *.pyw)", "All (*)"))
36+
self.setViewMode(QFileDialog.Detail)
37+
self.setNameFilters(("Python脚本文件 (*.py *.pyw)", "所有文件 (*)"))
3738
self.setFileMode(QFileDialog.ExistingFiles)
3839
self.setLabelText(QFileDialog.FileName, "Python入口文件")
3940
self.setLabelText(QFileDialog.FileType, "Python文件")
@@ -52,6 +53,7 @@ def __init__(self, parent: QWidget = None) -> None:
5253
"""
5354

5455
super(IconFileDlg, self).__init__(parent)
56+
5557
self._setup()
5658

5759
def _setup(self) -> None:
@@ -60,15 +62,37 @@ def _setup(self) -> None:
6062
"""
6163

6264
self.setAcceptMode(QFileDialog.AcceptOpen)
63-
self.setDefaultSuffix("ico")
64-
self.setNameFilters(("图标文件 (*.ico *.icns)", "All (*)"))
65+
self.setViewMode(QFileDialog.Detail)
66+
self.setNameFilters(("图标文件 (*.ico *.icns)", "所有文件 (*)"))
6567
self.setFileMode(QFileDialog.ExistingFile)
6668
self.setLabelText(QFileDialog.FileName, "图标")
6769
self.setLabelText(QFileDialog.FileType, "图标文件")
6870
self.setLabelText(QFileDialog.Accept, "打开")
6971
self.setLabelText(QFileDialog.Reject, "取消")
7072

7173

74+
class AddDataDlg(QFileDialog):
75+
"""
76+
用于添加附加数据的对话框
77+
"""
78+
79+
def __init__(self, parent: QWidget = None) -> None:
80+
"""
81+
:param parent: 父控件对象
82+
"""
83+
84+
super(AddDataDlg, self).__init__(parent)
85+
86+
self._setup()
87+
88+
def _setup(self) -> None:
89+
"""
90+
配置添加数据对话框 \n
91+
"""
92+
93+
pass
94+
95+
7296
class AboutDlg(QMessageBox):
7397
"""
7498
用于显示关于信息的对话框
@@ -80,6 +104,7 @@ def __init__(self, parent: QWidget = None) -> None:
80104
"""
81105

82106
super(AboutDlg, self).__init__(parent)
107+
83108
self._about_text: str = ""
84109
self._setup()
85110

@@ -88,7 +113,7 @@ def _setup(self) -> None:
88113
配置关于信息对话框 \n
89114
"""
90115

91-
self.setWindowTitle("关于Py2exe-GUI")
116+
self.setWindowTitle("关于")
92117
self.setStandardButtons(QMessageBox.Ok)
93118
self.setTextFormat(Qt.MarkdownText)
94119
self.setText(self.about_text)
@@ -120,7 +145,12 @@ class SubProcessDlg(QDialog):
120145
"""
121146

122147
def __init__(self, parent: QWidget = None) -> None:
148+
"""
149+
:param parent: 父控件对象
150+
"""
151+
123152
super(SubProcessDlg, self).__init__(parent)
153+
124154
self.info_label = QLabel(self)
125155
self.browser = QTextBrowser(self)
126156
self._setup()

src/py2exe_gui/Widgets/main_window.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
from .dialog_widgets import AboutDlg
77

88

9+
def open_url(url: str) -> None:
10+
"""
11+
辅助函数,在系统默认浏览器中打开URL \n
12+
:param url: 待打开的URL
13+
"""
14+
QDesktopServices.openUrl(QUrl(url))
15+
16+
917
class MainWindow(QMainWindow):
1018
"""
1119
主界面主窗口
@@ -15,8 +23,12 @@ def __init__(self, *args, **kwargs) -> None:
1523
super().__init__(*args, **kwargs)
1624

1725
self.center_widget = CenterWidget(self)
18-
self.status_bar = QStatusBar(self)
1926
self.menu_bar = QMenuBar(self)
27+
self.status_bar = QStatusBar(self)
28+
29+
self.setCentralWidget(self.center_widget)
30+
self.setMenuBar(self.menu_bar)
31+
self.setStatusBar(self.status_bar)
2032

2133
self._setup()
2234

@@ -26,37 +38,33 @@ def _setup(self) -> None:
2638
"""
2739

2840
self.setWindowTitle("Py2exe-GUI")
29-
self.setMinimumSize(320, 350)
41+
self.setMinimumSize(350, 430)
3042
# self.resize(800, 600)
31-
self.setWindowIcon(QIcon("../Resources/Icons/Py2exe-GUI_icon_72px.ico"))
43+
self.setWindowIcon(QIcon("py2exe_gui/Resources/Icons/Py2exe-GUI_icon_72px.ico"))
3244

3345
self._setup_menu_bar()
3446
self._setup_status_bar()
3547

36-
self.setCentralWidget(self.center_widget)
37-
self.setMenuBar(self.menu_bar)
38-
self.setStatusBar(self.status_bar)
39-
4048
def _setup_menu_bar(self) -> None:
4149
"""
4250
配置主窗口菜单栏 \n
4351
"""
4452

4553
file_menu = self.menu_bar.addMenu("文件(&F)")
46-
# file_menu.addAction("打开……") # 暂时只为占位
54+
file_menu.addAction("打开打包任务") # 暂时只为占位
55+
file_menu.addAction("保存当前打包任务") # 暂时只为占位
4756
file_menu.addSeparator()
48-
file_menu.addAction("退出(&X)", self.close) # 直接调用close可能整个程序并未完全退出?
57+
file_menu.addAction("设置") # 暂时只为占位
58+
file_menu.addSeparator()
59+
file_menu.addAction("退出(&X)", self.close)
4960

5061
help_menu = self.menu_bar.addMenu("帮助(&H)")
5162

52-
def open_url(url: str):
53-
"""辅助函数,在系统默认浏览器中打开URL"""
54-
QDesktopServices.openUrl(QUrl(url))
55-
5663
help_menu.addAction(
5764
"PyInstaller官方文档",
5865
lambda: open_url("https://pyinstaller.org/en/stable/usage.html"),
5966
)
67+
help_menu.addAction("PyInstaller选项详情") # 暂时只为占位
6068
help_menu.addSeparator()
6169
help_menu.addAction(
6270
"报告Bug", lambda: open_url("https://github.com/muziing/Py2exe-GUI/issues")

0 commit comments

Comments
 (0)