PrintJobPreviewImageProvider.py 1.1 KB

123456789101112131415161718192021222324252627
  1. from PyQt5.QtGui import QImage
  2. from PyQt5.QtQuick import QQuickImageProvider
  3. from PyQt5.QtCore import QSize
  4. from UM.Application import Application
  5. class PrintJobPreviewImageProvider(QQuickImageProvider):
  6. def __init__(self):
  7. super().__init__(QQuickImageProvider.Image)
  8. ## Request a new image.
  9. def requestImage(self, id: str, size: QSize) -> QImage:
  10. # The id will have an uuid and an increment separated by a slash. As we don't care about the value of the
  11. # increment, we need to strip that first.
  12. uuid = id[id.find("/") + 1:]
  13. for output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
  14. if not hasattr(output_device, "printJobs"):
  15. continue
  16. for print_job in output_device.printJobs:
  17. if print_job.key == uuid:
  18. if print_job.getPreviewImage():
  19. return print_job.getPreviewImage(), QSize(15, 15)
  20. else:
  21. return QImage(), QSize(15, 15)
  22. return QImage(), QSize(15,15)