Format all code using black

This commit is contained in:
Micah Lee 2019-10-12 21:01:25 -07:00
parent 90c244ee2f
commit 3037727890
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
87 changed files with 4293 additions and 2374 deletions

View file

@ -24,10 +24,12 @@ from onionshare.onion import *
from .widgets import Alert
class TorConnectionDialog(QtWidgets.QProgressDialog):
"""
Connecting to Tor dialog.
"""
open_settings = QtCore.pyqtSignal()
def __init__(self, common, qtapp, onion, custom_settings=False):
@ -40,18 +42,20 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
else:
self.settings = self.common.settings
self.common.log('TorConnectionDialog', '__init__')
self.common.log("TorConnectionDialog", "__init__")
self.qtapp = qtapp
self.onion = onion
self.setWindowTitle("OnionShare")
self.setWindowIcon(QtGui.QIcon(self.common.get_resource_path('images/logo.png')))
self.setWindowIcon(
QtGui.QIcon(self.common.get_resource_path("images/logo.png"))
)
self.setModal(True)
self.setFixedSize(400, 150)
# Label
self.setLabelText(strings._('connecting_to_tor'))
self.setLabelText(strings._("connecting_to_tor"))
# Progress bar ticks from 0 to 100
self.setRange(0, 100)
@ -59,10 +63,10 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
self.setMinimumDuration(100)
# Start displaying the status at 0
self._tor_status_update(0, '')
self._tor_status_update(0, "")
def start(self):
self.common.log('TorConnectionDialog', 'start')
self.common.log("TorConnectionDialog", "start")
t = TorConnectionThread(self.common, self.settings, self, self.onion)
t.tor_status_update.connect(self._tor_status_update)
@ -81,17 +85,19 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
def _tor_status_update(self, progress, summary):
self.setValue(int(progress))
self.setLabelText("<strong>{}</strong><br>{}".format(strings._('connecting_to_tor'), summary))
self.setLabelText(
"<strong>{}</strong><br>{}".format(strings._("connecting_to_tor"), summary)
)
def _connected_to_tor(self):
self.common.log('TorConnectionDialog', '_connected_to_tor')
self.common.log("TorConnectionDialog", "_connected_to_tor")
self.active = False
# Close the dialog after connecting
self.setValue(self.maximum())
def _canceled_connecting_to_tor(self):
self.common.log('TorConnectionDialog', '_canceled_connecting_to_tor')
self.common.log("TorConnectionDialog", "_canceled_connecting_to_tor")
self.active = False
self.onion.cleanup()
@ -99,12 +105,16 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
QtCore.QTimer.singleShot(1, self.cancel)
def _error_connecting_to_tor(self, msg):
self.common.log('TorConnectionDialog', '_error_connecting_to_tor')
self.common.log("TorConnectionDialog", "_error_connecting_to_tor")
self.active = False
def alert_and_open_settings():
# Display the exception in an alert box
Alert(self.common, "{}\n\n{}".format(msg, strings._('gui_tor_connection_error_settings')), QtWidgets.QMessageBox.Warning)
Alert(
self.common,
"{}\n\n{}".format(msg, strings._("gui_tor_connection_error_settings")),
QtWidgets.QMessageBox.Warning,
)
# Open settings
self.open_settings.emit()
@ -114,6 +124,7 @@ class TorConnectionDialog(QtWidgets.QProgressDialog):
# Cancel connecting to Tor
QtCore.QTimer.singleShot(1, self.cancel)
class TorConnectionThread(QtCore.QThread):
tor_status_update = QtCore.pyqtSignal(str, str)
connected_to_tor = QtCore.pyqtSignal()
@ -125,7 +136,7 @@ class TorConnectionThread(QtCore.QThread):
self.common = common
self.common.log('TorConnectionThread', '__init__')
self.common.log("TorConnectionThread", "__init__")
self.settings = settings
@ -133,7 +144,7 @@ class TorConnectionThread(QtCore.QThread):
self.onion = onion
def run(self):
self.common.log('TorConnectionThread', 'run')
self.common.log("TorConnectionThread", "run")
# Connect to the Onion
try:
@ -144,11 +155,15 @@ class TorConnectionThread(QtCore.QThread):
self.canceled_connecting_to_tor.emit()
except BundledTorCanceled as e:
self.common.log('TorConnectionThread', 'run', 'caught exception: BundledTorCanceled')
self.common.log(
"TorConnectionThread", "run", "caught exception: BundledTorCanceled"
)
self.canceled_connecting_to_tor.emit()
except Exception as e:
self.common.log('TorConnectionThread', 'run', 'caught exception: {}'.format(e.args[0]))
self.common.log(
"TorConnectionThread", "run", "caught exception: {}".format(e.args[0])
)
self.error_connecting_to_tor.emit(str(e.args[0]))
def _tor_status_update(self, progress, summary):