mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Track progress from export job
This way we can show a progress bar. Contributes to issue CURA-8609.
This commit is contained in:
parent
052e33e66b
commit
025ef743ee
2 changed files with 27 additions and 6 deletions
|
@ -37,12 +37,13 @@ class UploadMaterialsJob(Job):
|
||||||
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
|
self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope
|
||||||
|
|
||||||
uploadCompleted = Signal()
|
uploadCompleted = Signal()
|
||||||
|
uploadProgressChanged = 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()
|
||||||
|
|
||||||
self._material_sync.exportAll(QUrl.fromLocalFile(archive_file.name))
|
self._material_sync.exportAll(QUrl.fromLocalFile(archive_file.name), notify_progress = self.uploadProgressChanged)
|
||||||
|
|
||||||
http = HttpRequestManager.getInstance()
|
http = HttpRequestManager.getInstance()
|
||||||
http.get(
|
http.get(
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtProperty, 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 Optional
|
from typing import Optional, TYPE_CHECKING
|
||||||
import zipfile # To export all materials in a .zip archive.
|
import zipfile # To export all materials in a .zip archive.
|
||||||
|
|
||||||
import cura.CuraApplication # Imported like this to prevent circular imports.
|
import cura.CuraApplication # Imported like this to prevent circular imports.
|
||||||
|
@ -13,6 +13,8 @@ from UM.i18n import i18nCatalog
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from UM.Signal import Signal
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
class CloudMaterialSync(QObject):
|
class CloudMaterialSync(QObject):
|
||||||
|
@ -25,6 +27,7 @@ class CloudMaterialSync(QObject):
|
||||||
self.sync_all_dialog = None # type: Optional[QObject]
|
self.sync_all_dialog = None # type: Optional[QObject]
|
||||||
self._export_upload_status = "idle"
|
self._export_upload_status = "idle"
|
||||||
self._checkIfNewMaterialsWereInstalled()
|
self._checkIfNewMaterialsWereInstalled()
|
||||||
|
self._export_progress = 0
|
||||||
|
|
||||||
def _checkIfNewMaterialsWereInstalled(self) -> None:
|
def _checkIfNewMaterialsWereInstalled(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -97,13 +100,14 @@ class CloudMaterialSync(QObject):
|
||||||
return cura_application.getDefaultPath("dialog_material_path")
|
return cura_application.getDefaultPath("dialog_material_path")
|
||||||
|
|
||||||
@pyqtSlot(QUrl)
|
@pyqtSlot(QUrl)
|
||||||
def exportAll(self, file_path: QUrl) -> None:
|
def exportAll(self, file_path: QUrl, notify_progress: Optional["Signal"] = None) -> None:
|
||||||
"""
|
"""
|
||||||
Export all materials to a certain file path.
|
Export all materials to a certain file path.
|
||||||
:param file_path: The path to export the materials to.
|
:param file_path: The path to export the materials to.
|
||||||
"""
|
"""
|
||||||
registry = CuraContainerRegistry.getInstance()
|
registry = CuraContainerRegistry.getInstance()
|
||||||
|
|
||||||
|
# Create empty archive.
|
||||||
try:
|
try:
|
||||||
archive = zipfile.ZipFile(file_path.toLocalFile(), "w", compression = zipfile.ZIP_DEFLATED)
|
archive = zipfile.ZipFile(file_path.toLocalFile(), "w", compression = zipfile.ZIP_DEFLATED)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -115,7 +119,12 @@ class CloudMaterialSync(QObject):
|
||||||
)
|
)
|
||||||
error_message.show()
|
error_message.show()
|
||||||
return
|
return
|
||||||
for metadata in registry.findInstanceContainersMetadata(type = "material"):
|
|
||||||
|
materials_metadata = registry.findInstanceContainersMetadata(type = "material")
|
||||||
|
for index, metadata in enumerate(materials_metadata):
|
||||||
|
if notify_progress is not None:
|
||||||
|
progress = index / len(materials_metadata)
|
||||||
|
notify_progress.emit(progress)
|
||||||
if metadata["base_file"] != metadata["id"]: # Only process base files.
|
if metadata["base_file"] != metadata["id"]: # Only process base files.
|
||||||
continue
|
continue
|
||||||
if metadata["id"] == "empty_material": # Don't export the empty material.
|
if metadata["id"] == "empty_material": # Don't export the empty material.
|
||||||
|
@ -131,7 +140,7 @@ class CloudMaterialSync(QObject):
|
||||||
exportUploadStatusChanged = pyqtSignal()
|
exportUploadStatusChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty(str, notify = exportUploadStatusChanged)
|
@pyqtProperty(str, notify = exportUploadStatusChanged)
|
||||||
def exportUploadStatus(self):
|
def exportUploadStatus(self) -> str:
|
||||||
return self._export_upload_status
|
return self._export_upload_status
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
|
@ -142,6 +151,7 @@ class CloudMaterialSync(QObject):
|
||||||
self._export_upload_status = "uploading"
|
self._export_upload_status = "uploading"
|
||||||
self.exportUploadStatusChanged.emit()
|
self.exportUploadStatusChanged.emit()
|
||||||
job = UploadMaterialsJob(self)
|
job = UploadMaterialsJob(self)
|
||||||
|
job.uploadProgressChanged.connect(self.setExportProgress)
|
||||||
job.uploadCompleted.connect(self.exportUploadCompleted)
|
job.uploadCompleted.connect(self.exportUploadCompleted)
|
||||||
job.start()
|
job.start()
|
||||||
|
|
||||||
|
@ -151,4 +161,14 @@ class CloudMaterialSync(QObject):
|
||||||
self._export_upload_status = "error"
|
self._export_upload_status = "error"
|
||||||
else:
|
else:
|
||||||
self._export_upload_status = "success"
|
self._export_upload_status = "success"
|
||||||
self.exportUploadStatusChanged.emit()
|
self.exportUploadStatusChanged.emit()
|
||||||
|
|
||||||
|
exportProgressChanged = pyqtSignal(float)
|
||||||
|
|
||||||
|
def setExportProgress(self, progress: float) -> None:
|
||||||
|
self._export_progress = progress
|
||||||
|
self.exportProgressChanged.emit(self._export_progress)
|
||||||
|
|
||||||
|
@pyqtProperty(float, fset = setExportProgress, notify = exportProgressChanged)
|
||||||
|
def exportProgress(self) -> float:
|
||||||
|
return self._export_progress
|
Loading…
Add table
Add a link
Reference in a new issue