From a1b98f334c3f5da19c84a92a5a276b16fab4d645 Mon Sep 17 00:00:00 2001 From: Andrei Andreev Date: Thu, 24 Mar 2022 16:46:16 +0100 Subject: [PATCH] Test --- src/tribler/gui/single_application.py | 15 +++--- src/tribler/gui/tribler_app.py | 8 +-- src/tribler/gui/tribler_window.py | 77 ++++++++++++++++++--------- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/tribler/gui/single_application.py b/src/tribler/gui/single_application.py index f89ea94cbc5..576e56bddcf 100644 --- a/src/tribler/gui/single_application.py +++ b/src/tribler/gui/single_application.py @@ -2,11 +2,13 @@ import logging import sys +from typing import Optional -from PyQt5.QtCore import QTextStream, Qt, pyqtSignal +from PyQt5.QtCore import QTextStream, pyqtSignal from PyQt5.QtNetwork import QLocalServer, QLocalSocket from PyQt5.QtWidgets import QApplication +from tribler.gui.tribler_window import TriblerWindow from tribler.gui.utilities import connect, disconnect @@ -24,7 +26,7 @@ def __init__(self, win_id, *argv): f'Sys argv: "{sys.argv}"') QApplication.__init__(self, *argv) - self.tribler_window = None + self.tribler_window: Optional[TriblerWindow] = None self._id = win_id @@ -73,12 +75,6 @@ def is_running(self): def get_id(self): return self._id - def activate_tribler_window(self): - if not self.tribler_window: - return - self.tribler_window.setWindowState(self.tribler_window.windowState() & ~Qt.WindowMinimized) - self.tribler_window.raise_() - def send_message(self, msg): self.logger.info(f'Send message: {msg}') if not self._outStream: @@ -96,7 +92,8 @@ def _on_new_connection(self): self._inStream = QTextStream(self._inSocket) self._inStream.setCodec('UTF-8') connect(self._inSocket.readyRead, self._on_ready_read) - self.activate_tribler_window() + if self.tribler_window: + self.tribler_window.restore_from_minimised() def _on_ready_read(self): while True: diff --git a/src/tribler/gui/tribler_app.py b/src/tribler/gui/tribler_app.py index 39de34e585e..08e00d5364f 100644 --- a/src/tribler/gui/tribler_app.py +++ b/src/tribler/gui/tribler_app.py @@ -33,12 +33,8 @@ def on_app_message(self, msg): self.handle_uri(msg) def handle_uri(self, uri): - if not self.tribler_window: - return - - self.tribler_window.pending_uri_requests.append(uri) - if self.tribler_window.tribler_started and not self.tribler_window.start_download_dialog_active: - self.tribler_window.process_uri_request() + if self.tribler_window: + self.tribler_window.handle_uri(uri) def parse_sys_args(self, args): for arg in args[1:]: diff --git a/src/tribler/gui/tribler_window.py b/src/tribler/gui/tribler_window.py index f691c58c123..40c3b798875 100644 --- a/src/tribler/gui/tribler_window.py +++ b/src/tribler/gui/tribler_window.py @@ -21,7 +21,14 @@ pyqtSignal, pyqtSlot, ) -from PyQt5.QtGui import QDesktopServices, QFontDatabase, QIcon, QKeyEvent, QKeySequence, QPixmap +from PyQt5.QtGui import ( + QDesktopServices, + QFontDatabase, + QIcon, + QKeyEvent, + QKeySequence, + QPixmap, +) from PyQt5.QtWidgets import ( QAction, QApplication, @@ -80,7 +87,11 @@ from tribler.gui.error_handler import ErrorHandler from tribler.gui.event_request_manager import EventRequestManager from tribler.gui.tribler_action_menu import TriblerActionMenu -from tribler.gui.tribler_request_manager import TriblerNetworkRequest, TriblerRequestManager, request_manager +from tribler.gui.tribler_request_manager import ( + TriblerNetworkRequest, + TriblerRequestManager, + request_manager, +) from tribler.gui.upgrade_manager import UpgradeManager from tribler.gui.utilities import ( connect, @@ -97,8 +108,15 @@ ) from tribler.gui.widgets.channelsmenulistwidget import ChannelsMenuListWidget from tribler.gui.widgets.instanttooltipstyle import InstantTooltipStyle -from tribler.gui.widgets.tablecontentmodel import DiscoveredChannelsModel, PopularTorrentsModel -from tribler.gui.widgets.triblertablecontrollers import PopularContentTableViewController +from tribler.gui.widgets.tablecontentmodel import ( + DiscoveredChannelsModel, + PopularTorrentsModel, +) +from tribler.gui.widgets.triblertablecontrollers import ( + PopularContentTableViewController, +) + +# fmt: off fc_loading_list_item, _ = uic.loadUiType(get_ui_file_path('loading_list_item.ui')) @@ -135,15 +153,15 @@ class TriblerWindow(QMainWindow): received_search_completions = pyqtSignal(object) def __init__( - self, - app_manager: AppManager, - settings, - root_state_dir, - core_args=None, - core_env=None, - api_port=None, - api_key=None, - run_core=True, + self, + app_manager: AppManager, + settings, + root_state_dir, + core_args=None, + core_env=None, + api_port=None, + api_key=None, + run_core=True, ): QMainWindow.__init__(self) self._logger = logging.getLogger(self.__class__.__name__) @@ -598,14 +616,14 @@ def update_recent_download_locations(self, destination): self.gui_settings.setValue("recent_download_locations", ','.join(recent_locations)) def perform_start_download_request( - self, - uri, - anon_download, - safe_seeding, - destination, - selected_files, - add_to_channel=False, - callback=None, + self, + uri, + anon_download, + safe_seeding, + destination, + selected_files, + add_to_channel=False, + callback=None, ): # Check if destination directory is writable is_writable, error = is_dir_writable(destination) @@ -1134,10 +1152,10 @@ def closeEvent(self, close_event): def event(self, event): # Minimize to tray if ( - not DARWIN - and event.type() == QtCore.QEvent.WindowStateChange - and self.window().isMinimized() - and get_gui_setting(self.gui_settings, "minimize_to_tray", False, is_bool=True) + not DARWIN + and event.type() == QtCore.QEvent.WindowStateChange + and self.window().isMinimized() + and get_gui_setting(self.gui_settings, "minimize_to_tray", False, is_bool=True) ): self.window().hide() return True @@ -1275,3 +1293,12 @@ def on_config_error_signal(self, stacktrace): def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() == Qt.Key_Escape: self.escape_pressed.emit() + + def restore_from_minimised(self): + self.setWindowState(self.windowState() & ~Qt.WindowMinimized) + self.raise_() + + def handle_uri(self, uri): + self.pending_uri_requests.append(uri) + if self.tribler_started and not self.start_download_dialog_active: + self.process_uri_request()