Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename QtSingleApplication.activation_window() to tribler_window #6830

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/tribler/gui/single_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -24,10 +26,9 @@ def __init__(self, win_id, *argv):
f'Sys argv: "{sys.argv}"')

QApplication.__init__(self, *argv)
self.tribler_window: Optional[TriblerWindow] = None

self._id = win_id
self._activation_window = None
self._activate_on_message = False

# Is there another instance running?
self._outSocket = QLocalSocket()
Expand Down Expand Up @@ -74,19 +75,6 @@ def is_running(self):
def get_id(self):
return self._id

def activation_window(self):
return self._activation_window

def set_activation_window(self, activation_window, activate_on_message=True):
self._activation_window = activation_window
self._activate_on_message = activate_on_message

def activate_window(self):
if not self._activation_window:
return
self._activation_window.setWindowState(self._activation_window.windowState() & ~Qt.WindowMinimized)
self._activation_window.raise_()

def send_message(self, msg):
self.logger.info(f'Send message: {msg}')
if not self._outStream:
Expand All @@ -104,8 +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)
if self._activate_on_message:
self.activate_window()
if self.tribler_window:
self.tribler_window.restore_from_minimised()

def _on_ready_read(self):
while True:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/start_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run_gui(api_port, api_key, root_state_dir, parsed_args):
logger.info('Start Tribler Window')
window = TriblerWindow(app_manager, settings, root_state_dir, api_port=api_port, api_key=api_key)
window.setWindowTitle("Tribler")
app.set_activation_window(window)
app.tribler_window = window
app.parse_sys_args(sys.argv)
sys.exit(app.exec_())

Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fixture_window(tmpdir_factory):
api_key=api_key,
core_args=[str(RUN_TRIBLER_PY.absolute()), '--core', '--gui-test-mode'],
)
app.set_activation_window(window)
app.tribler_window = window
QTest.qWaitForWindowExposed(window)

screenshot(window, name="tribler_loading")
Expand Down
12 changes: 4 additions & 8 deletions src/tribler/gui/tribler_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ def on_app_message(self, msg):
self.handle_uri(msg)

def handle_uri(self, uri):
if not self.activation_window():
return

self.activation_window().pending_uri_requests.append(uri)
if self.activation_window().tribler_started and not self.activation_window().start_download_dialog_active:
self.activation_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:]:
Expand All @@ -52,9 +48,9 @@ def parse_sys_args(self, args):
if '--allow-code-injection' in sys.argv[1:]:
variables = globals().copy()
variables.update(locals())
variables['window'] = self.activation_window()
variables['window'] = self.tribler_window
self.code_executor = CodeExecutor(5500, shell_variables=variables)
connect(self.activation_window().tribler_crashed, self.code_executor.on_crash)
connect(self.tribler_window.tribler_crashed, self.code_executor.on_crash)

if '--testnet' in sys.argv[1:]:
os.environ['TESTNET'] = "YES"
Expand Down
77 changes: 52 additions & 25 deletions src/tribler/gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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'))

Expand Down Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()