Merge branch 'master' into CURA-5536_installed_check

This commit is contained in:
Diego Prado Gesto 2018-07-13 14:43:29 +02:00
commit a8727d7b39
12 changed files with 241 additions and 192 deletions

View file

@ -457,7 +457,8 @@ class CuraEngineBackend(QObject, Backend):
# Only count sliceable objects
if node.callDecoration("isSliceable"):
build_plate_number = node.callDecoration("getBuildPlateNumber")
num_objects[build_plate_number] += 1
if build_plate_number is not None:
num_objects[build_plate_number] += 1
return num_objects
## Listener for when the scene has changed.
@ -490,7 +491,9 @@ class CuraEngineBackend(QObject, Backend):
if mesh_data and mesh_data.getVertices() is None:
return
build_plate_changed.add(source_build_plate_number)
# There are some SceneNodes that do not have any build plate associated, then do not add to the list.
if source_build_plate_number is not None:
build_plate_changed.add(source_build_plate_number)
if not build_plate_changed:
return

View file

@ -88,6 +88,25 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._command_received = Event()
self._command_received.set()
CuraApplication.getInstance().getOnExitCallbackManager().addCallback(self._checkActivePrintingUponAppExit)
# This is a callback function that checks if there is any printing in progress via USB when the application tries
# to exit. If so, it will show a confirmation before
def _checkActivePrintingUponAppExit(self) -> None:
application = CuraApplication.getInstance()
if not self._is_printing:
# This USB printer is not printing, so we have nothing to do. Call the next callback if exists.
application.triggerNextExitCheck()
return
application.setConfirmExitDialogCallback(self._onConfirmExitDialogResult)
application.showConfirmExitDialog.emit(catalog.i18nc("@label", "A USB print is in progress, closing Cura will stop this print. Are you sure?"))
def _onConfirmExitDialogResult(self, result: bool) -> None:
if result:
application = CuraApplication.getInstance()
application.triggerNextExitCheck()
## Reset USB device settings
#
def resetDeviceSettings(self):
@ -435,9 +454,6 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._gcode_position += 1
def getIsPrinting(self)-> bool:
return self._is_printing
class FirmwareUpdateState(IntEnum):
idle = 0

View file

@ -6,8 +6,7 @@ import platform
import time
import serial.tools.list_ports
from PyQt5.QtCore import QObject, pyqtSlot, pyqtSignal, QCoreApplication
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
from UM.Logger import Logger
from UM.Resources import Resources
@ -51,11 +50,6 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin):
self._application.globalContainerStackChanged.connect(self.updateUSBPrinterOutputDevices)
self._application.checkCuraCloseChange.connect(self.checkWheterUSBIsActiveOrNot)
self._lock = threading.Lock()
self._confirm_dialog_visible = False
# The method updates/reset the USB settings for all connected USB devices
def updateUSBPrinterOutputDevices(self):
for key, device in self._usb_output_devices.items():
@ -190,51 +184,3 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin):
@classmethod
def getInstance(cls, *args, **kwargs) -> "USBPrinterOutputDeviceManager":
return cls.__instance
# The method checks whether a printer is printing via USB or not before closing cura. If the printer is printing then pop up a
# dialog to confirm stop printing
def checkWheterUSBIsActiveOrNot(self)-> None:
is_printing = False
for key, device in self._usb_output_devices.items():
if type(device) is USBPrinterOutputDevice.USBPrinterOutputDevice:
if device.getIsPrinting():
is_printing = True
break
if is_printing:
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
self._confirm_dialog_visible = True
CuraApplication.getInstance().messageBox(i18n_catalog.i18nc("@window:title", "Confirm stop printing"),
i18n_catalog.i18nc("@window:message","A USB print is in progress, closing Cura will stop this print. Are you sure?"),
buttons=QMessageBox.Yes + QMessageBox.No,
icon=QMessageBox.Question,
callback=self._messageBoxCallback)
# Wait for dialog result
self.waitForClose()
## Block thread until the dialog is closed.
def waitForClose(self)-> None:
if self._confirm_dialog_visible:
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
self._lock.release()
else:
# If this is not run from a separate thread, we need to ensure that the events are still processed.
while self._confirm_dialog_visible:
time.sleep(1 / 50)
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
def _messageBoxCallback(self, button):
if button == QMessageBox.Yes:
self._application.setCuraCanBeClosed(True)
else:
self._application.setCuraCanBeClosed(False)
self._confirm_dialog_visible = False
try:
self._lock.release()
except:
pass