Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Mar 24, 2022
1 parent d91680a commit a1b98f3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 40 deletions.
15 changes: 6 additions & 9 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,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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 2 additions & 6 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.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:]:
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()

0 comments on commit a1b98f3

Please sign in to comment.