mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-13 07:09:02 +08:00
Merge pull request #6182 from Ultimaker/fix-network-discovery-refresh
Fixes for network plugin
This commit is contained in:
commit
9b270d5659
@ -1,26 +1,39 @@
|
||||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
|
||||
from UM import i18nCatalog
|
||||
from UM.Message import Message
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
|
||||
|
||||
|
||||
I18N_CATALOG = i18nCatalog("cura")
|
||||
|
||||
|
||||
## Message shown when trying to connect to a printer that is not a host.
|
||||
class NotClusterHostMessage(Message):
|
||||
|
||||
|
||||
# Singleton used to prevent duplicate messages of this type at the same time.
|
||||
__is_visible = False
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
||||
def __init__(self, device: "UltimakerNetworkedPrinterOutputDevice") -> None:
|
||||
super().__init__(
|
||||
text = I18N_CATALOG.i18nc("@info:status", "You are attempting to connect to a printer that is not "
|
||||
"the host of an Ultimaker Connect group. Please connect to "
|
||||
"the host instead."),
|
||||
title = I18N_CATALOG.i18nc("@info:title", "Not a cluster host"),
|
||||
lifetime = 10
|
||||
text = I18N_CATALOG.i18nc("@info:status", "You are attempting to connect to {0} but it is not "
|
||||
"the host of a group. You can visit the web page to configure "
|
||||
"it as a group host.", device.name),
|
||||
title = I18N_CATALOG.i18nc("@info:title", "Not a group host"),
|
||||
lifetime = 0,
|
||||
dismissable = True
|
||||
)
|
||||
self._address = device.address
|
||||
self.addAction("", I18N_CATALOG.i18nc("@action", "Configure group"), "", "")
|
||||
self.actionTriggered.connect(self._onConfigureClicked)
|
||||
|
||||
def show(self) -> None:
|
||||
if NotClusterHostMessage.__is_visible:
|
||||
@ -31,3 +44,7 @@ class NotClusterHostMessage(Message):
|
||||
def hide(self, send_signal = True) -> None:
|
||||
super().hide(send_signal)
|
||||
NotClusterHostMessage.__is_visible = False
|
||||
|
||||
def _onConfigureClicked(self, messageId: str, actionId: str) -> None:
|
||||
QDesktopServices.openUrl(QUrl("http://{}/print_jobs".format(self._address)))
|
||||
self.hide()
|
||||
|
@ -45,6 +45,9 @@ class LocalClusterOutputDevice(UltimakerNetworkedPrinterOutputDevice):
|
||||
self._setInterfaceElements()
|
||||
self._active_camera_url = QUrl() # type: QUrl
|
||||
|
||||
# Get the cluster configuration at least once to check if it is a host.
|
||||
self._update()
|
||||
|
||||
## Set all the interface elements and texts for this output device.
|
||||
def _setInterfaceElements(self) -> None:
|
||||
self.setPriority(3) # Make sure the output device gets selected above local file output
|
||||
|
@ -14,7 +14,7 @@ from .ZeroConfClient import ZeroConfClient
|
||||
from .ClusterApiClient import ClusterApiClient
|
||||
from .LocalClusterOutputDevice import LocalClusterOutputDevice
|
||||
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
|
||||
from ..CloudFlowMessage import CloudFlowMessage
|
||||
from ..Messages.CloudFlowMessage import CloudFlowMessage
|
||||
from ..Messages.LegacyDeviceNoLongerSupportedMessage import LegacyDeviceNoLongerSupportedMessage
|
||||
from ..Messages.NotClusterHostMessage import NotClusterHostMessage
|
||||
from ..Models.Http.PrinterSystemStatus import PrinterSystemStatus
|
||||
@ -57,10 +57,14 @@ class LocalClusterOutputDeviceManager:
|
||||
## Stop network discovery and clean up discovered devices.
|
||||
def stop(self) -> None:
|
||||
self._zero_conf_client.stop()
|
||||
# Cleanup all manual devices.
|
||||
for instance_name in list(self._discovered_devices):
|
||||
self._onDiscoveredDeviceRemoved(instance_name)
|
||||
|
||||
## Restart discovery on the local network.
|
||||
def startDiscovery(self):
|
||||
self.stop()
|
||||
self.start()
|
||||
|
||||
## Add a networked printer manually by address.
|
||||
def addManualDevice(self, address: str, callback: Optional[Callable[[bool, str], None]] = None) -> None:
|
||||
api_client = ClusterApiClient(address, lambda error: print(error))
|
||||
@ -210,12 +214,7 @@ class LocalClusterOutputDeviceManager:
|
||||
if Version(device.firmwareVersion) < self.MIN_SUPPORTED_CLUSTER_VERSION:
|
||||
LegacyDeviceNoLongerSupportedMessage().show()
|
||||
return
|
||||
|
||||
# Tell the user that they cannot connect to a non-host printer.
|
||||
if device.clusterSize < 1:
|
||||
NotClusterHostMessage().show()
|
||||
return
|
||||
|
||||
|
||||
device.connect()
|
||||
machine.addConfiguredConnectionType(device.connectionType.value)
|
||||
CuraApplication.getInstance().getOutputDeviceManager().addOutputDevice(device)
|
||||
|
@ -37,6 +37,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._network_output_device_manager.stop()
|
||||
self._cloud_output_device_manager.stop()
|
||||
|
||||
## Restart network discovery.
|
||||
def startDiscovery(self) -> None:
|
||||
self._network_output_device_manager.startDiscovery()
|
||||
|
||||
## Force refreshing the network connections.
|
||||
def refreshConnections(self) -> None:
|
||||
self._network_output_device_manager.refreshConnections()
|
||||
|
@ -15,6 +15,7 @@ from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
|
||||
from .Utils import formatTimeCompleted, formatDateCompleted
|
||||
from .ClusterOutputController import ClusterOutputController
|
||||
from .Messages.PrintJobUploadProgressMessage import PrintJobUploadProgressMessage
|
||||
from .Messages.NotClusterHostMessage import NotClusterHostMessage
|
||||
from .Models.UM3PrintJobOutputModel import UM3PrintJobOutputModel
|
||||
from .Models.Http.ClusterPrinterStatus import ClusterPrinterStatus
|
||||
from .Models.Http.ClusterPrintJobStatus import ClusterPrintJobStatus
|
||||
@ -95,7 +96,7 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
||||
# Get the amount of printers in the cluster.
|
||||
@pyqtProperty(int, notify=_clusterPrintersChanged)
|
||||
def clusterSize(self) -> int:
|
||||
return max(1, len(self._printers))
|
||||
return len(self._printers)
|
||||
|
||||
# Get the amount of printer in the cluster per type.
|
||||
@pyqtProperty("QVariantList", notify=_clusterPrintersChanged)
|
||||
@ -190,6 +191,9 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
||||
return
|
||||
self._monitor_view_qml_path = os.path.join(plugin_path, "resources", "qml", "MonitorStage.qml")
|
||||
|
||||
def _update(self):
|
||||
super()._update()
|
||||
|
||||
def _updatePrinters(self, remote_printers: List[ClusterPrinterStatus]) -> None:
|
||||
|
||||
# Keep track of the new printers to show.
|
||||
@ -217,6 +221,14 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
||||
self.setActivePrinter(self._printers[0])
|
||||
|
||||
self.printersChanged.emit()
|
||||
self._checkIfClusterHost()
|
||||
|
||||
## Check is this device is a cluster host and takes the needed actions when it is not.
|
||||
def _checkIfClusterHost(self):
|
||||
if len(self._printers) < 1 and self.isConnected():
|
||||
NotClusterHostMessage(self).show()
|
||||
self.close()
|
||||
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
|
||||
|
||||
## Updates the local list of print jobs with the list received from the cluster.
|
||||
# \param remote_jobs: The print jobs received from the cluster.
|
||||
|
Loading…
x
Reference in New Issue
Block a user