Skip to content

Commit da73ba8

Browse files
committed
Add the PackagingTask class
重构,增加打包任务类; 将 `Core` 与 `Widgets` 升级为包;
1 parent 88e193e commit da73ba8

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/py2exe_gui/Core/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .packaging import Packaging
2+
from .packaging_task import PackagingTask
3+
from .validators import FilePathValidator, InterpreterValidator
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from pathlib import Path
2+
from typing import Optional
3+
4+
from PySide6 import QtCore
5+
6+
from .validators import FilePathValidator, InterpreterValidator
7+
8+
9+
class PackagingTask(QtCore.QObject):
10+
"""
11+
打包任务类,存储每个打包任务的详细信息
12+
"""
13+
14+
# 自定义信号
15+
option_set = QtCore.Signal(tuple) # 用户输入选项通过了验证,已设置为打包选项
16+
option_error = QtCore.Signal() # 用户输入选项有误,需要进一步处理
17+
18+
def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
19+
"""
20+
:param parent: 父控件对象
21+
"""
22+
23+
super(PackagingTask, self).__init__(parent)
24+
25+
self.script_path: Optional[Path] = None
26+
self.icon_path: Optional[Path] = None
27+
28+
def handle_option(self, option: tuple):
29+
"""
30+
处理用户在界面选择的打包选项 \n
31+
:param option: 选项
32+
"""
33+
34+
arg_key, arg_value = option
35+
36+
# 进行有效性验证,有效则保存并发射option_set信号,无效则发射option_error信号
37+
if arg_key == "script_path":
38+
self.option_set.emit(option)
39+
elif arg_key == "icon_path":
40+
self.option_set.emit(option)
41+
elif arg_key == "FD":
42+
self.option_set.emit(option)
43+
elif arg_key == "console":
44+
self.option_set.emit(option)
45+
elif arg_key == "out_name":
46+
self.option_set.emit(option)
47+
48+
def write_to_file(self):
49+
"""
50+
将打包任务保存至文件
51+
"""
52+
53+
pass

src/py2exe_gui/Widgets/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .arguments_browser import ArgumentsBrowser
2+
from .center_widget import CenterWidget
3+
from .dialog_widgets import *
4+
from .main_window import MainWindow

src/py2exe_gui/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PySide6.QtWidgets import QApplication
55

66
from py2exe_gui.Core.packaging import Packaging
7+
from py2exe_gui.Core.packaging_task import PackagingTask
78
from py2exe_gui.Widgets.dialog_widgets import SubProcessDlg
89
from py2exe_gui.Widgets.main_window import MainWindow
910

@@ -17,13 +18,15 @@ def __init__(self, *args, **kwargs) -> None:
1718
super(MainApp, self).__init__(*args, **kwargs)
1819

1920
self.packager = Packaging(self)
21+
self.packaging_task = PackagingTask(self)
22+
self.center_widget.option_selected.connect(self.packaging_task.handle_option)
23+
self.packaging_task.option_set.connect(self.packager.set_pyinstaller_args)
2024

2125
self.packager.args_settled.connect(
2226
lambda val: self.center_widget.pyinstaller_args_browser.enrich_args_text(
2327
val
2428
)
2529
)
26-
self.center_widget.option_selected.connect(self.packager.set_pyinstaller_args)
2730

2831
self.subprocess_dlg = SubProcessDlg(self)
2932

0 commit comments

Comments
 (0)