From d9f60a17e49871df417b977354b468efc0dfcfc0 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Sat, 16 Dec 2017 13:37:40 +0100 Subject: [PATCH] canvas/addons: Fix progress dialog showing up when not necessary Create the dialog only when starting a task. --- Orange/canvas/application/addons.py | 46 +++++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/Orange/canvas/application/addons.py b/Orange/canvas/application/addons.py index 273555d0323..94e746c74c4 100644 --- a/Orange/canvas/application/addons.py +++ b/Orange/canvas/application/addons.py @@ -476,22 +476,34 @@ def __init__(self, parent=None, **kwargs): method_queued(self._set_packages, (object,)) ) - self.__progress = QProgressDialog( - self, Qt.Sheet, - minimum=0, maximum=0, - labelText=self.tr("Retrieving package list"), - sizeGripEnabled=False, - windowTitle="Progress" - ) - - self.__progress.rejected.connect(self.reject) + self.__progress = None # type: Optional[QProgressDialog] self.__thread = None self.__installer = None + if not self._f_pypi_addons.done(): + self.__progressDialog() + + def __progressDialog(self): + if self.__progress is None: + self.__progress = QProgressDialog( + self, + minimum=0, maximum=0, + labelText=self.tr("Retrieving package list"), + sizeGripEnabled=False, + windowTitle="Progress", + ) + self.__progress.setWindowModality(Qt.WindowModal) + self.__progress.canceled.connect(self.reject) + self.__progress.hide() + + return self.__progress + @Slot(object) def _set_packages(self, f): - if self.__progress.isVisible(): - self.__progress.close() + if self.__progress is not None: + self.__progress.hide() + self.__progress.deleteLater() + self.__progress = None try: packages = f.result() @@ -550,7 +562,7 @@ def _set_packages(self, f): def showEvent(self, event): super().showEvent(event) - if not self._f_pypi_addons.done(): + if not self._f_pypi_addons.done() and self.__progress is not None: QTimer.singleShot(0, self.__progress.show) def done(self, retcode): @@ -563,6 +575,8 @@ def done(self, retcode): def closeEvent(self, event): super().closeEvent(event) + if self.__progress is not None: + self.__progress.hide() self._f_pypi_addons.cancel() self._executor.shutdown(wait=False) @@ -613,11 +627,11 @@ def __accepted(self): self.__installer.moveToThread(self.__thread) self.__installer.finished.connect(self.__on_installer_finished) self.__installer.error.connect(self.__on_installer_error) - self.__installer.installStatusChanged.connect( - self.__progress.setLabelText) - self.__progress.show() - self.__progress.setLabelText("Installing") + progress = self.__progressDialog() + self.__installer.installStatusChanged.connect(progress.setLabelText) + progress.show() + progress.setLabelText("Installing") self.__installer.start()