def close_tab(self, tab=None): tab = tab or self.current_tab if tab is not None: self.delete_removed_tabs(self.tab_tree.remove_tab(tab)) if not self.tabs: self.open_url(WELCOME_URL, switch_to_tab=True) QTimer.singleShot(0, self.current_tab_changed)
def restart(self): self.player_view.close() self.player_view = PlayerView(self.rect() - QMargins(0, 210, 0, 0), parent=self) # self.show_overlay() QTimer.singleShot(500, self.show_overlay) self.startButton.setEnabled(False)
def __init__(self, size=10 * 1024 * 1024): QObject.__init__(self) self._state = QWebEngineDownloadRequest.DownloadState.DownloadRequested self._received = self._total = -1 FakeDownloadItem.idc += 1 self._id = FakeDownloadItem.idc self._size = size self.fname = '%s.epub' % self.id() self.mimeType = lambda: mimetypes.guess_type(self.fname)[0] QTimer.singleShot(100, self._tick)
def call_auto_get_cookie(self): """自动读取浏览器cookie槽函数""" try: self._cookie = get_cookie_from_browser() except Exception as e: logger.error(f"Browser_cookie3 Error: {e}") self.auto_get_cookie_ok.setPlainText(f"❌获取失败,错误信息\n{e}") else: if self._cookie: self._user = self._pwd = '' self.auto_get_cookie_ok.setPlainText("✅获取成功即将登录……") QTimer.singleShot(2000, self._close_dialog) else: self.auto_get_cookie_ok.setPlainText("❌获取失败\n请提前使用支持的浏览器登录蓝奏云,读取前完全退出浏览器!\n支持的浏览器与顺序:\nchrome, chromium, opera, edge, firefox")
def run_app(urls=(), callback=None, callback_wait=0, master_password=None, new_instance=False, shutdown=False, restart_state=None, no_session=False, startup_session=None): env = os.environ.copy() app = Application(master_password=master_password, urls=urls, new_instance=new_instance, shutdown=shutdown, restart_state=restart_state, no_session=no_session) os.environ['QTWEBENGINE_DICTIONARIES_PATH'] = os.path.join( config_dir, 'spell') original_env = env style = Style() app.setStyle(style) try: if startup_session is not None: with open(startup_session, 'rb') as f: app.unserialize_state(pickle.load(f)) elif restart_state is not None: app.unserialize_state(restart_state) else: last_session = last_saved_session(no_session) if last_session is None or urls: app.open_urls(urls) else: app.unserialize_state(last_session) if callback is not None: QTimer.singleShot(callback_wait, callback) app.exec() finally: app.break_cycles() delete_profile() places.close() app.sendPostedEvents() restart_state = getattr(app, 'restart_state', None) sip.delete(app) del app gc.collect(), gc.collect(), gc.collect() if restart_state is not None: restart(restart_state, original_env)
def _tick(self): if self._state not in (QWebEngineDownloadRequest.DownloadState.DownloadInProgress, QWebEngineDownloadRequest.DownloadState.DownloadRequested): return if self._total == -1: self._total = self._size self._received = 0 self._state = QWebEngineDownloadRequest.DownloadState.DownloadInProgress self.stateChanged.emit(self._state) self.downloadProgress.emit(self._received, self._total) QTimer.singleShot(100, self._tick) elif self._received < self._total: self._received += min(self._total - self._received, self._size // 100) self.downloadProgress.emit(self._received, self._total) if self._received >= self._total: self._state = QWebEngineDownloadRequest.DownloadState.DownloadCompleted self.stateChanged.emit(self._state) self.finished.emit() else: QTimer.singleShot(100, self._tick)
def _game_over(self, result: GameResult) -> None: # QTimer is used to allow the last letter guessed to show up immediately QTimer.singleShot(0, lambda: self._result_dialog.exec(result))
def _new_game(self) -> None: self.label_word.clear() self.label_available_letters.clear() self.label_guessed_letters.clear() self._show_spinner() QTimer.singleShot(_spinner_delay, self._game.new_game)
def run_async(func, *args): QTimer.singleShot(0, functools.partial(func, *args))
import sys from PyQt6.QtCore import Qt, QTimer from PyQt6.QtWidgets import QApplication, QLabel if __name__ == '__main__': app = QApplication(sys.argv) label = QLabel( '<font color=red size=128><b>Hello PyQt,窗口在 10 秒后消失</b></font>') label.show() QTimer.singleShot(10000, app.quit) sys.exit(app.exec())