mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 07:44:22 +08:00
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:
commit
87517a77c2
@ -250,29 +250,13 @@ Cura.MachineAction
|
||||
renderType: Text.NativeRendering
|
||||
text:
|
||||
{
|
||||
if(base.selectedDevice)
|
||||
{
|
||||
if (base.selectedDevice.printerType == "ultimaker3")
|
||||
{
|
||||
return "Ultimaker 3";
|
||||
}
|
||||
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 ""
|
||||
if (base.selectedDevice) {
|
||||
// It would be great to use a more readable machine type here,
|
||||
// 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 base.selectedDevice.printerType
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
Label
|
||||
|
@ -11,20 +11,8 @@ import UM 1.2 as UM
|
||||
*/
|
||||
Item
|
||||
{
|
||||
// The printer name
|
||||
id: monitorPrinterPill
|
||||
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!
|
||||
implicitWidth: Math.max(printerNameLabel.contentWidth + 12 * screenScaleFactor, 36 * screenScaleFactor) // TODO: Theme!
|
||||
@ -40,9 +28,9 @@ Item
|
||||
id: printerNameLabel
|
||||
anchors.centerIn: parent
|
||||
color: UM.Theme.getColor("monitor_text_primary")
|
||||
text: tagText
|
||||
text: monitorPrinterPill.text
|
||||
font.pointSize: 10 // TODO: Theme!
|
||||
visible: text !== ""
|
||||
visible: monitorPrinterPill.text !== ""
|
||||
renderType: Text.NativeRendering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
from queue import Queue
|
||||
from threading import Event, Thread
|
||||
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
|
||||
|
||||
@ -67,7 +67,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
||||
self._zero_conf = None
|
||||
self._zero_conf_browser = None
|
||||
|
||||
@ -83,7 +83,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._application.globalContainerStackChanged.connect(self.refreshConnections)
|
||||
|
||||
self._discovered_devices = {}
|
||||
|
||||
|
||||
self._network_manager = QNetworkAccessManager()
|
||||
self._network_manager.finished.connect(self._onNetworkRequestFinished)
|
||||
|
||||
@ -124,7 +124,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
# Check if cloud flow is possible when user switches machines
|
||||
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)
|
||||
|
||||
# Listen if cloud cluster was added
|
||||
@ -168,7 +168,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
if address:
|
||||
self.addManualDevice(address)
|
||||
self.resetLastManualDevice()
|
||||
|
||||
|
||||
# TODO: CHANGE TO HOSTNAME
|
||||
def refreshConnections(self):
|
||||
active_machine = CuraApplication.getInstance().getGlobalContainerStack()
|
||||
@ -395,17 +395,28 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._application.getDiscoveredPrintersModel().removeDiscoveredPrinter(device.address)
|
||||
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):
|
||||
# Check what kind of device we need to add; Depending on the firmware we either add a "Connect"/"Cluster"
|
||||
# or "Legacy" UM3 device.
|
||||
cluster_size = int(properties.get(b"cluster_size", -1))
|
||||
|
||||
printer_type = properties.get(b"machine", b"").decode("utf-8")
|
||||
printer_type_identifiers = {
|
||||
"9066": "ultimaker3",
|
||||
"9511": "ultimaker3_extended",
|
||||
"9051": "ultimaker_s5"
|
||||
}
|
||||
printer_type_identifiers = self._getPrinterTypeIdentifiers()
|
||||
|
||||
for key, value in printer_type_identifiers.items():
|
||||
if printer_type.startswith(key):
|
||||
@ -517,7 +528,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
if ConnectionType.CloudConnection.value in active_machine.configuredConnectionTypes:
|
||||
Logger.log("d", "Active machine was already configured for cloud.")
|
||||
return
|
||||
|
||||
|
||||
# Check 1B: Printer isn't already configured for cloud
|
||||
if active_machine.getMetaDataEntry("cloud_flow_complete", False):
|
||||
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):
|
||||
Logger.log("d", "Active machine shouldn't ask about cloud anymore.")
|
||||
return
|
||||
|
||||
|
||||
# Check 3: User is logged in with an Ultimaker account
|
||||
if not self._account.isLoggedIn:
|
||||
Logger.log("d", "Cloud Flow not possible: User not logged in!")
|
||||
@ -537,7 +548,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
if not self._application.getMachineManager().activeMachineHasNetworkConnection:
|
||||
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
|
||||
return
|
||||
|
||||
|
||||
# Check 5: Machine has correct firmware version
|
||||
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion # type: str
|
||||
if not Version(firmware_version) > self._min_cloud_version:
|
||||
@ -545,7 +556,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
firmware_version,
|
||||
self._min_cloud_version)
|
||||
return
|
||||
|
||||
|
||||
Logger.log("d", "Cloud flow is possible!")
|
||||
self.cloudFlowIsPossible.emit()
|
||||
|
||||
@ -554,20 +565,20 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
if not self._start_cloud_flow_message:
|
||||
self._createCloudFlowStartMessage()
|
||||
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:
|
||||
# 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
|
||||
if self._start_cloud_flow_message and self._start_cloud_flow_message.visible:
|
||||
self._start_cloud_flow_message.hide()
|
||||
|
||||
|
||||
# Cloud flow is complete, so show the message
|
||||
if not self._cloud_flow_complete_message:
|
||||
self._createCloudFlowCompleteMessage()
|
||||
if self._cloud_flow_complete_message and not self._cloud_flow_complete_message.visible:
|
||||
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
|
||||
active_machine = self._application.getMachineManager().activeMachine
|
||||
if active_machine:
|
||||
@ -580,7 +591,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
|
||||
if added_host_name == saved_host_name:
|
||||
active_machine.setMetaDataEntry("do_not_show_cloud_message", True)
|
||||
|
||||
|
||||
return
|
||||
|
||||
def _onDontAskMeAgain(self, checked: bool) -> None:
|
||||
@ -599,7 +610,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._start_cloud_flow_message.hide()
|
||||
self._start_cloud_flow_message = None
|
||||
return
|
||||
|
||||
|
||||
def _onReviewCloudConnection(self, messageId: str, actionId: str) -> None:
|
||||
address = self._application.getMachineManager().activeMachineAddress # type: str
|
||||
if address:
|
||||
@ -643,4 +654,4 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
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.actionTriggered.connect(self._onReviewCloudConnection)
|
||||
self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection)
|
||||
|
Loading…
x
Reference in New Issue
Block a user