From 3a46bb8d8a1a7987c22ffae372bb16547eb1385b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 16 Jun 2016 09:34:43 +0200 Subject: [PATCH] Added CameraImageProvider & camera handling CURA-1036 and CURA-338 --- cura/CameraImageProvider.py | 18 ++++++++++++++++++ cura/CuraApplication.py | 6 +++++- resources/qml/Sidebar.qml | 2 -- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 cura/CameraImageProvider.py diff --git a/cura/CameraImageProvider.py b/cura/CameraImageProvider.py new file mode 100644 index 0000000000..ff66170f3c --- /dev/null +++ b/cura/CameraImageProvider.py @@ -0,0 +1,18 @@ +from PyQt5.QtGui import QImage +from PyQt5.QtQuick import QQuickImageProvider +from PyQt5.QtCore import QSize + +from UM.Application import Application + +class CameraImageProvider(QQuickImageProvider): + def __init__(self): + QQuickImageProvider.__init__(self, QQuickImageProvider.Image) + + ## Request a new image. + def requestImage(self, id, size): + for output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices(): + try: + return output_device.getCameraImage(), QSize(15, 15) + except AttributeError: + pass + return QImage(), QSize(15, 15) \ No newline at end of file diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 393f1e5634..2f1408a16d 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -43,6 +43,7 @@ from . import ZOffsetDecorator from . import CuraSplashScreen from . import MachineManagerModel from . import ContainerSettingsModel +from . import CameraImageProvider from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS from PyQt5.QtGui import QColor, QIcon @@ -222,7 +223,7 @@ class CuraApplication(QtApplication): JobQueue.getInstance().jobFinished.connect(self._onJobFinished) self.applicationShuttingDown.connect(self.saveSettings) - + self.engineCreatedSignal.connect(self._onEngineCreated) self._recent_files = [] files = Preferences.getInstance().getValue("cura/recent_files").split(";") for f in files: @@ -231,6 +232,9 @@ class CuraApplication(QtApplication): self._recent_files.append(QUrl.fromLocalFile(f)) + def _onEngineCreated(self): + self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) + ## Cura has multiple locations where instance containers need to be saved, so we need to handle this differently. # # Note that the AutoSave plugin also calls this method. diff --git a/resources/qml/Sidebar.qml b/resources/qml/Sidebar.qml index 04eacad044..74022bbe3b 100644 --- a/resources/qml/Sidebar.qml +++ b/resources/qml/Sidebar.qml @@ -281,8 +281,6 @@ Rectangle text: " " + Cura.MachineManager.printerOutputDevices[0].bedTemperature } - - // Spacers Label { text: " "} Label { text: " "}