Change camera URL to non-optional QUrl

Otherwise pyqt property will complain when it tries to convert a None to
a QUrl.
This commit is contained in:
Lipu Fei 2018-10-29 13:23:10 +01:00
parent 0c1b3931db
commit 02681a5700
5 changed files with 23 additions and 30 deletions

View file

@ -49,17 +49,21 @@ class PrinterOutputModel(QObject):
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
self._extruders] self._extruders]
self._camera_url = None # type: Optional[QUrl] self._camera_url = QUrl() # type: QUrl
@pyqtProperty(str, constant = True) @pyqtProperty(str, constant = True)
def firmwareVersion(self) -> str: def firmwareVersion(self) -> str:
return self._firmware_version return self._firmware_version
def setCameraUrl(self, camera_url: Optional["QUrl"]) -> None: def setCameraUrl(self, camera_url: "QUrl") -> None:
if self._camera_url is not camera_url: if self._camera_url != camera_url:
self._camera_url = camera_url self._camera_url = camera_url
self.cameraUrlChanged.emit() self.cameraUrlChanged.emit()
@pyqtProperty(QUrl, fset = setCameraUrl, notify = cameraUrlChanged)
def cameraUrl(self) -> "QUrl":
return self._camera_url
def updateIsPreheating(self, pre_heating: bool) -> None: def updateIsPreheating(self, pre_heating: bool) -> None:
if self._is_preheating != pre_heating: if self._is_preheating != pre_heating:
self._is_preheating = pre_heating self._is_preheating = pre_heating
@ -69,10 +73,6 @@ class PrinterOutputModel(QObject):
def isPreheating(self) -> bool: def isPreheating(self) -> bool:
return self._is_preheating return self._is_preheating
@pyqtProperty(QUrl, notify=cameraUrlChanged)
def cameraUrl(self) -> Optional["QUrl"]:
return self._camera_url
@pyqtProperty(str, notify = printerTypeChanged) @pyqtProperty(str, notify = printerTypeChanged)
def type(self) -> str: def type(self) -> str:
return self._printer_type return self._printer_type

View file

@ -31,8 +31,8 @@ Rectangle {
anchors.fill: parent; anchors.fill: parent;
hoverEnabled: true; hoverEnabled: true;
onClicked: { onClicked: {
if (OutputDevice.activeCameraUrl !== null) { if (OutputDevice.activeCameraUrl != "") {
OutputDevice.setActiveCameraUrl(null) OutputDevice.setActiveCameraUrl("");
} else { } else {
OutputDevice.setActiveCameraUrl(modelData.cameraUrl); OutputDevice.setActiveCameraUrl(modelData.cameraUrl);
} }

View file

@ -16,7 +16,7 @@ Component {
height: maximumHeight; height: maximumHeight;
onVisibleChanged: { onVisibleChanged: {
if (monitorFrame != null && !monitorFrame.visible) { if (monitorFrame != null && !monitorFrame.visible) {
OutputDevice.setActiveCameraUrl(null); OutputDevice.setActiveCameraUrl("");
} }
} }
width: maximumWidth; width: maximumWidth;
@ -126,7 +126,7 @@ Component {
PrinterVideoStream { PrinterVideoStream {
anchors.fill: parent; anchors.fill: parent;
cameraUrl: OutputDevice.activeCameraUrl; cameraUrl: OutputDevice.activeCameraUrl;
visible: OutputDevice.activeCameraUrl != null; visible: OutputDevice.activeCameraUrl != "";
} }
} }
} }

View file

@ -8,7 +8,7 @@ import UM 1.3 as UM
import Cura 1.0 as Cura import Cura 1.0 as Cura
Item { Item {
property var cameraUrl: null; property var cameraUrl: "";
Rectangle { Rectangle {
anchors.fill:parent; anchors.fill:parent;
@ -18,7 +18,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent; anchors.fill: parent;
onClicked: OutputDevice.setActiveCameraUrl(null); onClicked: OutputDevice.setActiveCameraUrl("");
z: 0; z: 0;
} }
@ -41,11 +41,11 @@ Item {
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth); height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
onVisibleChanged: { onVisibleChanged: {
if (visible) { if (visible) {
if (cameraUrl != null) { if (cameraUrl != "") {
start(); start();
} }
} else { } else {
if (cameraUrl != null) { if (cameraUrl != "") {
stop(); stop();
} }
} }
@ -58,7 +58,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: cameraImage; anchors.fill: cameraImage;
onClicked: { onClicked: {
OutputDevice.setActiveCameraUrl(null); OutputDevice.setActiveCameraUrl("");
} }
z: 1; z: 1;
} }

View file

@ -99,7 +99,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._latest_reply_handler = None # type: Optional[QNetworkReply] self._latest_reply_handler = None # type: Optional[QNetworkReply]
self._sending_job = None self._sending_job = None
self._active_camera_url = None # type: Optional[QUrl] self._active_camera_url = QUrl() # type: QUrl
def requestWrite(self, nodes: List[SceneNode], file_name: Optional[str] = None, limit_mimetypes: bool = False, file_handler: Optional[FileHandler] = None, **kwargs: str) -> None: def requestWrite(self, nodes: List[SceneNode], file_name: Optional[str] = None, limit_mimetypes: bool = False, file_handler: Optional[FileHandler] = None, **kwargs: str) -> None:
self.writeStarted.emit(self) self.writeStarted.emit(self)
@ -263,27 +263,20 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
def activePrinter(self) -> Optional[PrinterOutputModel]: def activePrinter(self) -> Optional[PrinterOutputModel]:
return self._active_printer return self._active_printer
@pyqtProperty(QUrl, notify=activeCameraUrlChanged)
def activeCameraUrl(self) -> Optional[QUrl]:
return self._active_camera_url
@pyqtSlot(QObject) @pyqtSlot(QObject)
def setActivePrinter(self, printer: Optional[PrinterOutputModel]) -> None: def setActivePrinter(self, printer: Optional[PrinterOutputModel]) -> None:
if self._active_printer != printer: if self._active_printer != printer:
self._active_printer = printer self._active_printer = printer
self.activePrinterChanged.emit() self.activePrinterChanged.emit()
@pyqtSlot(QObject) @pyqtProperty(QUrl, notify = activeCameraUrlChanged)
def setActiveCameraUrl(self, camera_url: Optional[QUrl]) -> None: def activeCameraUrl(self) -> "QUrl":
return self._active_camera_url
@pyqtSlot(QUrl)
def setActiveCameraUrl(self, camera_url: "QUrl") -> None:
if self._active_camera_url != camera_url: if self._active_camera_url != camera_url:
if self._active_camera_url:
self._active_camera_url.stop()
self._active_camera_url = camera_url self._active_camera_url = camera_url
if self._active_camera_url:
self._active_camera_url.start()
self.activeCameraUrlChanged.emit() self.activeCameraUrlChanged.emit()
def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None: def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None: