mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Fix cluster host checking, show neat actionable message when not host
This commit is contained in:
parent
669e64afdb
commit
90c69e079c
4 changed files with 40 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -215,11 +215,6 @@ class LocalClusterOutputDeviceManager:
|
|||
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)
|
||||
|
|
|
@ -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.
|
||||
|
@ -212,6 +216,13 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
|
|||
if self._active_printer and self._active_printer.key == removed_printer.key:
|
||||
self.setActivePrinter(None)
|
||||
|
||||
# Check if this is actually a group host.
|
||||
if len(new_printers) < 1 and self.isConnected():
|
||||
NotClusterHostMessage(self).show()
|
||||
self.close()
|
||||
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
|
||||
return
|
||||
|
||||
self._printers = new_printers
|
||||
if self._printers and not self.activePrinter:
|
||||
self.setActivePrinter(self._printers[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue