Skip to content

Commit fc89196

Browse files
committed
Optimize qrc
将文本格式的关于文档编译至 `qrc` 中; 优化 `pyproject.toml` 中项目构建配置,使仅包含编译后的资源;
1 parent aededb2 commit fc89196

4 files changed

Lines changed: 75 additions & 15 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ authors = ["muzing <muzi2001@foxmail.com>"]
77
license = "GPL-3.0-or-later"
88
readme = "README.md"
99
repository = "https://github.com/muziing/Py2exe-GUI"
10-
include = ["docs/source/images"]
10+
exclude = ["src/py2exe_gui/Resources"]
11+
include = ["src/py2exe_gui/Resources/compiled_resources.py"]
1112

1213
[tool.poetry.dependencies]
1314
python = ">=3.7,<3.11"
@@ -17,7 +18,7 @@ PySide6 = "~6.2.0" # latest LTS version
1718
"Bug Tracker" = "https://github.com/muziing/Py2exe-GUI/issues"
1819

1920
[tool.poetry.group.dev.dependencies]
20-
# Sphinx = "^5.2.0"
21+
# Sphinx = "^5.3.0"
2122
black = "^22.10.0"
2223
isort = "^5.10.0"
2324
mypy = "^0.991"

src/py2exe_gui/Resources/compiled_resources.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,47 @@
66
from PySide6 import QtCore
77

88
qt_resource_data = b"\
9+
\x00\x00\x02n\
10+
#\
11+
# \xe5\x85\xb3\xe4\xba\x8e Py2exe-\
12+
GUI\x0a\x0aPy2exe-GUI \
13+
\xe6\x98\xaf\xe4\xb8\x80\xe4\xb8\xaa\xe5\x9f\xba\xe4\xba\x8e \
14+
[PyInstaller](ht\
15+
tps://pyinstalle\
16+
r.org/) \xe7\x9a\x84\xe5\x9b\xbe\xe5\xbd\
17+
\xa2\xe5\x8c\x96\xe8\xb7\xa8\xe5\xb9\xb3\xe5\x8f\xb0\xe6\x89\x93\
18+
\xe5\x8c\x85\xe5\xb7\xa5\xe5\x85\xb7\xef\xbc\x8c\xe4\xbe\xbf\xe4\
19+
\xba\x8e\xe5\xb0\x86 Python \xe4\xbb\xa3\
20+
\xe7\xa0\x81\xe6\x89\x93\xe5\x8c\x85\xe4\xb8\xba\xe5\x8f\xaf\xe6\
21+
\x89\xa7\xe8\xa1\x8c\xe6\x96\x87\xe4\xbb\xb6\xe3\x80\x82\x0a\x0a\
22+
\xe6\x9c\xac\xe7\xa8\x8b\xe5\xba\x8f\xe4\xb8\xba**\xe5\xbc\
23+
\x80\xe6\xba\x90\xe8\xbd\xaf\xe4\xbb\xb6**\xef\xbc\x9a\xe6\
24+
\x89\x80\xe6\x9c\x89\xe6\xba\x90\xe4\xbb\xa3\xe7\xa0\x81\xe6\x89\
25+
\x98\xe7\xae\xa1\xe4\xba\x8e [GitHub]\
26+
(https://github.\
27+
com/muziing/Py2e\
28+
xe-GUI)\xef\xbc\x8c\xe5\xb9\xb6\xe9\x80\x9a\
29+
\xe8\xbf\x87 [PyPI](https\
30+
://pypi.org/proj\
31+
ect/py2exe-gui/)\
32+
\xe6\x8f\x90\xe4\xbe\x9b\xe5\x88\x86\xe5\x8f\x91\xe3\x80\x82\
33+
\x0a\x0a\xe6\x9c\xac\xe7\xa8\x8b\xe5\xba\x8f\xe4\xb8\xba**\
34+
\xe8\x87\xaa\xe7\x94\xb1\xe8\xbd\xaf\xe4\xbb\xb6**\xef\xbc\
35+
\x9a\xe5\x9c\xa8\xe8\x87\xaa\xe7\x94\xb1\xe8\xbd\xaf\xe4\xbb\xb6\
36+
\xe8\x81\x94\xe7\x9b\x9f\xe5\x8f\x91\xe5\xb8\x83\xe7\x9a\x84 \
37+
*GNU \xe9\x80\x9a\xe7\x94\xa8\xe5\x85\xac\xe5\x85\
38+
\xb1\xe8\xae\xb8\xe5\x8f\xaf\xe5\x8d\x8f\xe8\xae\xae\xef\xbc\x88\
39+
\xe7\xac\xac3\xe7\x89\x88\xe6\x88\x96\xe6\x9b\xb4\xe6\x96\xb0\
40+
\xe7\x9a\x84\xe7\x89\x88\xe6\x9c\xac\xef\xbc\x89* \xe7\x9a\
41+
\x84\xe7\xba\xa6\xe6\x9d\x9f\xe4\xb8\x8b\xef\xbc\x8c\xe4\xbd\xa0\
42+
\xe5\x8f\xaf\xe4\xbb\xa5\xe5\xaf\xb9\xe5\x85\xb6\xe8\xbf\x9b\xe8\
43+
\xa1\x8c\xe5\x86\x8d\xe5\x8f\x91\xe5\xb8\x83\xe5\x92\x8c/\xe6\
44+
\x88\x96\xe4\xbf\xae\xe6\x94\xb9\xe3\x80\x82\x0a\x0a\xe7\x89\x88\
45+
\xe6\x9d\x83\xe6\x89\x80\xe6\x9c\x89 \xc2\xa9 202\
46+
2 [Muzing (muzi\
47+
2001@foxmail.com\
48+
)](https://muzin\
49+
g.top/about)\x0a\
950
\x00\x00\x0c\xf9\
1051
\x89\
1152
PNG\x0d\x0a\x1a\x0a\x00\x00\x00\x0dIHDR\x00\
@@ -223,6 +264,14 @@
223264
\x00O\xa6S\
224265
\x00I\
225266
\x00c\x00o\x00n\x00s\
267+
\x00\x05\
268+
\x00Z\xcf\xb3\
269+
\x00T\
270+
\x00e\x00x\x00t\x00s\
271+
\x00\x0a\
272+
\x0c\xac^4\
273+
\x00A\
274+
\x00b\x00o\x00u\x00t\x00_\x00T\x00e\x00x\x00t\
226275
\x00\x14\
227276
\x01O\xad\x98\
228277
\x00P\
@@ -231,11 +280,15 @@
231280
"
232281

