Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Code style and strings

Co-authored-by: Carlos Cordoba <ccordoba12@gmail.com>
  • Loading branch information
dalthviz and ccordoba12 committed Oct 10, 2022
1 parent 8a1fbe2 commit c7fa3a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
5 changes: 4 additions & 1 deletion spyder/plugins/application/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def __init__(self, name, plugin, parent=None):
# Keep track of dpi message
self.current_dpi = None
self.dpi_messagebox = None
# Keep track of downloaded installer executable for updates

# Keep track of the downloaded installer executable for updates
self.installer_path = None

# ---- PluginMainContainer API
Expand Down Expand Up @@ -232,6 +233,8 @@ def on_close(self):
if self.dependencies_thread is not None:
self.dependencies_thread.quit()
self.dependencies_thread.wait()

# Run installer after Spyder is closed
cmd = ('start' if os.name == 'nt' else 'open')
if self.installer_path:
subprocess.Popen(' '.join([cmd, self.installer_path]), shell=True)
Expand Down
29 changes: 18 additions & 11 deletions spyder/plugins/application/widgets/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class UpdateInstallerDialog(QDialog):
Parameters
----------
installer_path: str
Path to installer executable.
Path to the installer executable.
"""

def __init__(self, parent):
Expand All @@ -150,6 +150,7 @@ def __init__(self, parent):
self.download_thread = None
self.download_worker = None
self.installer_path = None

super().__init__(parent)
self.setWindowFlags(Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint)
self._parent = parent
Expand Down Expand Up @@ -181,7 +182,7 @@ def reject(self):
if on_installation_widget:
self.close_installer()
else:
super(UpdateInstallerDialog, self).reject()
super().reject()

def setup(self):
"""Setup visibility of widgets."""
Expand All @@ -192,7 +193,7 @@ def save_latest_release(self, latest_release_version):
self.latest_release_version = latest_release_version

def start_installation(self, latest_release_version):
"""Start the update download and set downloading status."""
"""Start downloading the update and set downloading status."""
self.latest_release_version = latest_release_version
self.cancelled = False
self._change_update_installation_status(
Expand Down Expand Up @@ -249,11 +250,12 @@ def confirm_installation(self, installer_path):
return
self._change_update_installation_status(status=DOWNLOAD_FINISHED)
self.installer_path = installer_path
msg_box = QMessageBox(icon=QMessageBox.Question,
text=_("Would you like to proceed with the "
"installation?<br><br>"),
parent=self._parent)
msg_box.setWindowTitle("Spyder")
msg_box = QMessageBox(
icon=QMessageBox.Question,
text=_("Would you like to proceed with the installation?<br><br>"),
parent=self._parent
)
msg_box.setWindowTitle(_("Spyder update"))
msg_box.setAttribute(Qt.WA_ShowWithoutActivating)
if is_pynsist():
# Only add yes button for Windows installer
Expand All @@ -265,12 +267,15 @@ def confirm_installation(self, installer_path):
_("After closing"), QMessageBox.YesRole)
msg_box.addButton(QMessageBox.No)
msg_box.exec_()

if msg_box.clickedButton() == yes_button:
self._change_update_installation_status(status=INSTALLING)
cmd = ('start' if os.name == 'nt' else 'open')
if self.installer_path:
subprocess.Popen(
' '.join([cmd, self.installer_path]), shell=True)
' '.join([cmd, self.installer_path]),
shell=True
)
self._change_update_installation_status(status=PENDING)
elif msg_box.clickedButton() == after_closing_button:
self.sig_install_on_close_requested.emit(self.installer_path)
Expand All @@ -285,8 +290,10 @@ def finish_installation(self):

def close_installer(self):
"""Close the installation dialog."""
if (self.status == FINISHED
or self.status == CANCELLED):
if (
self.status == FINISHED
or self.status == CANCELLED
):
self.finish_installation()
else:
self.hide()
Expand Down
11 changes: 5 additions & 6 deletions spyder/workers/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ def _download_installer(self):
name = 'Spyder_64bit_{}.exe'.format('full' if is_full_installer
else 'lite')
else:
name = 'Spyder{}.dmg'.format('' if is_full_installer
else '-Lite')
name = 'Spyder{}.dmg'.format('' if is_full_installer else '-Lite')

url = ('https://github.com/spyder-ide/spyder/releases/latest/'
f'download/{name}')
Expand All @@ -202,7 +201,7 @@ def _download_installer(self):

installer_path = osp.join(installer_dir_path, name)
self.installer_path = installer_path
if (not osp.isfile(installer_path)):
if not osp.isfile(installer_path):
logger.debug(
f"Downloading installer from {url} to {installer_path}")
urlretrieve(
Expand All @@ -222,10 +221,10 @@ def start(self):
except HTTPError:
error_msg = _('Unable to retrieve installer information.')
except URLError:
error_msg = _('Unable to connect to the internet. <br><br>Make '
'sure the connection is working properly.')
error_msg = _('Unable to connect to the internet. <br><br>'
'Make sure the connection is working properly.')
except Exception:
error_msg = _('Unable to download installer.')
error_msg = _('Unable to download the installer.')
self.error = error_msg
try:
self.sig_ready.emit(self.installer_path)
Expand Down

0 comments on commit c7fa3a0

Please sign in to comment.