From 2a07a3572fca87e128e185ec11d411d2f97860fd Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 20 Oct 2019 20:11:45 -0700 Subject: [PATCH] Move Onion and OnionShare app objects into the main window --- onionshare_gui/__init__.py | 13 ++----------- onionshare_gui/main_window.py | 31 +++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/onionshare_gui/__init__.py b/onionshare_gui/__init__.py index 0dff4229..6f2b72ab 100644 --- a/onionshare_gui/__init__.py +++ b/onionshare_gui/__init__.py @@ -27,8 +27,6 @@ import psutil from PyQt5 import QtCore, QtWidgets from onionshare.common import Common -from onionshare.onion import Onion -from onionshare.onionshare import OnionShare from .gui_common import GuiCommon from .widgets import Alert @@ -158,19 +156,12 @@ def main(): # TODO: open tab return - # Start the Onion - onion = Onion(common) - - # Start the OnionShare app - app = OnionShare(common, onion, local_only) - # Launch the gui - gui = MainWindow(common, onion, qtapp, app, filenames, config, local_only) + main_window = MainWindow(common, qtapp, filenames, config, local_only) # Clean up when app quits def shutdown(): - onion.cleanup() - app.cleanup() + main_window.cleanup() qtapp.aboutToQuit.connect(shutdown) diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index de658a1b..6db40473 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -23,6 +23,9 @@ from PyQt5 import QtCore, QtWidgets, QtGui from onionshare import strings from onionshare.web import Web +from onionshare.onion import Onion +from onionshare.onionshare import OnionShare + from .mode.share_mode import ShareMode from .mode.receive_mode import ReceiveMode from .mode.website_mode import WebsiteMode @@ -39,23 +42,27 @@ class MainWindow(QtWidgets.QMainWindow): MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs """ - def __init__( - self, common, onion, qtapp, app, filenames, config=False, local_only=False - ): + def __init__(self, common, qtapp, filenames, config=False, local_only=False): super(MainWindow, self).__init__() self.common = common self.common.log("MainWindow", "__init__") - self.setMinimumWidth(820) - self.setMinimumHeight(660) - self.onion = onion self.qtapp = qtapp - self.app = app self.local_only = local_only self.mode = self.common.gui.MODE_SHARE + # Start the Onion + self.onion = Onion(common) + + # Start the OnionShare app + self.app = OnionShare(common, self.onion, local_only) + + # Initialize the window + self.setMinimumWidth(820) + self.setMinimumHeight(660) + self.setWindowTitle("OnionShare") self.setWindowIcon( QtGui.QIcon(self.common.get_resource_path("images/logo.png")) @@ -157,7 +164,7 @@ class MainWindow(QtWidgets.QMainWindow): self.share_mode = ShareMode( self.common, qtapp, - app, + self.app, self.status_bar, self.server_status_label, self.system_tray, @@ -188,7 +195,7 @@ class MainWindow(QtWidgets.QMainWindow): self.receive_mode = ReceiveMode( self.common, qtapp, - app, + self.app, self.status_bar, self.server_status_label, self.system_tray, @@ -221,7 +228,7 @@ class MainWindow(QtWidgets.QMainWindow): self.website_mode = WebsiteMode( self.common, qtapp, - app, + self.app, self.status_bar, self.server_status_label, self.system_tray, @@ -756,3 +763,7 @@ class MainWindow(QtWidgets.QMainWindow): except: e.accept() + + def cleanup(self): + self.onion.cleanup() + self.app.cleanup()