Notify to update remaining time when it drastically changes

When the time passes normally it doesn't trigger this signal but just go on counting, but when the pre-heat starts or cancels it updates via this signal. This is handy for the future, when we want to update the remaining time from the printer information. However for now it is also nice because we can make the pre-heat timer dependent on this signal so we know when to have it running. This fixes the problem that the pre-heat seems to have been cancelled in the GUI when you switch away the tab, because the timer running is now dependent on the property rather than always false.

Contributes to issue CURA-3161.
This commit is contained in:
Ghostkeeper 2017-02-16 11:44:21 +01:00
parent 9a5b355f2b
commit d2fa6dbae2
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75
4 changed files with 11 additions and 4 deletions

View file

@ -108,6 +108,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
printerTypeChanged = pyqtSignal()
# Signal to be emitted when some drastic change occurs in the remaining time (not when the time just passes on normally).
preheatBedRemainingTimeChanged = pyqtSignal()
@pyqtProperty(str, notify=printerTypeChanged)
def printerType(self):
return self._printer_type
@ -227,7 +230,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
#
# This is formatted in M:SS format.
# \return The duration of the time-out to pre-heat the bed, formatted.
@pyqtProperty(str)
@pyqtProperty(str, notify = preheatBedRemainingTimeChanged)
def preheatBedRemainingTime(self):
period = self._preheat_bed_timer.remainingTime()
if period <= 0:

View file

@ -264,6 +264,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
self._manager.put(put_request, data.encode())
self._preheat_bed_timer.start(self._preheat_bed_timeout * 1000) #Times 1000 because it needs to be provided as milliseconds.
self.preheatBedRemainingTimeChanged.emit()
## Cancels pre-heating the heated bed of the printer.
#
@ -274,6 +275,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
self.preheatBed(temperature = 0, duration = 0)
self._preheat_bed_timer.stop()
self._preheat_bed_timer.setInterval(0)
self.preheatBedRemainingTimeChanged.emit()
## Changes the target bed temperature on the printer.
#

View file

@ -652,6 +652,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
def preheatBed(self, temperature, duration):
Logger.log("i", "Pre-heating the bed to %i degrees.", temperature)
self._setTargetBedTemperature(temperature)
self.preheatBedRemainingTimeChanged.emit()
## Cancels pre-heating the heated bed of the printer.
#
@ -660,3 +661,4 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
def cancelPreheatBed(self):
Logger.log("i", "Cancelling pre-heating of the bed.")
self._setTargetBedTemperature(0)
self.preheatBedRemainingTimeChanged.emit()

View file

@ -282,7 +282,7 @@ Column
{
id: preheatUpdateTimer
interval: 100 //Update every 100ms. You want to update every 1s, but then you have one timer for the updating running out of sync with the actual date timer and you might skip seconds.
running: false
running: connectedPrinter.preheatBedRemainingTime != ""
repeat: true
onTriggered: update()
property var endTime: new Date() //Set initial endTime to be the current date, so that the endTime has initially already passed and the timer text becomes invisible if you were to update.
@ -302,7 +302,7 @@ Column
Label
{
id: preheatCountdown
text: ""
text: connectedPrinter != null ? connectedPrinter.preheatBedRemainingTime : ""
visible: text != "" //Has no direct effect, but just so that we can link visibility of clock icon to visibility of the countdown text.
font: UM.Theme.getFont("default")
color: UM.Theme.getColor("text")