Merge pull request #6057 from Ultimaker/network-plugin-remove-hardcoded-references

Get rid of any hard-coded references to machines
This commit is contained in:
ChrisTerBeke 2019-07-25 16:02:29 +02:00 committed by GitHub
commit 87517a77c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 58 deletions

View File

@ -250,29 +250,13 @@ Cura.MachineAction
renderType: Text.NativeRendering renderType: Text.NativeRendering
text: text:
{ {
if(base.selectedDevice) if (base.selectedDevice) {
{ // It would be great to use a more readable machine type here,
if (base.selectedDevice.printerType == "ultimaker3") // but the new discoveredPrintersModel is not used yet in the UM networking actions.
{ // TODO: remove actions or replace 'connect via network' button with new flow?
return "Ultimaker 3"; return base.selectedDevice.printerType
}
else if (base.selectedDevice.printerType == "ultimaker3_extended")
{
return "Ultimaker 3 Extended";
}
else if (base.selectedDevice.printerType == "ultimaker_s5")
{
return "Ultimaker S5";
}
else
{
return catalog.i18nc("@label", "Unknown") // We have no idea what type it is. Should not happen 'in the field'
}
}
else
{
return ""
} }
return ""
} }
} }
Label Label

View File

@ -11,20 +11,8 @@ import UM 1.2 as UM
*/ */
Item Item
{ {
// The printer name id: monitorPrinterPill
property var text: "" property var text: ""
property var tagText: {
switch(text) {
case "Ultimaker 3":
return "UM 3"
case "Ultimaker 3 Extended":
return "UM 3 EXT"
case "Ultimaker S5":
return "UM S5"
default:
return text
}
}
implicitHeight: 18 * screenScaleFactor // TODO: Theme! implicitHeight: 18 * screenScaleFactor // TODO: Theme!
implicitWidth: Math.max(printerNameLabel.contentWidth + 12 * screenScaleFactor, 36 * screenScaleFactor) // TODO: Theme! implicitWidth: Math.max(printerNameLabel.contentWidth + 12 * screenScaleFactor, 36 * screenScaleFactor) // TODO: Theme!
@ -40,9 +28,9 @@ Item
id: printerNameLabel id: printerNameLabel
anchors.centerIn: parent anchors.centerIn: parent
color: UM.Theme.getColor("monitor_text_primary") color: UM.Theme.getColor("monitor_text_primary")
text: tagText text: monitorPrinterPill.text
font.pointSize: 10 // TODO: Theme! font.pointSize: 10 // TODO: Theme!
visible: text !== "" visible: monitorPrinterPill.text !== ""
renderType: Text.NativeRendering renderType: Text.NativeRendering
} }
} }

View File

@ -5,7 +5,7 @@ import os
from queue import Queue from queue import Queue
from threading import Event, Thread from threading import Event, Thread
from time import time from time import time
from typing import Optional, TYPE_CHECKING, Dict, Callable from typing import Optional, TYPE_CHECKING, Dict, Callable, Union, Any
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
@ -395,17 +395,28 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._application.getDiscoveredPrintersModel().removeDiscoveredPrinter(device.address) self._application.getDiscoveredPrintersModel().removeDiscoveredPrinter(device.address)
self.discoveredDevicesChanged.emit() self.discoveredDevicesChanged.emit()
## Returns a dict of printer BOM numbers to machine types.
# These numbers are available in the machine definition already so we just search for them here.
def _getPrinterTypeIdentifiers(self) -> Dict[str, str]:
container_registry = self._application.getContainerRegistry()
ultimaker_machines = container_registry.findContainersMetadata(type="machine", manufacturer="Ultimaker B.V.")
found_machine_type_identifiers = {} # type: Dict[str, str]
for machine in ultimaker_machines:
machine_bom_number = machine.get("firmware_update_info", {}).get("id", None)
machine_type = machine.get("id", None)
if machine_bom_number and machine_type:
found_machine_type_identifiers[str(machine_bom_number)] = machine_type
return found_machine_type_identifiers
def _onAddDevice(self, name, address, properties): def _onAddDevice(self, name, address, properties):
# Check what kind of device we need to add; Depending on the firmware we either add a "Connect"/"Cluster" # Check what kind of device we need to add; Depending on the firmware we either add a "Connect"/"Cluster"
# or "Legacy" UM3 device. # or "Legacy" UM3 device.
cluster_size = int(properties.get(b"cluster_size", -1)) cluster_size = int(properties.get(b"cluster_size", -1))
printer_type = properties.get(b"machine", b"").decode("utf-8") printer_type = properties.get(b"machine", b"").decode("utf-8")
printer_type_identifiers = { printer_type_identifiers = self._getPrinterTypeIdentifiers()
"9066": "ultimaker3",
"9511": "ultimaker3_extended",
"9051": "ultimaker_s5"
}
for key, value in printer_type_identifiers.items(): for key, value in printer_type_identifiers.items():
if printer_type.startswith(key): if printer_type.startswith(key):