mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Ensured that sidebar has the right properties to show again
CL-541
This commit is contained in:
parent
7d9af8e345
commit
52a137a68c
4 changed files with 48 additions and 7 deletions
|
@ -12,13 +12,15 @@ from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
|||
|
||||
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
from PyQt5.QtCore import pyqtSlot, QUrl
|
||||
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
printJobsChanged = pyqtSignal()
|
||||
printersChanged = pyqtSignal()
|
||||
def __init__(self, device_id, address, properties, parent = None):
|
||||
super().__init__(device_id = device_id, address = address, properties=properties, parent = parent)
|
||||
self._api_prefix = "/cluster-api/v1/"
|
||||
|
@ -40,6 +42,31 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
Logger.log("d", "Opening printer control panel...")
|
||||
QDesktopServices.openUrl(QUrl("http://" + self._address + "/printers"))
|
||||
|
||||
@pyqtProperty("QVariantList", notify=printJobsChanged)
|
||||
def printJobs(self):
|
||||
return self._print_jobs
|
||||
|
||||
@pyqtProperty("QVariantList", notify=printJobsChanged)
|
||||
def queuedPrintJobs(self):
|
||||
return [print_job for print_job in self._print_jobs if print_job.assignedPrinter is None]
|
||||
|
||||
@pyqtProperty("QVariantList", notify=printJobsChanged)
|
||||
def activePrintJobs(self):
|
||||
return [print_job for print_job in self._print_jobs if print_job.assignedPrinter is not None]
|
||||
|
||||
@pyqtProperty("QVariantList", notify=printersChanged)
|
||||
def connectedPrintersTypeCount(self):
|
||||
printer_count = {}
|
||||
for printer in self._printers:
|
||||
if printer.type in printer_count:
|
||||
printer_count[printer.type] += 1
|
||||
else:
|
||||
printer_count[printer.type] = 1
|
||||
result = []
|
||||
for machine_type in printer_count:
|
||||
result.append({"machine_type": machine_type, "count": printer_count[machine_type]})
|
||||
return result
|
||||
|
||||
def _update(self):
|
||||
if not super()._update():
|
||||
return
|
||||
|
@ -82,6 +109,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
old_job.assignedPrinter.updateActivePrintJob(None)
|
||||
|
||||
self._print_jobs = print_jobs_seen
|
||||
self.printJobsChanged.emit()
|
||||
|
||||
def _onGetPrintersDataFinished(self, reply: QNetworkReply):
|
||||
status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
|
||||
|
@ -92,6 +120,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
Logger.log("w", "Received an invalid printers state message: Not valid JSON.")
|
||||
return
|
||||
|
||||
# TODO: Ensure that printers that have been removed are also removed locally.
|
||||
for printer_data in result:
|
||||
uuid = printer_data["uuid"]
|
||||
|
||||
|
@ -107,6 +136,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||
|
||||
printer.updateName(printer_data["friendly_name"])
|
||||
printer.updateKey(uuid)
|
||||
printer.updateType(printer_data["machine_variant"])
|
||||
|
||||
for index in range(0, self._number_of_extruders):
|
||||
extruder = printer.extruders[index]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue