PrintJobPreviewImageProvider.py 1.1 KB

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