First steps to ensure that the Discover UM3 action works with new architecture

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-20 13:35:08 +01:00
parent 1b8caa7a21
commit 4197f18fc1
4 changed files with 65 additions and 27 deletions

View file

@ -2,13 +2,14 @@ from UM.Application import Application
from cura.PrinterOutputDevice import PrinterOutputDevice
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 typing import Callable
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)
self._manager = None
self._createNetworkManager()
@ -16,7 +17,7 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
self._last_request_time = None
self._api_prefix = ""
self._address = address
self._properties = properties
self._user_agent = "%s/%s " % (Application.getInstance().getApplicationName(), Application.getInstance().getVersion())
self._onFinishedCallbacks = {}
@ -69,3 +70,37 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
except Exception as e:
print("Something went wrong with callback", e)
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

View file

@ -1,8 +1,11 @@
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
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):
super()._update()
pass

View file

@ -10,7 +10,7 @@ Cura.MachineAction
{
id: base
anchors.fill: parent;
property var selectedPrinter: null
property var selectedDevice: null
property bool completeProperties: true
Connections
@ -31,7 +31,7 @@ Cura.MachineAction
{
if(base.selectedPrinter && base.completeProperties)
{
var printerKey = base.selectedPrinter.getKey()
var printerKey = base.selectedDevice.key
if(manager.getStoredKey() != printerKey)
{
manager.setKey(printerKey);
@ -83,10 +83,10 @@ Cura.MachineAction
{
id: editButton
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:
{
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
manualPrinterDialog.showDialog(base.selectedDevice.key, base.selectedDevice.ipAddress);
}
}
@ -94,8 +94,8 @@ Cura.MachineAction
{
id: removeButton
text: catalog.i18nc("@action:button", "Remove")
enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true"
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
onClicked: manager.removeManualPrinter(base.selectedDevice.key, base.selectedDevice.ipAddress)
}
Button
@ -139,7 +139,7 @@ Cura.MachineAction
{
var selectedKey = manager.getStoredKey();
for(var i = 0; i < model.length; i++) {
if(model[i].getKey() == selectedKey)
if(model[i].key == selectedKey)
{
currentIndex = i;
return
@ -151,9 +151,9 @@ Cura.MachineAction
currentIndex: -1
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
base.completeProperties = base.selectedPrinter != null && base.selectedPrinter.getProperty("incomplete") != "true";
base.completeProperties = base.selectedDevice != null && base.selectedDevice.getProperty("incomplete") != "true";
}
Component.onCompleted: manager.startDiscovery()
delegate: Rectangle
@ -199,13 +199,13 @@ Cura.MachineAction
Column
{
width: Math.floor(parent.width * 0.5)
visible: base.selectedPrinter ? true : false
visible: base.selectedDevice ? true : false
spacing: UM.Theme.getSize("default_margin").height
Label
{
width: parent.width
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.name : ""
text: base.selectedDevice ? base.selectedDevice.name : ""
font: UM.Theme.getFont("large")
elide: Text.ElideRight
}
@ -226,12 +226,12 @@ Cura.MachineAction
wrapMode: Text.WordWrap
text:
{
if(base.selectedPrinter)
if(base.selectedDevice)
{
if(base.selectedPrinter.printerType == "ultimaker3")
if(base.selectedDevice.printerType == "ultimaker3")
{
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")
} else
@ -255,7 +255,7 @@ Cura.MachineAction
{
width: Math.floor(parent.width * 0.5)
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.firmwareVersion : ""
text: base.selectedDevice ? base.selectedDevice.firmwareVersion : ""
}
Label
{
@ -267,7 +267,7 @@ Cura.MachineAction
{
width: Math.floor(parent.width * 0.5)
wrapMode: Text.WordWrap
text: base.selectedPrinter ? base.selectedPrinter.ipAddress : ""
text: base.selectedDevice ? base.selectedDevice.ipAddress : ""
}
}
@ -277,17 +277,17 @@ Cura.MachineAction
wrapMode: Text.WordWrap
text:{
// 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 "";
}
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.");
}
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
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." )
}
Button
{
text: catalog.i18nc("@action:button", "Connect")
enabled: (base.selectedPrinter && base.completeProperties) ? true : false
enabled: (base.selectedDevice && base.completeProperties) ? true : false
onClicked: connectToPrinter()
}
}

View file

@ -2,7 +2,7 @@ from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutp
class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
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):
pass