233282
qt_resource_struct = b"\
234-
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
283+
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\
284+
\x00\x00\x00\x00\x00\x00\x00\x00\
285+
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x04\
235286
\x00\x00\x00\x00\x00\x00\x00\x00\
236-
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
287+
\x00\x00\x00\x10\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\
237288
\x00\x00\x00\x00\x00\x00\x00\x00\
238-
\x00\x00\x00\x10\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
289+
\x00\x00\x00 \x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
290+
\x00\x00\x01\x83\xbc\xcf\xde\xf8\
291+
\x00\x00\x00:\x00\x00\x00\x00\x00\x01\x00\x00\x02r\
239292
\x00\x00\x01\x83Y\xef\xb3\x13\
240293
"
241294

src/py2exe_gui/Resources/resources.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<qresource prefix="Icons">
44
<file alias="Py2exe-GUI_icon_72px">Icons/Py2exe-GUI_icon_72px.png</file>
55
</qresource>
6+
<qresource prefix="Texts">
7+
<file alias="About_Text">About.md</file>
8+
</qresource>
69
</RCC>

src/py2exe_gui/Widgets/dialog_widgets.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import subprocess
22
from typing import Optional
33

4-
from PySide6 import QtCore
4+
from PySide6.QtCore import QFile, QIODevice, Qt, Slot
55
from PySide6.QtGui import QPixmap
66
from PySide6.QtWidgets import (
77
QDialog,
@@ -119,7 +119,7 @@ def _setup(self) -> None:
119119

120120
self.setWindowTitle("关于")
121121
self.setStandardButtons(QMessageBox.Ok)
122-
self.setTextFormat(QtCore.Qt.MarkdownText)
122+
self.setTextFormat(Qt.MarkdownText)
123123
self.setText(self.about_text)
124124
self.setIconPixmap(QPixmap(":/Icons/Py2exe-GUI_icon_72px"))
125125

@@ -130,12 +130,15 @@ def about_text(self) -> str:
130130
:return: 关于信息
131131
"""
132132

133-
try:
134-
with open(
135-
"py2exe_gui/Resources/About.md", "r", encoding="utf-8"
136-
) as about_file:
137-
self._about_text = about_file.read()
138-
except FileNotFoundError:
133+
# 因使用qrc系统,所以使用Qt风格读取文本文件
134+
about_file = QFile(":/Texts/About_Text")
135+
about_file.open(QIODevice.ReadOnly | QIODevice.Text) # type: ignore
136+
about_text = bytes(about_file.readAll()).decode("utf-8")
137+
about_file.close()
138+
139+
if about_text:
140+
self._about_text = about_text
141+
else:
139142
self._about_text = "无法打开关于文档,请尝试重新获取本程序。"
140143

141144
return self._about_text
@@ -179,7 +182,7 @@ def _setup(self) -> None:
179182
# 连接信号与槽
180183
self.multifunction_btn.clicked.connect(self.handle_multifunction) # type:ignore
181184

182-
@QtCore.Slot(tuple)
185+
@Slot(tuple)
183186
def handle_output(self, subprocess_output: tuple[int, str]) -> None:
184187
"""
185188
处理子进程的输出 \n
@@ -199,7 +202,7 @@ def handle_output(self, subprocess_output: tuple[int, str]) -> None:
199202
if output_text == "正在运行中……":
200203
self.multifunction_btn.setText("取消")
201204

202-
@QtCore.Slot()
205+
@Slot()
203206
def handle_multifunction(self) -> None:
204207
"""
205208
处理多功能按钮点击信号的槽 \n

0 commit comments

Comments
 (0)