From a4e353c830e0d2d6d014698c6b252ef2ef856dbb Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 23 Jun 2017 12:42:39 +0200 Subject: [PATCH] Download buttons are now disabled when another plugin is being downloaded CURA-3856 --- plugins/PluginBrowser/PluginBrowser.py | 16 +++++++++++++++- plugins/PluginBrowser/PluginBrowser.qml | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/PluginBrowser/PluginBrowser.py b/plugins/PluginBrowser/PluginBrowser.py index 251ed92d2f..eeaebdae4c 100644 --- a/plugins/PluginBrowser/PluginBrowser.py +++ b/plugins/PluginBrowser/PluginBrowser.py @@ -41,8 +41,16 @@ class PluginBrowser(QObject, Extension): self._dialog = None self._download_progress = 0 + self._is_downloading = False + + pluginsMetadataChanged = pyqtSignal() onDownloadProgressChanged = pyqtSignal() + onIsDownloadingChanged = pyqtSignal() + + @pyqtProperty(bool, notify = onIsDownloadingChanged) + def isDownloading(self): + return self._is_downloading def browsePlugins(self): self._createNetworkManager() @@ -71,6 +79,11 @@ class PluginBrowser(QObject, Extension): Logger.log("e", "QQmlComponent status %s", self._qml_component.status()) Logger.log("e", "QQmlComponent errorString %s", self._qml_component.errorString()) + def setIsDownloading(self, is_downloading): + if self._is_downloading != is_downloading: + self._is_downloading = is_downloading + self.onIsDownloadingChanged.emit() + def _onDownloadPluginProgress(self, bytes_sent, bytes_total): if bytes_total > 0: new_progress = bytes_sent / bytes_total * 100 @@ -79,6 +92,7 @@ class PluginBrowser(QObject, Extension): self.onDownloadProgressChanged.emit() self._download_progress = new_progress if new_progress == 100.0: + self.setIsDownloading(False) self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadPluginProgress) self._temp_plugin_file = tempfile.NamedTemporaryFile(suffix = ".curaplugin") self._temp_plugin_file.write(self._download_plugin_reply.readAll()) @@ -96,6 +110,7 @@ class PluginBrowser(QObject, Extension): self._download_plugin_request = QNetworkRequest(url) self._download_plugin_reply = self._network_manager.get(self._download_plugin_request) self._download_progress = 0 + self.setIsDownloading(True) self.onDownloadProgressChanged.emit() self._download_plugin_reply.downloadProgress.connect(self._onDownloadPluginProgress) @@ -134,7 +149,6 @@ class PluginBrowser(QObject, Extension): return False return True - def _onRequestFinished(self, reply): reply_url = reply.url().toString() if reply.operation() == QNetworkAccessManager.GetOperation: diff --git a/plugins/PluginBrowser/PluginBrowser.qml b/plugins/PluginBrowser/PluginBrowser.qml index 849d2b4a8b..0258763a19 100644 --- a/plugins/PluginBrowser/PluginBrowser.qml +++ b/plugins/PluginBrowser/PluginBrowser.qml @@ -8,7 +8,7 @@ UM.Dialog { id: base - title: "YAY" + title: "Find & Update plugins" width: 450 height: 150 ScrollView @@ -63,10 +63,10 @@ UM.Dialog } Button { - text: enabled ? "Download" : "Already Installed" + text: !model.already_installed ? "Download" : "Already Installed" onClicked: manager.downloadAndInstallPlugin(model.file_location) anchors.right: parent.right - enabled: !model.already_installed + enabled: !model.already_installed && !manager.isDownloading } }