Skip to content

Commit 14f50a1

Browse files
authored
Update gui.py
1 parent 7da76fb commit 14f50a1

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

gui.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
import threading
1313
from pathlib import Path
1414

15+
# Windows 高 DPI 支持 - 必须在导入 PyQt5 之前设置
16+
if sys.platform == 'win32':
17+
try:
18+
from ctypes import windll
19+
windll.shcore.SetProcessDpiAwareness(2) # PROCESS_PER_MONITOR_DPI_AWARE
20+
except:
21+
try:
22+
windll.user32.SetProcessDPIAware()
23+
except:
24+
pass
25+
1526
# 检查 PyQt5
1627
try:
1728
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
@@ -20,6 +31,12 @@
2031
QMessageBox, QInputDialog)
2132
from PyQt5.QtCore import Qt, QThread, pyqtSignal
2233
HAS_PYQT = True
34+
35+
# 高 DPI 支持 - 必须在创建 QApplication 之前设置
36+
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
37+
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
38+
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
39+
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
2340
except ImportError:
2441
HAS_PYQT = False
2542
print("错误: 未安装 PyQt5")
@@ -167,20 +184,31 @@ def run(self):
167184
cmd.extend(['-ech', self.config['ech']])
168185

169186
try:
187+
# Windows 上需要指定 UTF-8 编码,因为 Go 程序输出 UTF-8
170188
self.process = subprocess.Popen(
171189
cmd,
172190
stdout=subprocess.PIPE,
173191
stderr=subprocess.STDOUT,
174-
universal_newlines=True,
175192
bufsize=1
176193
)
177194
self.is_running = True
178195

179-
for line in iter(self.process.stdout.readline, ''):
180-
if not self.is_running:
196+
# 使用 UTF-8 解码,忽略无法解码的字符
197+
while self.is_running:
198+
line = self.process.stdout.readline()
199+
if not line:
181200
break
182-
if line:
183-
self.log_output.emit(line)
201+
try:
202+
# 尝试 UTF-8 解码
203+
decoded_line = line.decode('utf-8', errors='replace')
204+
except:
205+
# 如果失败,尝试系统默认编码
206+
try:
207+
decoded_line = line.decode(errors='replace')
208+
except:
209+
decoded_line = str(line)
210+
if decoded_line:
211+
self.log_output.emit(decoded_line)
184212

185213
self.process.wait()
186214
self.is_running = False

0 commit comments

Comments
 (0)