Move Onion and OnionShare app objects into the main window

This commit is contained in:
Micah Lee 2019-10-20 20:11:45 -07:00
parent e51be47844
commit 2a07a3572f
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 23 additions and 21 deletions

View File

@ -27,8 +27,6 @@ import psutil
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
from onionshare.common import Common from onionshare.common import Common
from onionshare.onion import Onion
from onionshare.onionshare import OnionShare
from .gui_common import GuiCommon from .gui_common import GuiCommon
from .widgets import Alert from .widgets import Alert
@ -158,19 +156,12 @@ def main():
# TODO: open tab # TODO: open tab
return return
# Start the Onion
onion = Onion(common)
# Start the OnionShare app
app = OnionShare(common, onion, local_only)
# Launch the gui # 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 # Clean up when app quits
def shutdown(): def shutdown():
onion.cleanup() main_window.cleanup()
app.cleanup()
qtapp.aboutToQuit.connect(shutdown) qtapp.aboutToQuit.connect(shutdown)

View File

@ -23,6 +23,9 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from onionshare import strings from onionshare import strings
from onionshare.web import Web from onionshare.web import Web
from onionshare.onion import Onion
from onionshare.onionshare import OnionShare
from .mode.share_mode import ShareMode from .mode.share_mode import ShareMode
from .mode.receive_mode import ReceiveMode from .mode.receive_mode import ReceiveMode
from .mode.website_mode import WebsiteMode 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 MainWindow is the OnionShare main window, which contains the GUI elements, including all open tabs
""" """
def __init__( def __init__(self, common, qtapp, filenames, config=False, local_only=False):
self, common, onion, qtapp, app, filenames, config=False, local_only=False
):
super(MainWindow, self).__init__() super(MainWindow, self).__init__()
self.common = common self.common = common
self.common.log("MainWindow", "__init__") self.common.log("MainWindow", "__init__")
self.setMinimumWidth(820)
self.setMinimumHeight(660)
self.onion = onion
self.qtapp = qtapp self.qtapp = qtapp
self.app = app
self.local_only = local_only self.local_only = local_only
self.mode = self.common.gui.MODE_SHARE 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.setWindowTitle("OnionShare")
self.setWindowIcon( self.setWindowIcon(
QtGui.QIcon(self.common.get_resource_path("images/logo.png")) QtGui.QIcon(self.common.get_resource_path("images/logo.png"))
@ -157,7 +164,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.share_mode = ShareMode( self.share_mode = ShareMode(
self.common, self.common,
qtapp, qtapp,
app, self.app,
self.status_bar, self.status_bar,
self.server_status_label, self.server_status_label,
self.system_tray, self.system_tray,
@ -188,7 +195,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.receive_mode = ReceiveMode( self.receive_mode = ReceiveMode(
self.common, self.common,
qtapp, qtapp,
app, self.app,
self.status_bar, self.status_bar,
self.server_status_label, self.server_status_label,
self.system_tray, self.system_tray,
@ -221,7 +228,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.website_mode = WebsiteMode( self.website_mode = WebsiteMode(
self.common, self.common,
qtapp, qtapp,
app, self.app,
self.status_bar, self.status_bar,
self.server_status_label, self.server_status_label,
self.system_tray, self.system_tray,
@ -756,3 +763,7 @@ class MainWindow(QtWidgets.QMainWindow):
except: except:
e.accept() e.accept()
def cleanup(self):
self.onion.cleanup()
self.app.cleanup()