Remove absolute plugin imports, some fixes

This commit is contained in:
ChrisTerBeke 2019-07-29 16:11:01 +02:00
parent 7d69b1727d
commit ddd282eef3
16 changed files with 67 additions and 62 deletions

View file

@ -8,12 +8,13 @@ from PyQt5.QtCore import QUrl
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
from UM.Logger import Logger
from plugins.UM3NetworkPrinting.src.Models.BaseModel import BaseModel
from ..Models.BaseModel import BaseModel
from ..Models.Http.ClusterPrintJobStatus import ClusterPrintJobStatus
from ..Models.Http.ClusterPrinterStatus import ClusterPrinterStatus
## The generic type variable used to document the methods below.
from plugins.UM3NetworkPrinting.src.Models.Http.ClusterPrinterStatus import ClusterPrinterStatus
ClusterApiClientModel = TypeVar("ClusterApiClientModel", bound=BaseModel)
@ -53,13 +54,23 @@ class ClusterApiClient:
## Get the print jobs in the cluster.
# \param on_finished: The callback in case the response is successful.
def getPrintJobs(self, on_finished: Callable) -> None:
def getPrintJobs(self, on_finished: Callable[[List[ClusterPrintJobStatus]], Any]) -> None:
url = f"{self.CLUSTER_API_PREFIX}/print_jobs/"
# reply = self._manager.get(self._createEmptyRequest(url))
# self._addCallback(reply, on_finished)
reply = self._manager.get(self._createEmptyRequest(url))
self._addCallback(reply, on_finished, ClusterPrintJobStatus)
def requestPrint(self) -> None:
pass
pass # TODO
## Move a print job to the top of the queue.
def movePrintJobToTop(self, print_job_uuid: str) -> None:
url = f"{self.CLUSTER_API_PREFIX}/print_jobs/{print_job_uuid}/action/move"
self._manager.post(self._createEmptyRequest(url), json.dumps({"to_position": 0, "list": "queued"}).encode())
## Delete a print job from the queue.
def deletePrintJob(self, print_job_uuid: str) -> None:
url = f"{self.CLUSTER_API_PREFIX}/print_jobs/{print_job_uuid}"
self._manager.deleteResource(self._createEmptyRequest(url))
## Send a print job action to the cluster.
# \param print_job_uuid: The UUID of the print job to perform the action on.
@ -68,7 +79,7 @@ class ClusterApiClient:
def doPrintJobAction(self, print_job_uuid: str, action: str, data: Optional[Dict[str, Union[str, int]]] = None
) -> None:
url = f"{self.CLUSTER_API_PREFIX}/print_jobs/{print_job_uuid}/action/{action}/"
body = json.loads(data).encode() if data else b""
body = json.dumps(data).encode() if data else b""
self._manager.put(self._createEmptyRequest(url), body)
## We override _createEmptyRequest in order to add the user credentials.

View file

@ -20,7 +20,7 @@ from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOut
I18N_CATALOG = i18nCatalog("cura")
class ClusterUM3OutputDevice(UltimakerNetworkedPrinterOutputDevice):
class LocalClusterOutputDevice(UltimakerNetworkedPrinterOutputDevice):
activeCameraUrlChanged = pyqtSignal()
@ -88,11 +88,11 @@ class ClusterUM3OutputDevice(UltimakerNetworkedPrinterOutputDevice):
@pyqtSlot(str, name="sendJobToTop")
def sendJobToTop(self, print_job_uuid: str) -> None:
self._cluster_api.doPrintJobAction(print_job_uuid, "move", {"to_position": 0, "list": "queued"})
self._cluster_api.movePrintJobToTop(print_job_uuid)
@pyqtSlot(str, name="deleteJobFromQueue")
def deleteJobFromQueue(self, print_job_uuid: str) -> None:
self._cluster_api.doPrintJobAction(print_job_uuid, "delete")
self._cluster_api.deletePrintJob(print_job_uuid)
@pyqtSlot(str, name="forceSendJob")
def forceSendJob(self, print_job_uuid: str) -> None:

View file

@ -15,9 +15,10 @@ from UM.Version import Version
from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice
from plugins.UM3NetworkPrinting.src.Network.ClusterApiClient import ClusterApiClient
from plugins.UM3NetworkPrinting.src.Network.ClusterUM3OutputDevice import ClusterUM3OutputDevice
from plugins.UM3NetworkPrinting.src.Network.ManualPrinterRequest import ManualPrinterRequest
from .ClusterApiClient import ClusterApiClient
from .LocalClusterOutputDevice import LocalClusterOutputDevice
from .ManualPrinterRequest import ManualPrinterRequest
## The NetworkOutputDeviceManager is responsible for discovering and managing local networked clusters.
@ -37,7 +38,7 @@ class NetworkOutputDeviceManager:
def __init__(self) -> None:
# Persistent dict containing the networked clusters.
self._discovered_devices = {} # type: Dict[str, ClusterUM3OutputDevice]
self._discovered_devices = {} # type: Dict[str, LocalClusterOutputDevice]
self._output_device_manager = CuraApplication.getInstance().getOutputDeviceManager()
self._zero_conf = None # type: Optional[Zeroconf]
@ -211,7 +212,7 @@ class NetworkOutputDeviceManager:
if cluster_size == -1:
return
device = ClusterUM3OutputDevice(key, address, properties)
device = LocalClusterOutputDevice(key, address, properties)
CuraApplication.getInstance().getDiscoveredPrintersModel().addDiscoveredPrinter(
ip_address=address,