CameraImageProvider.py 921 B

1234567891011121314151617181920212223242526272829
  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 CameraImageProvider(QQuickImageProvider):
  6. def __init__(self):
  7. super().__init__(QQuickImageProvider.Image)
  8. ## Request a new image.
  9. def requestImage(self, id, size):
  10. for output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
  11. try:
  12. image = output_device.activePrinter.camera.getImage()
  13. if image.isNull():
  14. image = QImage()
  15. return image, QSize(15, 15)
  16. except AttributeError:
  17. try:
  18. image = output_device.activeCamera.getImage()
  19. return image, QSize(15, 15)
  20. except AttributeError:
  21. pass
  22. return QImage(), QSize(15, 15)