Skip to content

Commit 650179d

Browse files
authored
Merge-build: v2.9.11
2 parents 19029d0 + 86df6b9 commit 650179d

31 files changed

+180
-163
lines changed

CGS.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# -*- coding: utf-8 -*-
22
import os
33
import sys
4-
import functools
54
import traceback
65
from datetime import datetime
76
from multiprocessing import freeze_support
87
from pathlib import Path
98

10-
from PyQt5.QtCore import Qt, QTimer
9+
from PyQt5.QtCore import Qt
1110
from PyQt5.QtWidgets import QApplication, QMessageBox
1211

13-
_CGS_PATCHED_QTIMER = False
14-
1512

1613
class ExceptionRouter:
1714
def __init__(self):
@@ -22,7 +19,6 @@ def bind_ui(self, ui):
2219

2320
def install(self):
2421
sys.excepthook = self.excepthook
25-
self._install_qtimer_single_shot_guard()
2622

2723
def raise_fatal(self, exc, phase):
2824
trace_text = "".join(traceback.format_exception(type(exc), exc, exc.__traceback__))
@@ -114,31 +110,6 @@ def _append_fatal_log(self, phase, trace_text):
114110
pass
115111
return log_path
116112

117-
def _install_qtimer_single_shot_guard(self):
118-
global _CGS_PATCHED_QTIMER
119-
if _CGS_PATCHED_QTIMER:
120-
return
121-
original_single_shot = QTimer.singleShot
122-
123-
@functools.wraps(original_single_shot)
124-
def patched_single_shot(*args, **kwargs):
125-
if args and callable(args[-1]):
126-
callback = args[-1]
127-
128-
@functools.wraps(callback)
129-
def guarded_callback(*cb_args, **cb_kwargs):
130-
try:
131-
return callback(*cb_args, **cb_kwargs)
132-
except Exception:
133-
self.handle_current_exception("QTimer.singleShot")
134-
return None
135-
136-
args = (*args[:-1], guarded_callback)
137-
return original_single_shot(*args, **kwargs)
138-
139-
QTimer.singleShot = patched_single_shot
140-
_CGS_PATCHED_QTIMER = True
141-
142113
@staticmethod
143114
def _write_stderr(message):
144115
if sys.stderr is None:

GUI/browser_window.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,6 @@ def closeEvent(self, event):
407407
self.gui.BrowserWindow = None
408408
self.gui.previewInit = True
409409
self.gui.previewSecondInit = False
410+
self.gui.pageFrame.setEnabled(False)
411+
self.gui.pageFrame.setStyleSheet("QToolButton { background-color: rgb(127, 127, 127); }")
410412
super().closeEvent(event)

GUI/core/anim.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22
from typing import Callable, Literal, Optional, Sequence
33

44
from PyQt5.QtCore import (
5-
QObject,
6-
QAbstractAnimation,
7-
QPropertyAnimation,
8-
QEasingCurve,
9-
QParallelAnimationGroup,
10-
QSequentialAnimationGroup,
11-
QRect,
12-
QPoint,
13-
QTimer,
5+
QObject, QAbstractAnimation, QPropertyAnimation, QEasingCurve,
6+
QParallelAnimationGroup, QSequentialAnimationGroup, QRect, QPoint,
147
pyqtProperty,
158
)
169
from PyQt5.QtWidgets import QGraphicsOpacityEffect
1710

11+
from GUI.core.timer import safe_single_shot
12+
1813

1914
PopupDirection = Literal["right", "up", "down"]
2015

@@ -491,4 +486,4 @@ def _start_anim():
491486
widget.setWindowOpacity(1.0)
492487
group.start()
493488

494-
QTimer.singleShot(0, _start_anim)
489+
safe_single_shot(0, _start_anim)

GUI/core/timer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
from PyQt5.QtCore import QTimer
3+
4+
5+
def safe_single_shot(msec, callback):
6+
def guarded():
7+
try:
8+
callback()
9+
except Exception:
10+
sys.excepthook(*sys.exc_info())
11+
QTimer.singleShot(msec, guarded)

