Update cluster view components

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-27 15:54:44 +01:00
parent 52a137a68c
commit 5d3779da26
9 changed files with 59 additions and 50 deletions

View file

@ -16,7 +16,7 @@ if MYPY:
class PrinterOutputModel(QObject):
bedTemperatureChanged = pyqtSignal()
targetBedTemperatureChanged = pyqtSignal()
printerStateChanged = pyqtSignal()
stateChanged = pyqtSignal()
activePrintJobChanged = pyqtSignal()
nameChanged = pyqtSignal()
headPositionChanged = pyqtSignal()
@ -161,17 +161,17 @@ class PrinterOutputModel(QObject):
self._active_print_job = print_job
self.activePrintJobChanged.emit()
def updatePrinterState(self, printer_state):
def updateState(self, printer_state):
if self._printer_state != printer_state:
self._printer_state = printer_state
self.printerStateChanged.emit()
self.stateChanged.emit()
@pyqtProperty(QObject, notify = activePrintJobChanged)
def activePrintJob(self):
return self._active_print_job
@pyqtProperty(str, notify=printerStateChanged)
def printerState(self):
@pyqtProperty(str, notify=stateChanged)
def state(self):
return self._printer_state
@pyqtProperty(int, notify = bedTemperatureChanged)

View file

@ -86,6 +86,10 @@ class PrinterOutputDevice(QObject, OutputDevice):
return self._printers[0]
return None
@pyqtProperty("QVariantList", notify = printersChanged)
def printers(self):
return self._printers
@pyqtProperty(QObject, constant=True)
def monitorItem(self):
# Note that we specifically only check if the monitor component is created.

View file

