diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index cf07b98ca1..6be3827e5e 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import os @@ -367,11 +367,18 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._sendCommand("M84") def _sendNextGcodeLine(self): - if self._gcode_position >= len(self._gcode): + """ + Send the next line of g-code, at the current `_gcode_position`, via a + serial port to the printer. + + If the print is done, this sets `_is_printing` to `False` as well. + """ + try: + line = self._gcode[self._gcode_position] + except IndexError: # End of print, or print got cancelled. self._printers[0].updateActivePrintJob(None) self._is_printing = False return - line = self._gcode[self._gcode_position] if ";" in line: line = line[:line.find(";")] @@ -401,7 +408,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): if print_job is None: controller = GenericOutputController(self) controller.setCanUpdateFirmware(True) - print_job = PrintJobOutputModel(output_controller=controller, name=CuraApplication.getInstance().getPrintInformation().jobName) + print_job = PrintJobOutputModel(output_controller = controller, name = CuraApplication.getInstance().getPrintInformation().jobName) print_job.updateState("printing") self._printers[0].updateActivePrintJob(print_job)