mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Connect buttons for selected printers: Print and refresh.
part of CURA-9278
This commit is contained in:
parent
2b1909b7b5
commit
b7611da95e
3 changed files with 22 additions and 9 deletions
|
@ -29,6 +29,7 @@ class CompatibleMachineModel(ListModel):
|
|||
from cura.CuraApplication import CuraApplication
|
||||
machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||
machine_manager.globalContainerChanged.connect(self._update)
|
||||
machine_manager.outputDevicesChanged.connect(self._update)
|
||||
|
||||
def _update(self) -> None:
|
||||
self.clear()
|
||||
|
@ -77,6 +78,6 @@ class CompatibleMachineModel(ListModel):
|
|||
if all([len(extruder["materials"]) > 0 for extruder in extruder_configs.values()]):
|
||||
self.appendItem({
|
||||
"name": printer.name,
|
||||
"unique_id": printer.uniqueName,
|
||||
"unique_id": printer.name, # <- Can assume the cloud doesn't have duplicate names?
|
||||
"extruders": [extruder for extruder in extruder_configs.values()]
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from time import time
|
||||
from typing import List, Optional
|
||||
from typing import Callable, List, Optional
|
||||
|
||||
from PyQt6.QtCore import QObject, pyqtSlot
|
||||
from PyQt6.QtNetwork import QNetworkReply
|
||||
|
@ -14,7 +14,6 @@ from cura.CuraApplication import CuraApplication
|
|||
from cura.PrinterOutput.NetworkedPrinterOutputDevice import AuthState
|
||||
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
|
||||
from .CloudApiClient import CloudApiClient
|
||||
from ..Models.Http.CloudClusterResponse import CloudClusterResponse
|
||||
from ..Models.Http.CloudClusterWithConfigResponse import CloudClusterWithConfigResponse
|
||||
from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice
|
||||
|
||||
|
@ -24,7 +23,7 @@ I18N_CATALOG = i18nCatalog("cura")
|
|||
class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
|
||||
API_CHECK_INTERVAL = 10.0 # seconds
|
||||
|
||||
def __init__(self, api_client: CloudApiClient, printer_type: str, parent: QObject = None) -> None:
|
||||
def __init__(self, api_client: CloudApiClient, printer_type: str, request_write_callback: Callable, refresh_callback: Callable, parent: QObject = None) -> None:
|
||||
|
||||
self._api = api_client
|
||||
properties = {b"printer_type": printer_type.encode()}
|
||||
|
@ -37,6 +36,9 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
|
|||
)
|
||||
|
||||
self._on_print_dialog: Optional[QObject] = None
|
||||
self._nodes: List[SceneNode] = None
|
||||
self._request_write_callback = request_write_callback
|
||||
self._refresh_callback = refresh_callback
|
||||
|
||||
self._setInterfaceElements()
|
||||
|
||||
|
@ -94,14 +96,14 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
|
|||
|
||||
@pyqtSlot(str)
|
||||
def printerSelected(self, unique_id: str):
|
||||
print(unique_id)
|
||||
self._request_write_callback(unique_id, self._nodes)
|
||||
if self._on_print_dialog:
|
||||
self._on_print_dialog.close()
|
||||
|
||||
@pyqtSlot()
|
||||
def refresh(self):
|
||||
print("-REFRESH-")
|
||||
pass
|
||||
self._refresh_callback()
|
||||
self._update()
|
||||
|
||||
def _openChoosePrinterDialog(self) -> None:
|
||||
if self._on_print_dialog is None:
|
||||
|
@ -113,5 +115,8 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
|
|||
self._on_print_dialog.show()
|
||||
|
||||
def requestWrite(self, nodes: List[SceneNode], file_name: Optional[str] = None, limit_mimetypes: bool = False, file_handler: Optional[FileHandler] = None, **kwargs) -> None:
|
||||
if not nodes or len(nodes) < 1:
|
||||
Logger.log("w", "Nothing to print.")
|
||||
return
|
||||
self._nodes = nodes
|
||||
self._openChoosePrinterDialog()
|
||||
|
||||
|
|
|
@ -172,6 +172,13 @@ class CloudOutputDeviceManager:
|
|||
self._syncing = False
|
||||
self._account.setSyncState(self.SYNC_SERVICE_NAME, SyncState.ERROR)
|
||||
|
||||
def _requestWrite(self, unique_id: str, nodes: List["SceneNode"]):
|
||||
for remote in self._remote_clusters.values():
|
||||
if unique_id == remote.name: # No other id-type would match. Assume cloud doesn't have duplicate names.
|
||||
remote.requestWrite(nodes)
|
||||
return
|
||||
Logger.log("e", f"Failed writing to specific cloud printer: {unique_id} not in remote clusters.")
|
||||
|
||||
def _createMachineStacksForDiscoveredClusters(self, discovered_clusters: List[CloudClusterResponse]) -> None:
|
||||
"""**Synchronously** create machines for discovered devices
|
||||
|
||||
|
@ -193,7 +200,7 @@ class CloudOutputDeviceManager:
|
|||
output_device = CloudOutputDevice(self._api, cluster_data)
|
||||
|
||||
if cluster_data.printer_type not in self._abstract_clusters:
|
||||
self._abstract_clusters[cluster_data.printer_type] = AbstractCloudOutputDevice(self._api, cluster_data.printer_type)
|
||||
self._abstract_clusters[cluster_data.printer_type] = AbstractCloudOutputDevice(self._api, cluster_data.printer_type, self._requestWrite, self.refreshConnections)
|
||||
# Ensure that the abstract machine is added (either because it was never added, or it somehow got
|
||||
# removed)
|
||||
_abstract_machine = CuraStackBuilder.createAbstractMachine(cluster_data.printer_type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue