PrintJobPreviewImageProvider.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. def requestImage(self, id: str, size: QSize) -> Tuple[QImage, QSize]:
  10. """Request a new image.
  11. :param id: id of the requested image
  12. :param size: is not used defaults to QSize(15, 15)
  13. :return: an tuple containing the image and size
  14. """
  15. # The id will have an uuid and an increment separated by a slash. As we don't care about the value of the
  16. # increment, we need to strip that first.
  17. uuid = id[id.find("/") + 1:]
  18. for output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
  19. if not hasattr(output_device, "printJobs"):
  20. continue
  21. for print_job in output_device.printJobs:
  22. if print_job.key == uuid:
  23. if print_job.getPreviewImage():
  24. return print_job.getPreviewImage(), QSize(15, 15)
  25. return QImage(), QSize(15, 15)
  26. return QImage(), QSize(15, 15)