Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change camera URL to non-optional QUrl #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cura/PrinterOutput/PrinterOutputModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ def __init__(self, output_controller: "PrinterOutputController", number_of_extru
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
self._extruders]

self._camera_url = None # type: Optional[QUrl]
self._camera_url = QUrl() # type: QUrl

@pyqtProperty(str, constant = True)
def firmwareVersion(self) -> str:
return self._firmware_version

def setCameraUrl(self, camera_url: Optional["QUrl"]) -> None:
if self._camera_url is not camera_url:
def setCameraUrl(self, camera_url: "QUrl") -> None:
if self._camera_url != camera_url:
self._camera_url = camera_url
self.cameraUrlChanged.emit()

@pyqtProperty(QUrl, fset = setCameraUrl, notify = cameraUrlChanged)
def cameraUrl(self) -> "QUrl":
return self._camera_url

def updateIsPreheating(self, pre_heating: bool) -> None:
if self._is_preheating != pre_heating:
self._is_preheating = pre_heating
Expand All @@ -69,10 +73,6 @@ def updateIsPreheating(self, pre_heating: bool) -> None:
def isPreheating(self) -> bool:
return self._is_preheating

@pyqtProperty(QUrl, notify=cameraUrlChanged)
def cameraUrl(self) -> Optional["QUrl"]:
return self._camera_url

@pyqtProperty(str, notify = printerTypeChanged)
def type(self) -> str:
return self._printer_type
Expand Down
4 changes: 2 additions & 2 deletions plugins/UM3NetworkPrinting/resources/qml/CameraButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Rectangle {
anchors.fill: parent;
hoverEnabled: true;
onClicked: {
if (OutputDevice.activeCameraUrl !== null) {
OutputDevice.setActiveCameraUrl(null)
if (OutputDevice.activeCameraUrl != "") {
OutputDevice.setActiveCameraUrl("");
} else {
OutputDevice.setActiveCameraUrl(modelData.cameraUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Component {
height: maximumHeight;
onVisibleChanged: {
if (monitorFrame != null && !monitorFrame.visible) {
OutputDevice.setActiveCameraUrl(null);
OutputDevice.setActiveCameraUrl("");
}
}
width: maximumWidth;
Expand Down Expand Up @@ -126,7 +126,7 @@ Component {
PrinterVideoStream {
anchors.fill: parent;
cameraUrl: OutputDevice.activeCameraUrl;
visible: OutputDevice.activeCameraUrl != null;
visible: OutputDevice.activeCameraUrl != "";
}
}
}
10 changes: 5 additions & 5 deletions plugins/UM3NetworkPrinting/resources/qml/PrinterVideoStream.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UM 1.3 as UM
import Cura 1.0 as Cura

Item {
property var cameraUrl: null;
property var cameraUrl: "";

Rectangle {
anchors.fill:parent;
Expand All @@ -18,7 +18,7 @@ Item {

MouseArea {
anchors.fill: parent;
onClicked: OutputDevice.setActiveCameraUrl(null);
onClicked: OutputDevice.setActiveCameraUrl("");
z: 0;
}

Expand All @@ -41,11 +41,11 @@ Item {
height: Math.round((imageHeight === 0 ? 600 * screenScaleFactor : imageHeight) * width / imageWidth);
onVisibleChanged: {
if (visible) {
if (cameraUrl != null) {
if (cameraUrl != "") {
start();
}
} else {
if (cameraUrl != null) {
if (cameraUrl != "") {
stop();
}
}
Expand All @@ -58,7 +58,7 @@ Item {
MouseArea {
anchors.fill: cameraImage;
onClicked: {
OutputDevice.setActiveCameraUrl(null);
OutputDevice.setActiveCameraUrl("");
}
z: 1;
}
Expand Down
21 changes: 7 additions & 14 deletions plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, device_id, address, properties, parent = None) -> None:
self._latest_reply_handler = None # type: Optional[QNetworkReply]
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:
self.writeStarted.emit(self)
Expand Down Expand Up @@ -263,27 +263,20 @@ def _sendPrintJobWaitOnWriteJobFinished(self, job: WriteFileJob) -> None:
def activePrinter(self) -> Optional[PrinterOutputModel]:
return self._active_printer

@pyqtProperty(QUrl, notify=activeCameraUrlChanged)
def activeCameraUrl(self) -> Optional[QUrl]:
return self._active_camera_url

@pyqtSlot(QObject)
def setActivePrinter(self, printer: Optional[PrinterOutputModel]) -> None:
if self._active_printer != printer:
self._active_printer = printer
self.activePrinterChanged.emit()

@pyqtSlot(QObject)
def setActiveCameraUrl(self, camera_url: Optional[QUrl]) -> None:
if self._active_camera_url != camera_url:
if self._active_camera_url:
self._active_camera_url.stop()
@pyqtProperty(QUrl, notify = activeCameraUrlChanged)
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:
self._active_camera_url = camera_url

if self._active_camera_url:
self._active_camera_url.start()

self.activeCameraUrlChanged.emit()

def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None:
Expand Down