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
@ -67,7 +67,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._zero_conf = None self._zero_conf = None
self._zero_conf_browser = None self._zero_conf_browser = None
@ -83,7 +83,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._application.globalContainerStackChanged.connect(self.refreshConnections) self._application.globalContainerStackChanged.connect(self.refreshConnections)
self._discovered_devices = {} self._discovered_devices = {}
self._network_manager = QNetworkAccessManager() self._network_manager = QNetworkAccessManager()
self._network_manager.finished.connect(self._onNetworkRequestFinished) self._network_manager.finished.connect(self._onNetworkRequestFinished)
@ -124,7 +124,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
# Check if cloud flow is possible when user switches machines # Check if cloud flow is possible when user switches machines
self._application.globalContainerStackChanged.connect(self._onMachineSwitched) self._application.globalContainerStackChanged.connect(self._onMachineSwitched)
# Listen for when cloud flow is possible # Listen for when cloud flow is possible
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible) self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
# Listen if cloud cluster was added # Listen if cloud cluster was added
@ -168,7 +168,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if address: if address:
self.addManualDevice(address) self.addManualDevice(address)
self.resetLastManualDevice() self.resetLastManualDevice()
# TODO: CHANGE TO HOSTNAME # TODO: CHANGE TO HOSTNAME
def refreshConnections(self): def refreshConnections(self):
active_machine = CuraApplication.getInstance().getGlobalContainerStack() active_machine = CuraApplication.getInstance().getGlobalContainerStack()
@ -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):
@ -517,7 +528,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if ConnectionType.CloudConnection.value in active_machine.configuredConnectionTypes: if ConnectionType.CloudConnection.value in active_machine.configuredConnectionTypes:
Logger.log("d", "Active machine was already configured for cloud.") Logger.log("d", "Active machine was already configured for cloud.")
return return
# Check 1B: Printer isn't already configured for cloud # Check 1B: Printer isn't already configured for cloud
if active_machine.getMetaDataEntry("cloud_flow_complete", False): if active_machine.getMetaDataEntry("cloud_flow_complete", False):
Logger.log("d", "Active machine was already configured for cloud.") Logger.log("d", "Active machine was already configured for cloud.")
@ -527,7 +538,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if active_machine.getMetaDataEntry("do_not_show_cloud_message", False): if active_machine.getMetaDataEntry("do_not_show_cloud_message", False):
Logger.log("d", "Active machine shouldn't ask about cloud anymore.") Logger.log("d", "Active machine shouldn't ask about cloud anymore.")
return return
# Check 3: User is logged in with an Ultimaker account # Check 3: User is logged in with an Ultimaker account
if not self._account.isLoggedIn: if not self._account.isLoggedIn:
Logger.log("d", "Cloud Flow not possible: User not logged in!") Logger.log("d", "Cloud Flow not possible: User not logged in!")
@ -537,7 +548,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if not self._application.getMachineManager().activeMachineHasNetworkConnection: if not self._application.getMachineManager().activeMachineHasNetworkConnection:
Logger.log("d", "Cloud Flow not possible: Machine is not connected!") Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
return return
# Check 5: Machine has correct firmware version # Check 5: Machine has correct firmware version
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion # type: str firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion # type: str
if not Version(firmware_version) > self._min_cloud_version: if not Version(firmware_version) > self._min_cloud_version:
@ -545,7 +556,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
firmware_version, firmware_version,
self._min_cloud_version) self._min_cloud_version)
return return
Logger.log("d", "Cloud flow is possible!") Logger.log("d", "Cloud flow is possible!")
self.cloudFlowIsPossible.emit() self.cloudFlowIsPossible.emit()
@ -554,20 +565,20 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if not self._start_cloud_flow_message: if not self._start_cloud_flow_message:
self._createCloudFlowStartMessage() self._createCloudFlowStartMessage()
if self._start_cloud_flow_message and not self._start_cloud_flow_message.visible: if self._start_cloud_flow_message and not self._start_cloud_flow_message.visible:
self._start_cloud_flow_message.show() self._start_cloud_flow_message.show()
def _onCloudPrintingConfigured(self, device) -> None: def _onCloudPrintingConfigured(self, device) -> None:
# Hide the cloud flow start message if it was hanging around already # Hide the cloud flow start message if it was hanging around already
# For example: if the user already had the browser openen and made the association themselves # For example: if the user already had the browser openen and made the association themselves
if self._start_cloud_flow_message and self._start_cloud_flow_message.visible: if self._start_cloud_flow_message and self._start_cloud_flow_message.visible:
self._start_cloud_flow_message.hide() self._start_cloud_flow_message.hide()
# Cloud flow is complete, so show the message # Cloud flow is complete, so show the message
if not self._cloud_flow_complete_message: if not self._cloud_flow_complete_message:
self._createCloudFlowCompleteMessage() self._createCloudFlowCompleteMessage()
if self._cloud_flow_complete_message and not self._cloud_flow_complete_message.visible: if self._cloud_flow_complete_message and not self._cloud_flow_complete_message.visible:
self._cloud_flow_complete_message.show() self._cloud_flow_complete_message.show()
# Set the machine's cloud flow as complete so we don't ask the user again and again for cloud connected printers # Set the machine's cloud flow as complete so we don't ask the user again and again for cloud connected printers
active_machine = self._application.getMachineManager().activeMachine active_machine = self._application.getMachineManager().activeMachine
if active_machine: if active_machine:
@ -580,7 +591,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
if added_host_name == saved_host_name: if added_host_name == saved_host_name:
active_machine.setMetaDataEntry("do_not_show_cloud_message", True) active_machine.setMetaDataEntry("do_not_show_cloud_message", True)
return return
def _onDontAskMeAgain(self, checked: bool) -> None: def _onDontAskMeAgain(self, checked: bool) -> None:
@ -599,7 +610,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._start_cloud_flow_message.hide() self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None self._start_cloud_flow_message = None
return return
def _onReviewCloudConnection(self, messageId: str, actionId: str) -> None: def _onReviewCloudConnection(self, messageId: str, actionId: str) -> None:
address = self._application.getMachineManager().activeMachineAddress # type: str address = self._application.getMachineManager().activeMachineAddress # type: str
if address: if address:
@ -643,4 +654,4 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
image_caption = i18n_catalog.i18nc("@info:status", "Connected!") image_caption = i18n_catalog.i18nc("@info:status", "Connected!")
) )
self._cloud_flow_complete_message.addAction("", i18n_catalog.i18nc("@action", "Review your connection"), "", "", 1) # TODO: Icon self._cloud_flow_complete_message.addAction("", i18n_catalog.i18nc("@action", "Review your connection"), "", "", 1) # TODO: Icon
self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection) self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection)