mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
First steps to ensure that the Discover UM3 action works with new architecture
CL-541
This commit is contained in:
parent
1b8caa7a21
commit
4197f18fc1
4 changed files with 65 additions and 27 deletions
|
@ -2,13 +2,14 @@ from UM.Application import Application
|
||||||
from cura.PrinterOutputDevice import PrinterOutputDevice
|
from cura.PrinterOutputDevice import PrinterOutputDevice
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply
|
from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer, pyqtSignal, QUrl
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
|
||||||
class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def __init__(self, device_id, address: str, parent = None):
|
def __init__(self, device_id, address: str, properties, parent = None):
|
||||||
super().__init__(device_id = device_id, parent = parent)
|
super().__init__(device_id = device_id, parent = parent)
|
||||||
self._manager = None
|
self._manager = None
|
||||||
self._createNetworkManager()
|
self._createNetworkManager()
|
||||||
|
@ -16,7 +17,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
||||||
self._last_request_time = None
|
self._last_request_time = None
|
||||||
self._api_prefix = ""
|
self._api_prefix = ""
|
||||||
self._address = address
|
self._address = address
|
||||||
|
self._properties = properties
|
||||||
self._user_agent = "%s/%s " % (Application.getInstance().getApplicationName(), Application.getInstance().getVersion())
|
self._user_agent = "%s/%s " % (Application.getInstance().getApplicationName(), Application.getInstance().getVersion())
|
||||||
|
|
||||||
self._onFinishedCallbacks = {}
|
self._onFinishedCallbacks = {}
|
||||||
|
@ -69,3 +70,37 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Something went wrong with callback", e)
|
print("Something went wrong with callback", e)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@pyqtSlot(str, result=str)
|
||||||
|
def getProperty(self, key):
|
||||||
|
key = key.encode("utf-8")
|
||||||
|
if key in self._properties:
|
||||||
|
return self._properties.get(key, b"").decode("utf-8")
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
## Get the unique key of this machine
|
||||||
|
# \return key String containing the key of the machine.
|
||||||
|
@pyqtProperty(str, constant=True)
|
||||||
|
def key(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
## The IP address of the printer.
|
||||||
|
@pyqtProperty(str, constant=True)
|
||||||
|
def address(self):
|
||||||
|
return self._properties.get(b"address", b"").decode("utf-8")
|
||||||
|
|
||||||
|
## Name of the printer (as returned from the ZeroConf properties)
|
||||||
|
@pyqtProperty(str, constant=True)
|
||||||
|
def name(self):
|
||||||
|
return self._properties.get(b"name", b"").decode("utf-8")
|
||||||
|
|
||||||
|
## Firmware version (as returned from the ZeroConf properties)
|
||||||
|
@pyqtProperty(str, constant=True)
|
||||||
|
def firmwareVersion(self):
|
||||||
|
return self._properties.get(b"firmware_version", b"").decode("utf-8")
|
||||||
|
|
||||||
|
## IPadress of this printer
|
||||||
|
@pyqtProperty(str, constant=True)
|
||||||
|
def ipAddress(self):
|
||||||
|
return self._address
|
|
@ -1,8 +1,11 @@
|
||||||
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
||||||
|
|
||||||
|
|
||||||
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
def __init__(self, device_id, address, properties, parent = None):
|
def __init__(self, device_id, address, properties, parent = None):
|
||||||
super().__init__(device_id = device_id, address = address, parent = parent)
|
super().__init__(device_id = device_id, address = address, properties=properties, parent = parent)
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
|
super()._update()
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -10,7 +10,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: base
|
id: base
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
property var selectedPrinter: null
|
property var selectedDevice: null
|
||||||
property bool completeProperties: true
|
property bool completeProperties: true
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
|
@ -31,7 +31,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
if(base.selectedPrinter && base.completeProperties)
|
if(base.selectedPrinter && base.completeProperties)
|
||||||
{
|
{
|
||||||
var printerKey = base.selectedPrinter.getKey()
|
var printerKey = base.selectedDevice.key
|
||||||
if(manager.getStoredKey() != printerKey)
|
if(manager.getStoredKey() != printerKey)
|
||||||
{
|
{
|
||||||
manager.setKey(printerKey);
|
manager.setKey(printerKey);
|
||||||
|
@ -83,10 +83,10 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: editButton
|
id: editButton
|
||||||
text: catalog.i18nc("@action:button", "Edit")
|
text: catalog.i18nc("@action:button", "Edit")
|
||||||
enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
|
enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
|
manualPrinterDialog.showDialog(base.selectedDevice.key, base.selectedDevice.ipAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: removeButton
|
id: removeButton
|
||||||
text: catalog.i18nc("@action:button", "Remove")
|
text: catalog.i18nc("@action:button", "Remove")
|
||||||
enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
|
enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
|
||||||
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
|
onClicked: manager.removeManualPrinter(base.selectedDevice.key, base.selectedDevice.ipAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
Button
|
Button
|
||||||
|
@ -139,7 +139,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
var selectedKey = manager.getStoredKey();
|
var selectedKey = manager.getStoredKey();
|
||||||
for(var i = 0; i < model.length; i++) {
|
for(var i = 0; i < model.length; i++) {
|
||||||
if(model[i].getKey() == selectedKey)
|
if(model[i].key == selectedKey)
|
||||||
{
|
{
|
||||||
currentIndex = i;
|
currentIndex = i;
|
||||||
return
|
return
|
||||||
|
@ -151,9 +151,9 @@ Cura.MachineAction
|
||||||
currentIndex: -1
|
currentIndex: -1
|
||||||
onCurrentIndexChanged:
|
onCurrentIndexChanged:
|
||||||
{
|
{
|
||||||
base.selectedPrinter = listview.model[currentIndex];
|
base.selectedDevice = listview.model[currentIndex];
|
||||||
// Only allow connecting if the printer has responded to API query since the last refresh
|
// Only allow connecting if the printer has responded to API query since the last refresh
|
||||||
base.completeProperties = base.selectedPrinter != null && base.selectedPrinter.getProperty("incomplete") != "true";
|
base.completeProperties = base.selectedDevice != null && base.selectedDevice.getProperty("incomplete") != "true";
|
||||||
}
|
}
|
||||||
Component.onCompleted: manager.startDiscovery()
|
Component.onCompleted: manager.startDiscovery()
|
||||||
delegate: Rectangle
|
delegate: Rectangle
|
||||||
|
@ -199,13 +199,13 @@ Cura.MachineAction
|
||||||
Column
|
Column
|
||||||
{
|
{
|
||||||
width: Math.floor(parent.width * 0.5)
|
width: Math.floor(parent.width * 0.5)
|
||||||
visible: base.selectedPrinter ? true : false
|
visible: base.selectedDevice ? true : false
|
||||||
spacing: UM.Theme.getSize("default_margin").height
|
spacing: UM.Theme.getSize("default_margin").height
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
width: parent.width
|
width: parent.width
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text: base.selectedPrinter ? base.selectedPrinter.name : ""
|
text: base.selectedDevice ? base.selectedDevice.name : ""
|
||||||
font: UM.Theme.getFont("large")
|
font: UM.Theme.getFont("large")
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
|
@ -226,12 +226,12 @@ Cura.MachineAction
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text:
|
text:
|
||||||
{
|
{
|
||||||
if(base.selectedPrinter)
|
if(base.selectedDevice)
|
||||||
{
|
{
|
||||||
if(base.selectedPrinter.printerType == "ultimaker3")
|
if(base.selectedDevice.printerType == "ultimaker3")
|
||||||
{
|
{
|
||||||
return catalog.i18nc("@label", "Ultimaker 3")
|
return catalog.i18nc("@label", "Ultimaker 3")
|
||||||
} else if(base.selectedPrinter.printerType == "ultimaker3_extended")
|
} else if(base.selectedDevice.printerType == "ultimaker3_extended")
|
||||||
{
|
{
|
||||||
return catalog.i18nc("@label", "Ultimaker 3 Extended")
|
return catalog.i18nc("@label", "Ultimaker 3 Extended")
|
||||||
} else
|
} else
|
||||||
|
@ -255,7 +255,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
width: Math.floor(parent.width * 0.5)
|
width: Math.floor(parent.width * 0.5)
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text: base.selectedPrinter ? base.selectedPrinter.firmwareVersion : ""
|
text: base.selectedDevice ? base.selectedDevice.firmwareVersion : ""
|
||||||
}
|
}
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
|
@ -267,7 +267,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
width: Math.floor(parent.width * 0.5)
|
width: Math.floor(parent.width * 0.5)
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text: base.selectedPrinter ? base.selectedPrinter.ipAddress : ""
|
text: base.selectedDevice ? base.selectedDevice.ipAddress : ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,17 +277,17 @@ Cura.MachineAction
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text:{
|
text:{
|
||||||
// The property cluster size does not exist for older UM3 devices.
|
// The property cluster size does not exist for older UM3 devices.
|
||||||
if(!base.selectedPrinter || base.selectedPrinter.clusterSize == null || base.selectedPrinter.clusterSize == 1)
|
if(!base.selectedDevice || base.selectedDevice.clusterSize == null || base.selectedDevice.clusterSize == 1)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
else if (base.selectedPrinter.clusterSize === 0)
|
else if (base.selectedDevice.clusterSize === 0)
|
||||||
{
|
{
|
||||||
return catalog.i18nc("@label", "This printer is not set up to host a group of Ultimaker 3 printers.");
|
return catalog.i18nc("@label", "This printer is not set up to host a group of Ultimaker 3 printers.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return catalog.i18nc("@label", "This printer is the host for a group of %1 Ultimaker 3 printers.".arg(base.selectedPrinter.clusterSize));
|
return catalog.i18nc("@label", "This printer is the host for a group of %1 Ultimaker 3 printers.".arg(base.selectedDevice.clusterSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,14 +296,14 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
width: parent.width
|
width: parent.width
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
visible: base.selectedPrinter != null && !base.completeProperties
|
visible: base.selectedDevice != null && !base.completeProperties
|
||||||
text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
|
text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
|
||||||
}
|
}
|
||||||
|
|
||||||
Button
|
Button
|
||||||
{
|
{
|
||||||
text: catalog.i18nc("@action:button", "Connect")
|
text: catalog.i18nc("@action:button", "Connect")
|
||||||
enabled: (base.selectedPrinter && base.completeProperties) ? true : false
|
enabled: (base.selectedDevice && base.completeProperties) ? true : false
|
||||||
onClicked: connectToPrinter()
|
onClicked: connectToPrinter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutp
|
||||||
|
|
||||||
class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
|
class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
def __init__(self, device_id, address: str, properties, parent = None):
|
def __init__(self, device_id, address: str, properties, parent = None):
|
||||||
super().__init__(device_id = device_id, address = address, parent = parent)
|
super().__init__(device_id = device_id, address = address, properties = properties, parent = parent)
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue