mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Disable sync button while in progress
Need to show a bit more feedback I think. Let's see what the design said... Contributes to issue CURA-8609.
This commit is contained in:
parent
9729f4f3d2
commit
e7b49ee551
3 changed files with 30 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
import copy # To duplicate materials.
|
import copy # To duplicate materials.
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QUrl
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from typing import Any, Dict, Optional, TYPE_CHECKING
|
from typing import Any, Dict, Optional, TYPE_CHECKING
|
||||||
import uuid # To generate new GUIDs for new materials.
|
import uuid # To generate new GUIDs for new materials.
|
||||||
|
@ -35,6 +35,7 @@ class MaterialManagementModel(QObject):
|
||||||
def __init__(self, parent: QObject = None):
|
def __init__(self, parent: QObject = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._sync_all_dialog = None # type: Optional[QObject]
|
self._sync_all_dialog = None # type: Optional[QObject]
|
||||||
|
self._export_upload_status = "idle"
|
||||||
self._checkIfNewMaterialsWereInstalled()
|
self._checkIfNewMaterialsWereInstalled()
|
||||||
|
|
||||||
def _checkIfNewMaterialsWereInstalled(self) -> None:
|
def _checkIfNewMaterialsWereInstalled(self) -> None:
|
||||||
|
@ -330,12 +331,11 @@ class MaterialManagementModel(QObject):
|
||||||
"""
|
"""
|
||||||
if self._sync_all_dialog is None:
|
if self._sync_all_dialog is None:
|
||||||
qml_path = Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.QmlFiles, "Preferences", "Materials", "MaterialsSyncDialog.qml")
|
qml_path = Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.QmlFiles, "Preferences", "Materials", "MaterialsSyncDialog.qml")
|
||||||
self._sync_all_dialog = cura.CuraApplication.CuraApplication.getInstance().createQmlComponent(qml_path, {
|
self._sync_all_dialog = cura.CuraApplication.CuraApplication.getInstance().createQmlComponent(qml_path, {})
|
||||||
"materialManagementModel": self,
|
|
||||||
"pageIndex": 0
|
|
||||||
})
|
|
||||||
if self._sync_all_dialog is None: # Failed to load QML file.
|
if self._sync_all_dialog is None: # Failed to load QML file.
|
||||||
return
|
return
|
||||||
|
self._sync_all_dialog.setProperty("materialManagementModel", self)
|
||||||
|
self._sync_all_dialog.setProperty("pageIndex", 0) # Return to first page.
|
||||||
self._sync_all_dialog.show()
|
self._sync_all_dialog.show()
|
||||||
|
|
||||||
@pyqtSlot(result = QUrl)
|
@pyqtSlot(result = QUrl)
|
||||||
|
@ -388,10 +388,23 @@ class MaterialManagementModel(QObject):
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Logger.log("e", f"An error has occurred while writing the material \'{metadata['id']}\' in the file \'{filename}\': {e}.")
|
Logger.log("e", f"An error has occurred while writing the material \'{metadata['id']}\' in the file \'{filename}\': {e}.")
|
||||||
|
|
||||||
|
exportUploadStatusChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtProperty(str, notify = exportUploadStatusChanged)
|
||||||
|
def exportUploadStatus(self):
|
||||||
|
return self._export_upload_status
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def exportUpload(self) -> None:
|
def exportUpload(self) -> None:
|
||||||
"""
|
"""
|
||||||
Export all materials and upload them to the user's account.
|
Export all materials and upload them to the user's account.
|
||||||
"""
|
"""
|
||||||
|
self._export_upload_status = "uploading"
|
||||||
|
self.exportUploadStatusChanged.emit()
|
||||||
job = UploadMaterialsJob()
|
job = UploadMaterialsJob()
|
||||||
|
job.uploadCompleted.connect(self.exportUploadCompleted)
|
||||||
job.start()
|
job.start()
|
||||||
|
|
||||||
|
def exportUploadCompleted(self):
|
||||||
|
self._export_upload_status = "idle"
|
||||||
|
self.exportUploadStatusChanged.emit()
|
|
@ -11,6 +11,7 @@ from cura.UltimakerCloud import UltimakerCloudConstants # To know where the API
|
||||||
from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To know how to communicate with this server.
|
from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To know how to communicate with this server.
|
||||||
from UM.Job import Job
|
from UM.Job import Job
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Signal import Signal
|
||||||
from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To call the API.
|
from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To call the API.
|
||||||
from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope
|
from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ class UploadMaterialsJob(Job):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
|
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
|
||||||
|
|
||||||
|
uploadCompleted = Signal()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
|
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
|
||||||
archive_file.close()
|
archive_file.close()
|
||||||
|
@ -78,6 +81,7 @@ class UploadMaterialsJob(Job):
|
||||||
self.setResult(self.Result.FAILED)
|
self.setResult(self.Result.FAILED)
|
||||||
return
|
return
|
||||||
self.setResult(self.Result.SUCCESS)
|
self.setResult(self.Result.SUCCESS)
|
||||||
|
self.uploadCompleted.emit()
|
||||||
|
|
||||||
def onError(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]):
|
def onError(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]):
|
||||||
pass # TODO: Handle errors.
|
pass # TODO: Handle errors.
|
|
@ -355,6 +355,14 @@ Window
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
text: catalog.i18nc("@button", "Sync")
|
text: catalog.i18nc("@button", "Sync")
|
||||||
onClicked: materialManagementModel.exportUpload()
|
onClicked: materialManagementModel.exportUpload()
|
||||||
|
enabled:
|
||||||
|
{
|
||||||
|
if(!materialManagementModel)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return materialManagementModel.exportUploadStatus != "uploading";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue