Replace NetworkCamera with NetworkMJPGImage

This commit is contained in:
fieldOfView 2018-10-25 21:58:21 +02:00
parent 890ddc015e
commit c187b6a25c
5 changed files with 30 additions and 47 deletions

View file

@ -10,43 +10,36 @@ Component {
height: maximumHeight;
width: maximumWidth;
Cura.CameraView {
Cura.NetworkMJPGImage {
id: cameraImage;
anchors {
horizontalCenter: parent.horizontalCenter;
verticalCenter: parent.verticalCenter;
}
Component.onCompleted: {
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
OutputDevice.activePrinter.camera.start();
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
cameraImage.start();
}
}
height: Math.floor((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
onVisibleChanged: {
if (visible) {
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
OutputDevice.activePrinter.camera.start();
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
cameraImage.start();
}
} else {
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.camera != null) {
OutputDevice.activePrinter.camera.stop();
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
cameraImage.stop();
}
}
}
source: {
if (OutputDevice.activePrinter != null && OutputDevice.activePrinter.cameraUrl != null) {
return OutputDevice.activePrinter.cameraUrl;
}
}
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
z: 1;
Connections
{
target: OutputDevice.activePrinter.camera;
onNewImage:
{
if (cameraImage.visible) {
cameraImage.image = OutputDevice.activePrinter.camera.latestImage;
cameraImage.update();
}
}
}
}
}
}

View file

@ -34,33 +34,23 @@ Item {
z: 999;
}
Cura.CameraView {
Cura.NetworkMJPGImage {
id: cameraImage
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
onVisibleChanged: {
if (visible) {
if (camera != null) {
camera.start();
if (cameraUrl != null) {
start();
}
} else {
if (camera != null) {
camera.stop();
}
}
}
Connections
{
target: camera
onNewImage: {
if (cameraImage.visible) {
cameraImage.image = camera.latestImage;
cameraImage.update();
if (cameraUrl != null) {
stop();
}
}
}
source: cameraUrl
width: Math.min(imageWidth === 0 ? 800 * screenScaleFactor : imageWidth, maximumWidth);
z: 1
}

View file

@ -548,7 +548,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
def _createPrinterModel(self, data: Dict[str, Any]) -> PrinterOutputModel:
printer = PrinterOutputModel(output_controller = ClusterUM3PrinterOutputController(self),
number_of_extruders = self._number_of_extruders)
printer.setCamera(NetworkCamera("http://" + data["ip_address"] + ":8080/?action=stream"))
printer.setCameraUrl(QUrl("http://" + data["ip_address"] + ":8080/?action=stream"))
self._printers.append(printer)
return printer

View file

@ -18,7 +18,7 @@ from UM.i18n import i18nCatalog
from UM.Message import Message
from PyQt5.QtNetwork import QNetworkRequest
from PyQt5.QtCore import QTimer
from PyQt5.QtCore import QTimer, QUrl
from PyQt5.QtWidgets import QMessageBox
from .LegacyUM3PrinterOutputController import LegacyUM3PrinterOutputController
@ -568,7 +568,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
# Quickest way to get the firmware version is to grab it from the zeroconf.
firmware_version = self._properties.get(b"firmware_version", b"").decode("utf-8")
self._printers = [PrinterOutputModel(output_controller=self._output_controller, number_of_extruders=self._number_of_extruders, firmware_version=firmware_version)]
self._printers[0].setCamera(NetworkCamera("http://" + self._address + ":8080/?action=stream"))
self._printers[0].setCameraUrl(QUrl("http://" + self._address + ":8080/?action=stream"))
for extruder in self._printers[0].extruders:
extruder.activeMaterialChanged.connect(self.materialIdChanged)
extruder.hotendIDChanged.connect(self.hotendIdChanged)