Cluster can now "target" one of it's printers for display

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-30 13:07:01 +01:00
parent a49d3dbd8e
commit dea13899b3
5 changed files with 31 additions and 13 deletions

View file

@ -62,7 +62,6 @@ Component
} }
} }
ScrollView ScrollView
{ {
id: printerScrollView id: printerScrollView
@ -93,10 +92,10 @@ Component
} }
} }
/*PrinterVideoStream PrinterVideoStream
{ {
visible: OutputDevice.selectedPrinterName != "" visible: OutputDevice.activePrinter != null
anchors.fill:parent anchors.fill:parent
}*/ }
} }
} }

View file

@ -15,10 +15,12 @@ from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
from PyQt5.QtGui import QDesktopServices from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
from time import time from time import time
from datetime import datetime from datetime import datetime
from typing import Optional
import json import json
import os import os
@ -27,6 +29,7 @@ i18n_catalog = i18nCatalog("cura")
class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
printJobsChanged = pyqtSignal() printJobsChanged = pyqtSignal()
activePrinterChanged = 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. # 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. # Inheritance doesn't seem to work. Tying them together does work, but i'm open for better suggestions.
@ -54,6 +57,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._error_message = None self._error_message = None
self._progress_message = None self._progress_message = None
self._active_printer = None # type: Optional[PrinterOutputModel]
def requestWrite(self, nodes, file_name=None, filter_by_machine=False, file_handler=None, **kwargs): def requestWrite(self, nodes, file_name=None, filter_by_machine=False, file_handler=None, **kwargs):
# Notify the UI that a switch to the print monitor should happen # Notify the UI that a switch to the print monitor should happen
Application.getInstance().showPrintMonitor.emit(True) Application.getInstance().showPrintMonitor.emit(True)
@ -105,11 +110,20 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self.postFormWithParts("print_jobs/", parts, onFinished=self._onPostPrintJobFinished, onProgress=self._onUploadPrintJobProgress) self.postFormWithParts("print_jobs/", parts, onFinished=self._onPostPrintJobFinished, onProgress=self._onUploadPrintJobProgress)
@pyqtProperty(QObject, notify=activePrinterChanged)
def activePrinter(self) -> Optional["PrinterOutputModel"]:
return self._active_printer
@pyqtSlot(QObject)
def setActivePrinter(self, printer):
if self._active_printer != printer:
self._active_printer = printer
self.activePrinterChanged.emit()
def _onPostPrintJobFinished(self, reply): def _onPostPrintJobFinished(self, reply):
self._progress_message.hide() self._progress_message.hide()
self._compressing_gcode = False self._compressing_gcode = False
self._sending_gcode = False self._sending_gcode = False
Application.getInstance().showPrintMonitor.emit(False)
def _onUploadPrintJobProgress(self, bytes_sent, bytes_total): def _onUploadPrintJobProgress(self, bytes_sent, bytes_total):
if bytes_total > 0: if bytes_total > 0:

View file

@ -61,11 +61,11 @@ Rectangle
{ {
id: mouse id: mouse
anchors.fill:parent anchors.fill:parent
onClicked: OutputDevice.selectPrinter(printer.unique_name, printer.friendly_name) onClicked: OutputDevice.setActivePrinter(printer)
hoverEnabled: true; hoverEnabled: true;
// Only clickable if no printer is selected // Only clickable if no printer is selected
enabled: OutputDevice.selectedPrinterName == "" && printer.state !== "unreachable" enabled: OutputDevice.activePrinter == null && printer.state !== "unreachable"
} }
Row Row

View file

@ -17,7 +17,7 @@ Item
MouseArea MouseArea
{ {
anchors.fill: parent anchors.fill: parent
onClicked: OutputDevice.selectAutomaticPrinter() onClicked: OutputDevice.setActivePrinter(null)
z: 0 z: 0
} }

View file

@ -70,8 +70,10 @@ Item
property variant statusColor: property variant statusColor:
{ {
if(!printerConnected || !printerAcceptsCommands) if(!printerConnected || !printerAcceptsCommands || activePrinter == null)
{
return UM.Theme.getColor("text"); return UM.Theme.getColor("text");
}
switch(activePrinter.state) switch(activePrinter.state)
{ {
@ -117,7 +119,10 @@ Item
} }
var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0] var printerOutputDevice = Cura.MachineManager.printerOutputDevices[0]
if(activePrinter == null)
{
return "";
}
if(activePrinter.state == "maintenance") if(activePrinter.state == "maintenance")
{ {
return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer"); return catalog.i18nc("@label:MonitorStatus", "In maintenance. Please check the printer");
@ -262,7 +267,7 @@ Item
property bool userClicked: false property bool userClicked: false
property string lastJobState: "" property string lastJobState: ""
visible: printerConnected && activePrinter.canPause visible: printerConnected && activePrinter != null &&activePrinter.canPause
enabled: (!userClicked) && printerConnected && printerAcceptsCommands && activePrintJob != null && enabled: (!userClicked) && printerConnected && printerAcceptsCommands && activePrintJob != null &&
(["paused", "printing"].indexOf(activePrintJob.state) >= 0) (["paused", "printing"].indexOf(activePrintJob.state) >= 0)
@ -305,7 +310,7 @@ Item
{ {
id: abortButton id: abortButton
visible: printerConnected && activePrinter.canAbort visible: printerConnected && activePrinter != null && activePrinter.canAbort
enabled: printerConnected && printerAcceptsCommands && activePrintJob != null && enabled: printerConnected && printerAcceptsCommands && activePrintJob != null &&
(["paused", "printing", "pre_print"].indexOf(activePrintJob.state) >= 0) (["paused", "printing", "pre_print"].indexOf(activePrintJob.state) >= 0)