Properly retrieve snapshot (now made on slice).

Circumvents the snapshot/thumbnail not working when the focus is not on the main window, even if the thread is main. This was an issue when writing a file to Digital Factory becasue that workflow uses a modal window.

Thanks for the idea Jelle!
This commit is contained in:
Remco Burema 2021-01-21 08:55:45 +01:00
parent 4fc0612806
commit f4ef3b44e3
No known key found for this signature in database
GPG key ID: 215C49431D43F98C
2 changed files with 3 additions and 6 deletions

View file

@ -257,7 +257,7 @@ class CuraEngineBackend(QObject, Backend):
Logger.logException("w", "Failed to create snapshot image") Logger.logException("w", "Failed to create snapshot image")
self._snapshot = None # Failing to create thumbnail should not fail creation of UFP self._snapshot = None # Failing to create thumbnail should not fail creation of UFP
def getLatestSnapShot(self) -> Optional[QImage]: def getLatestSnapshot(self) -> Optional[QImage]:
return self._snapshot return self._snapshot
def slice(self) -> None: def slice(self) -> None:

View file

@ -62,12 +62,9 @@ class UFPWriter(MeshWriter):
gcode.write(gcode_textio.getvalue().encode("UTF-8")) gcode.write(gcode_textio.getvalue().encode("UTF-8"))
archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode") archive.addRelation(virtual_path = "/3D/model.gcode", relation_type = "http://schemas.ultimaker.org/package/2018/relationships/gcode")
snapshot = None # Attempt to store the thumbnail, if any:
backend = CuraApplication.getInstance().getBackend() backend = CuraApplication.getInstance().getBackend()
if isinstance(backend, CuraEngineBackend): snapshot = None if getattr(backend, "getLatestSnapshot", None) is None else backend.getLatestSnapshot()
snapshot = backend.getLatestSnapshot()
# Store the thumbnail.
if snapshot: if snapshot:
archive.addContentType(extension = "png", mime_type = "image/png") archive.addContentType(extension = "png", mime_type = "image/png")
thumbnail = archive.getStream("/Metadata/thumbnail.png") thumbnail = archive.getStream("/Metadata/thumbnail.png")