@ -12,7 +12,6 @@ Component
width: maximumWidth
height: maximumHeight
color: UM.Theme.getColor("viewport_background")
property var emphasisColor: UM.Theme.getColor("setting_control_border_highlight")
property var lineColor: "#DCDCDC" // TODO: Should be linked to theme.
property var cornerRadius: 4 * screenScaleFactor // TODO: Should be linked to theme.
@ -34,9 +33,9 @@ Component
horizontalCenter: parent.horizontalCenter
}
text: OutputDevice.connectedPrinters.length == 0 ? catalog.i18nc("@label: arg 1 is group name", "%1 is not set up to host a group of connected Ultimaker 3 printers").arg(Cura.MachineManager.printerOutputDevices[0].name) : ""
text: OutputDevice.printers.length == 0 ? catalog.i18nc("@label: arg 1 is group name", "%1 is not set up to host a group of connected Ultimaker 3 printers").arg(Cura.MachineManager.printerOutputDevices[0].name) : ""
visible: OutputDevice.connectedPrinters.length == 0
visible: OutputDevice.printers.length == 0
}
Item
@ -47,7 +46,7 @@ Component
width: Math.min(800 * screenScaleFactor, maximumWidth)
height: children.height
visible: OutputDevice.connectedPrinters.length != 0
visible: OutputDevice.printers.length != 0
Label
{
@ -80,7 +79,7 @@ Component
anchors.fill: parent
spacing: -UM.Theme.getSize("default_lining").height
model: OutputDevice.connectedPrinters
model: OutputDevice.printers
delegate: PrinterInfoBlock
{

View file

@ -20,7 +20,11 @@ import os
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
printJobsChanged = pyqtSignal()
printersChanged = pyqtSignal()
# This is a bit of a hack, as the notify can only use signals that are defined by the class that they are in.
# Inheritance doesn't seem to work. Tying them together does work, but i'm open for better suggestions.
clusterPrintersChanged = 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/"
@ -32,6 +36,9 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ClusterMonitorItem.qml")
self._control_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ClusterControlItem.qml")
# See comments about this hack with the clusterPrintersChanged signal
self.printersChanged.connect(self.clusterPrintersChanged)
@pyqtSlot()
def openPrintJobControlPanel(self):
Logger.log("d", "Opening print job control panel...")
@ -54,7 +61,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
def activePrintJobs(self):
return [print_job for print_job in self._print_jobs if print_job.assignedPrinter is not None]
@pyqtProperty("QVariantList", notify=printersChanged)
@pyqtProperty("QVariantList", notify=clusterPrintersChanged)
def connectedPrintersTypeCount(self):
printer_count = {}
for printer in self._printers:
@ -119,7 +126,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
except json.decoder.JSONDecodeError:
Logger.log("w", "Received an invalid printers state message: Not valid JSON.")
return
printer_list_changed = False
# TODO: Ensure that printers that have been removed are also removed locally.
for printer_data in result:
uuid = printer_data["uuid"]
@ -133,10 +140,15 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
if printer is None:
printer = PrinterOutputModel(output_controller=None, number_of_extruders=self._number_of_extruders)
self._printers.append(printer)
printer_list_changed = True
printer.updateName(printer_data["friendly_name"])
printer.updateKey(uuid)
printer.updateType(printer_data["machine_variant"])
if not printer_data["enabled"]:
printer.updateState("disabled")
else:
printer.updateState(printer_data["status"])
for index in range(0, self._number_of_extruders):
extruder = printer.extruders[index]
@ -171,6 +183,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
name = name)
extruder.updateActiveMaterial(material)
if printer_list_changed:
self.printersChanged.emit()
else:
Logger.log("w",
"Got status code {status_code} while trying to get printer data".format(status_code=status_code))

View file

@ -159,7 +159,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
# No active printer. Unable to write
return
if self.activePrinter.printerState not in ["idle", ""]:
if self.activePrinter.state not in ["idle", ""]:
# Printer is not able to accept commands.
return
@ -578,7 +578,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
printer = self._printers[0]
printer.updateBedTemperature(result["bed"]["temperature"]["current"])
printer.updateTargetBedTemperature(result["bed"]["temperature"]["target"])
printer.updatePrinterState(result["status"])
printer.updateState(result["status"])
head_position = result["heads"][0]["position"]
printer.updateHeadPosition(head_position["x"], head_position["y"], head_position["z"])

View file

@ -15,7 +15,7 @@ Item
Label
{
id: materialLabel
text: printCoreConfiguration.material.material + " (" + printCoreConfiguration.material.color + ")"
text: printCoreConfiguration.activeMaterial.type + " (" + printCoreConfiguration.activeMaterial.color + ")"
elide: Text.ElideRight
width: parent.width
font: UM.Theme.getFont("very_small")
@ -23,7 +23,7 @@ Item
Label
{
id: printCoreLabel
text: printCoreConfiguration.print_core_id
text: printCoreConfiguration.hotendID
anchors.top: materialLabel.bottom
elide: Text.ElideRight
width: parent.width

View file

@ -31,7 +31,7 @@ Rectangle
function printerStatusText(printer)
{
switch (printer.status)
switch (printer.state)
{
case "pre_print":
return catalog.i18nc("@label", "Preparing to print")
@ -49,22 +49,14 @@ Rectangle
}
id: printerDelegate
property var printer
property var printer: null
property var printJob: printer != null ? printer.activePrintJob: null
border.width: UM.Theme.getSize("default_lining").width
border.color: mouse.containsMouse ? emphasisColor : lineColor
z: mouse.containsMouse ? 1 : 0 // Push this item up a bit on mouse over to ensure that the highlighted bottom border is visible.
property var printJob:
{
if (printer.reserved_by != null)
{
// Look in another list.
return OutputDevice.printJobsByUUID[printer.reserved_by]
}
return OutputDevice.printJobsByPrinterUUID[printer.uuid]
}
MouseArea
{
id: mouse
@ -73,7 +65,7 @@ Rectangle
hoverEnabled: true;
// Only clickable if no printer is selected
enabled: OutputDevice.selectedPrinterName == "" && printer.status !== "unreachable"
enabled: OutputDevice.selectedPrinterName == "" && printer.state !== "unreachable"
}
Row
@ -166,7 +158,7 @@ Rectangle
anchors.right: printProgressArea.left
anchors.rightMargin: UM.Theme.getSize("default_margin").width
color: emphasisColor
opacity: printer != null && printer.status === "unreachable" ? 0.3 : 1
opacity: printer != null && printer.state === "unreachable" ? 0.3 : 1
Image
{
@ -192,7 +184,7 @@ Rectangle
{
id: leftExtruderInfo
width: Math.floor((parent.width - extruderSeperator.width) / 2)
printCoreConfiguration: printer.configuration[0]
printCoreConfiguration: printer.extruders[0]
}
Rectangle
@ -207,7 +199,7 @@ Rectangle
{
id: rightExtruderInfo
width: Math.floor((parent.width - extruderSeperator.width) / 2)
printCoreConfiguration: printer.configuration[1]
printCoreConfiguration: printer.extruders[1]
}
}
@ -225,9 +217,9 @@ Rectangle
if(printJob != null)
{
var extendStates = ["sent_to_printer", "wait_for_configuration", "printing", "pre_print", "post_print", "wait_cleanup", "queued"];
return extendStates.indexOf(printJob.status) !== -1;
return extendStates.indexOf(printJob.state) !== -1;
}
return !printer.enabled;
return printer.state == "disabled"
}
Item // Status and Percent
@ -235,7 +227,7 @@ Rectangle
id: printProgressTitleBar
property var showPercent: {
return printJob != null && (["printing", "post_print", "pre_print", "sent_to_printer"].indexOf(printJob.status) !== -1);
return printJob != null && (["printing", "post_print", "pre_print", "sent_to_printer"].indexOf(printJob.state) !== -1);
}
width: parent.width
@ -252,19 +244,19 @@ Rectangle
anchors.rightMargin: UM.Theme.getSize("default_margin").width
anchors.verticalCenter: parent.verticalCenter
text: {
if (!printer.enabled)
if (printer.state == "disabled")
{
return catalog.i18nc("@label:status", "Disabled");
}
if (printer.status === "unreachable")
if (printer.state === "unreachable")
{
return printerStatusText(printer);
}
if (printJob != null)
{
switch (printJob.status)
switch (printJob.state)
{
case "printing":
case "post_print":
@ -328,26 +320,26 @@ Rectangle
visible: !printProgressTitleBar.showPercent
source: {
if (!printer.enabled)
if (printer.state == "disabled")
{
return "blocked-icon.svg";
}
if (printer.status === "unreachable")
if (printer.state === "unreachable")
{
return "";
}
if (printJob != null)
{
if(printJob.status === "queued")
if(printJob.state === "queued")
{
if (printJob.configuration_changes_required != null && printJob.configuration_changes_required.length !== 0)
{
return "action-required-icon.svg";
}
}
else if (printJob.status === "wait_cleanup")
else if (printJob.state === "wait_cleanup")
{
return "checkmark-icon.svg";
}
@ -384,19 +376,19 @@ Rectangle
{
text:
{
if (!printer.enabled)
if (printer.state == "disabled")
{
return catalog.i18nc("@label", "Not accepting print jobs");
}
if (printer.status === "unreachable")
if (printer.state === "unreachable")
{
return "";
}
if(printJob != null)
{
switch (printJob.status)
switch (printJob.state)
{
case "printing":
case "post_print":
@ -432,7 +424,7 @@ Rectangle
text: {
if(printJob != null)
{
if(printJob.status == "printing" || printJob.status == "post_print")
if(printJob.state == "printing" || printJob.state == "post_print")
{
return OutputDevice.getDateCompleted(printJob.time_total - printJob.time_elapsed)
}

View file

@ -73,7 +73,7 @@ Item
if(!printerConnected || !printerAcceptsCommands)
return UM.Theme.getColor("text");
switch(activePrinter.printerState)
switch(activePrinter.state)
{
case "maintenance":
return UM.Theme.getColor("status_busy");
@ -118,7 +118,7 @@ Item
var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
if(activePrinter.printerState == "maintenance")
if(activePrinter.state == "maintenance")
{
return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
}

View file

@ -124,7 +124,7 @@ Rectangle
{
return UM.Theme.getIcon("tab_status_unknown");
}
if (Cura.MachineManager.printerOutputDevices[0].printerState == "maintenance")
if (Cura.MachineManager.printerOutputDevices[0].state == "maintenance")
{
return UM.Theme.getIcon("tab_status_busy");
}