GUI/gui.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import multiprocessing.managers as m
99
from PyQt5.QtGui import QKeySequence, QGuiApplication
1010
from PyQt5.QtCore import (
11-
QThread, Qt, QCoreApplication, QUrl, QRect, QTimer,
11+
QThread, Qt, QCoreApplication, QUrl, QRect,
1212
pyqtSignal
1313
)
14+
from GUI.core.timer import safe_single_shot
1415
from PyQt5.QtWidgets import QMainWindow, QCompleter, QShortcut
1516
from qfluentwidgets import InfoBar, InfoBarPosition
1617

@@ -99,7 +100,7 @@ def setupUi(self, MainWindow):
99100
self.task_mgr = TaskProgressManager(self)
100101
self.task_mgr.init_native_panel()
101102
setupTheme(self)
102-
QTimer.singleShot(10, self.setupUi_)
103+
safe_single_shot(10, self.setupUi_)
103104
self.first_init = False
104105
else:
105106
self.apply_translations()
@@ -243,7 +244,7 @@ def showAggrWin(self):
243244
self.rvBtn.click()
244245
def _jump():
245246
self.toolWin.stackedWidget.setCurrentWidget(self.toolWin.asInterface)
246-
QTimer.singleShot(10, _jump)
247+
safe_single_shot(10, _jump)
247248

248249
def set_tool_win(self):
249250
self.toolWin = ToolWindow(self)
@@ -410,6 +411,8 @@ def _show_preview(self):
410411
self.BrowserWindow.second_init()
411412
self.previewSecondInit = False
412413
self.BrowserWindow.set_ensure_handler()
414+
self.pageFrame.setEnabled(True)
415+
self.pageFrame.setStyleSheet("QToolButton { background-color: rgb(255, 255, 255); }")
413416
final_rect = self.BrowserWindow.geometry()
414417
PopupAnimator.show(self.BrowserWindow, final_rect, duration_ms=220, direction="right")
415418

@@ -450,14 +453,14 @@ def retry_all():
450453
self.BrowserWindow = None
451454
def safe_setup():
452455
if hasattr(self, 'p_crawler') and self.p_crawler and self.p_crawler.is_alive():
453-
QTimer.singleShot(70, safe_setup)
456+
safe_single_shot(70, safe_setup)
454457
else:
455458
self.Q('InputFieldQueue').clear()
456459
self.setupUi(self)
457-
QTimer.singleShot(10, safe_setup)
460+
safe_single_shot(10, safe_setup)
458461

459462
self.say(font_color(f"{self.res.reboot_tip}", cls='theme-highlight', size=4))
460-
QTimer.singleShot(50, retry_all)
463+
safe_single_shot(50, retry_all)
461464
self.retrybtn.setDisabled(True)
462465
self.log.info('===--→ retry_schedule end\n')
463466

GUI/mainwindow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
from PyQt5 import QtCore, QtWidgets
4-
from PyQt5.QtCore import Qt, QTimer
4+
from PyQt5.QtCore import Qt
5+
from GUI.core.timer import safe_single_shot
56
from PyQt5.QtWidgets import QStackedLayout, QWidget, QVBoxLayout, QSizePolicy
67
from qfluentwidgets import (
78
FluentIcon as FIF, ToolButton, ImageLabel, TransparentToolButton, ScrollArea, FlowLayout
@@ -103,7 +104,7 @@ def setup_sleep_widget(self, _img=None):
103104
self.sleepWidget, "sleepLabel", _img or str(ori_path.joinpath("docs/public/cgs_sleep.png")),
104105
init=lambda l: (l.setAlignment(Qt.AlignLeft | Qt.AlignBottom), l.setScaledContents(True)),
105106
)
106-
QTimer.singleShot(0, self._sync_sleep_widget_geometry)
107+
safe_single_shot(0, self._sync_sleep_widget_geometry)
107108

