Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py')
-rw-r--r--plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py
index 8448c095c8..4ee74550a4 100644
--- a/plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py
+++ b/plugins/UM3NetworkPrinting/src/Cloud/AbstractCloudOutputDevice.py
@@ -1,15 +1,19 @@
from time import time
-from typing import List
+from typing import Callable, List, Optional
-from PyQt6.QtCore import QObject
+from PyQt6.QtCore import QObject, pyqtSlot
from PyQt6.QtNetwork import QNetworkReply
from UM import i18nCatalog
from UM.Logger import Logger
+from UM.FileHandler.FileHandler import FileHandler
+from UM.Resources import Resources
+from UM.Scene.SceneNode import SceneNode
+
+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
@@ -19,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()}
@@ -31,6 +35,11 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
parent=parent
)
+ 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()
def connect(self) -> None:
@@ -41,7 +50,6 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
Logger.log("i", "Attempting to connect AbstractCloudOutputDevice %s", self.key)
super().connect()
- #CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange)
self._update()
def disconnect(self) -> None:
@@ -84,4 +92,31 @@ class AbstractCloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
self._updatePrinters(all_configurations)
def _onError(self, reply: QNetworkReply, error: QNetworkReply.NetworkError) -> None:
- pass
+ Logger.log("w", f"Failed to get clusters by machine type: {str(error)}.")
+
+ @pyqtSlot(str)
+ def printerSelected(self, unique_id: str):
+ self._request_write_callback(unique_id, self._nodes)
+ if self._on_print_dialog:
+ self._on_print_dialog.close()
+
+ @pyqtSlot()
+ def refresh(self):
+ self._refresh_callback()
+ self._update()
+
+ def _openChoosePrinterDialog(self) -> None:
+ if self._on_print_dialog is None:
+ qml_path = Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Dialogs", "ChoosePrinterDialog.qml")
+ self._on_print_dialog = CuraApplication.getInstance().createQmlComponent(qml_path, {})
+ if self._on_print_dialog is None: # Failed to load QML file.
+ return
+ self._on_print_dialog.setProperty("manager", self)
+ 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()