Sending prints to a specific printer in the cluster is now possible again

CL-541
This commit is contained in:
Jaime van Kessel 2018-01-04 14:56:42 +01:00
parent 8a7105dd9c
commit c9b8b0333c
2 changed files with 46 additions and 22 deletions

View file

@ -62,11 +62,15 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._active_printer = None # type: Optional[PrinterOutputModel] self._active_printer = None # type: Optional[PrinterOutputModel]
self._printer_selection_dialog = None
self.setPriority(3) # Make sure the output device gets selected above local file output self.setPriority(3) # Make sure the output device gets selected above local file output
self.setName(self._id) self.setName(self._id)
self.setShortDescription(i18n_catalog.i18nc("@action:button Preceded by 'Ready to'.", "Print over network")) self.setShortDescription(i18n_catalog.i18nc("@action:button Preceded by 'Ready to'.", "Print over network"))
self.setDescription(i18n_catalog.i18nc("@properties:tooltip", "Print over network")) self.setDescription(i18n_catalog.i18nc("@properties:tooltip", "Print over network"))
self._printer_uuid_to_unique_name_mapping = {}
self._finished_jobs = [] self._finished_jobs = []
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):
@ -79,11 +83,21 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
# Unable to find g-code. Nothing to send # Unable to find g-code. Nothing to send
return return
# TODO; DEBUG if len(self._printers) > 1:
self.sendPrintJob() self._spawnPrinterSelectionDialog()
else:
self.sendPrintJob()
def _spawnPrinterSelectionDialog(self):
if self._printer_selection_dialog is None:
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "PrintWindow.qml")
self._printer_selection_dialog = Application.getInstance().createQmlComponent(path, {"OutputDevice": self})
if self._printer_selection_dialog is not None:
self._printer_selection_dialog.show()
@pyqtSlot() @pyqtSlot()
def sendPrintJob(self): @pyqtSlot(str)
def sendPrintJob(self, target_printer = ""):
Logger.log("i", "Sending print job to printer.") Logger.log("i", "Sending print job to printer.")
if self._sending_gcode: if self._sending_gcode:
self._error_message = Message( self._error_message = Message(
@ -108,9 +122,9 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
parts = [] parts = []
# If a specific printer was selected, it should be printed with that machine. # If a specific printer was selected, it should be printed with that machine.
require_printer_name = "" # Todo; actually needs to be set if target_printer:
if require_printer_name: target_printer = self._printer_uuid_to_unique_name_mapping[target_printer]
parts.append(self._createFormPart("name=require_printer_name", bytes(require_printer_name, "utf-8"), "text/plain")) parts.append(self._createFormPart("name=require_printer_name", bytes(target_printer, "utf-8"), "text/plain"))
# Add user name to the print_job # Add user name to the print_job
parts.append(self._createFormPart("name=owner", bytes(self._getUserName(), "utf-8"), "text/plain")) parts.append(self._createFormPart("name=owner", bytes(self._getUserName(), "utf-8"), "text/plain"))
@ -324,6 +338,10 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
print_job.updateOwner(data["owner"]) print_job.updateOwner(data["owner"])
def _updatePrinter(self, printer, data): def _updatePrinter(self, printer, data):
# For some unknown reason the cluster wants UUID for everything, except for sending a job directly to a printer.
# Then we suddenly need the unique name. So in order to not have to mess up all the other code, we save a mapping.
self._printer_uuid_to_unique_name_mapping[data["uuid"]] = data["unique_name"]
printer.updateName(data["friendly_name"]) printer.updateName(data["friendly_name"])
printer.updateKey(data["uuid"]) printer.updateKey(data["uuid"])
printer.updateType(data["machine_variant"]) printer.updateType(data["machine_variant"])

View file

@ -20,8 +20,24 @@ UM.Dialog
visible: true visible: true
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
onVisibleChanged:
{
if(visible)
{
resetPrintersModel()
}
}
title: catalog.i18nc("@title:window", "Print over network")
title: catalog.i18nc("@title:window","Print over network") property var printersModel: ListModel{}
function resetPrintersModel() {
printersModel.append({ name: "Automatic", key: ""})
for (var index in OutputDevice.printers)
{
printersModel.append({name: OutputDevice.printers[index].name, key: OutputDevice.printers[index].key})
}
}
Column Column
{ {
@ -31,8 +47,7 @@ UM.Dialog
anchors.topMargin: UM.Theme.getSize("default_margin").height anchors.topMargin: UM.Theme.getSize("default_margin").height
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
anchors.rightMargin: UM.Theme.getSize("default_margin").width anchors.rightMargin: UM.Theme.getSize("default_margin").width
height: 50 * screenScaleFactor height: 50 * screenScaleFactord
Label Label
{ {
id: manualPrinterSelectionLabel id: manualPrinterSelectionLabel
@ -42,7 +57,7 @@ UM.Dialog
topMargin: UM.Theme.getSize("default_margin").height topMargin: UM.Theme.getSize("default_margin").height
right: parent.right right: parent.right
} }
text: "Printer selection" text: catalog.i18nc("@label", "Printer selection")
wrapMode: Text.Wrap wrapMode: Text.Wrap
height: 20 * screenScaleFactor height: 20 * screenScaleFactor
} }
@ -50,18 +65,12 @@ UM.Dialog
ComboBox ComboBox
{ {
id: printerSelectionCombobox id: printerSelectionCombobox
model: OutputDevice.printers model: base.printersModel
textRole: "friendly_name" textRole: "name"
width: parent.width width: parent.width
height: 40 * screenScaleFactor height: 40 * screenScaleFactor
Behavior on height { NumberAnimation { duration: 100 } } Behavior on height { NumberAnimation { duration: 100 } }
onActivated:
{
var printerData = OutputDevice.printers[index];
OutputDevice.selectPrinter(printerData.unique_name, printerData.friendly_name);
}
} }
SystemPalette SystemPalette
@ -79,8 +88,6 @@ UM.Dialog
enabled: true enabled: true
onClicked: { onClicked: {
base.visible = false; base.visible = false;
// reset to defaults
OutputDevice.selectAutomaticPrinter()
printerSelectionCombobox.currentIndex = 0 printerSelectionCombobox.currentIndex = 0
} }
} }
@ -93,9 +100,8 @@ UM.Dialog
enabled: true enabled: true
onClicked: { onClicked: {
base.visible = false; base.visible = false;
OutputDevice.sendPrintJob(); OutputDevice.sendPrintJob(printerSelectionCombobox.model.get(printerSelectionCombobox.currentIndex).key)
// reset to defaults // reset to defaults
OutputDevice.selectAutomaticPrinter()
printerSelectionCombobox.currentIndex = 0 printerSelectionCombobox.currentIndex = 0
} }
} }