108109
def resizeEvent(self, event):
109110
QtWidgets.QMainWindow.resizeEvent(self, event)

GUI/manager/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import contextlib
33
import subprocess
44

5-
from PyQt5.QtCore import QTimer
5+
from GUI.core.timer import safe_single_shot
66
from qfluentwidgets import (
77
InfoBarPosition, StateToolTip
88
)
@@ -135,7 +135,7 @@ def to_update(recv):
135135
f"""<{ver}>""", _type="SUCCESS")
136136
_close_thread()
137137
self.gui.update_notifier.on_updated_or_dismissed()
138-
QTimer.singleShot(4000, lambda: self.to_update(ver))
138+
safe_single_shot(4000, lambda: self.to_update(ver))
139139

140140
def checked(recv):
141141
with contextlib.suppress(RuntimeError):
@@ -175,7 +175,7 @@ def checked(recv):
175175
def rerun(self):
176176
cmd = ["cgs"]
177177
subprocess.Popen(cmd, cwd=exc_p, env=env)
178-
QTimer.singleShot(1000, self.gui.close)
178+
safe_single_shot(1000, self.gui.close)
179179

180180
def to_update(self, ver):
181181
_UpdateLauncher(ver).run()

GUI/manager/ags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from PyQt5.QtCore import QTimer
3+
from GUI.core.timer import safe_single_shot
34

45
from utils.website.info import BookInfo
56
from utils import conf
@@ -72,7 +73,7 @@ def delayed_mark():
7273
dled_bidxes.append(key)
7374
js_code = f'''tryMarkDownload({dled_bidxes},[]);'''
7475
self.gui.BrowserWindow.js_execute_by_page(self.page, js_code, lambda _: None)
75-
QTimer.singleShot(300, delayed_mark)
76+
safe_single_shot(300, delayed_mark)
7677
self.gui.BrowserWindow.refreshBtn.click()
7778
if self.gui.BrowserWindow.topHintBox.isChecked():
7879
self.gui.BrowserWindow.topHintBox.click()

GUI/manager/async_task.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import traceback
88
from typing import Any, Callable, Dict, List, Optional, Tuple
99

10-
from PyQt5.QtCore import QObject, Qt, QThread, QTimer, pyqtSignal
10+
from PyQt5.QtCore import QObject, Qt, QThread, pyqtSignal
11+
from GUI.core.timer import safe_single_shot
1112
from qfluentwidgets import InfoBar, InfoBarPosition, StateToolTip
1213

1314

@@ -124,7 +125,7 @@ def complete(self, task_id: str, auto_hide: bool):
124125
return
125126
if auto_hide:
126127
tooltip.setState(True)
127-
QTimer.singleShot(self.CLOSE_DELAY_MS, lambda tid=task_id: self.close(tid))
128+
safe_single_shot(self.CLOSE_DELAY_MS, lambda tid=task_id: self.close(tid))
128129
return
129130
tooltip.setContent("任务已完成")
130131

GUI/manager/clip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import pathlib
3-
from PyQt5.QtCore import Qt, QTimer
3+
from PyQt5.QtCore import Qt
4+
from GUI.core.timer import safe_single_shot
45
from qfluentwidgets import InfoBar, InfoBarPosition
56

67
from assets import res
@@ -120,7 +121,7 @@ def delayed_mark():
120121
dled_eidxes.append(key)
121122
js_code = f'''tryMarkDownload({dled_bidxes},{dled_eidxes});'''
122123
self.gui.BrowserWindow.js_execute_by_page(self.page, js_code, lambda _: None)
123-
QTimer.singleShot(300, delayed_mark)
124+
safe_single_shot(300, delayed_mark)
124125
self.gui.BrowserWindow.refreshBtn.click()
125126
if self.gui.BrowserWindow.topHintBox.isChecked():
126127
self.gui.BrowserWindow.topHintBox.click()

0 commit comments

Comments
 (0)