mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 17:27:51 -06:00
Move pre-heat timer into PrinterOutputDevice
If it's held inside the device that has two advantages: It's being held per-device, so switching connection doesn't stop the timer. And also, the logic is no longer in the GUI. Contributes to issue CURA-3161.
This commit is contained in:
parent
2f89a1cff4
commit
75a50b73c2
3 changed files with 28 additions and 22 deletions
|
@ -3,12 +3,11 @@
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from UM.OutputDevice.OutputDevice import OutputDevice
|
from UM.OutputDevice.OutputDevice import OutputDevice
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
from enum import IntEnum # For the connection state tracking.
|
||||||
|
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
from enum import IntEnum # For the connection state tracking.
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Signal import signalemitter
|
from UM.Signal import signalemitter
|
||||||
|
|
||||||
|
@ -49,6 +48,9 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
self._error_text = ""
|
self._error_text = ""
|
||||||
self._accepts_commands = True
|
self._accepts_commands = True
|
||||||
self._preheat_bed_timeout = 900 #Default time-out for pre-heating the bed, in seconds.
|
self._preheat_bed_timeout = 900 #Default time-out for pre-heating the bed, in seconds.
|
||||||
|
self._preheat_bed_timer = QTimer() #Timer that tracks how long to preheat still.
|
||||||
|
self._preheat_bed_timer.setSingleShot(True)
|
||||||
|
self._preheat_bed_timer.timeout.connect(self.cancelPreheatBed)
|
||||||
|
|
||||||
self._printer_state = ""
|
self._printer_state = ""
|
||||||
self._printer_type = "unknown"
|
self._printer_type = "unknown"
|
||||||
|
@ -214,13 +216,26 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
||||||
self._target_bed_temperature = temperature
|
self._target_bed_temperature = temperature
|
||||||
self.targetBedTemperatureChanged.emit()
|
self.targetBedTemperatureChanged.emit()
|
||||||
|
|
||||||
## The duration of the time-out to pre-heat the bed, in seconds.
|
## The total duration of the time-out to pre-heat the bed, in seconds.
|
||||||
#
|
#
|
||||||
# \return The duration of the time-out to pre-heat the bed, in seconds.
|
# \return The duration of the time-out to pre-heat the bed, in seconds.
|
||||||
@pyqtProperty(int)
|
@pyqtProperty(int, constant = True)
|
||||||
def preheatBedTimeout(self):
|
def preheatBedTimeout(self):
|
||||||
return self._preheat_bed_timeout
|
return self._preheat_bed_timeout
|
||||||
|
|
||||||
|
## The remaining duration of the pre-heating of the bed.
|
||||||
|
#
|
||||||
|
# This is formatted in M:SS format.
|
||||||
|
# \return The duration of the time-out to pre-heat the bed, formatted.
|
||||||
|
@pyqtProperty(str)
|
||||||
|
def preheatBedRemainingTime(self):
|
||||||
|
period = self._preheat_bed_timer.remainingTime()
|
||||||
|
if period <= 0:
|
||||||
|
return ""
|
||||||
|
minutes, period = divmod(period, 60000) #60000 milliseconds in a minute.
|
||||||
|
seconds, _ = divmod(period, 1000) #1000 milliseconds in a second.
|
||||||
|
return "%d:%02d" % (minutes, seconds)
|
||||||
|
|
||||||
## Time the print has been printing.
|
## Time the print has been printing.
|
||||||
# Note that timeTotal - timeElapsed should give time remaining.
|
# Note that timeTotal - timeElapsed should give time remaining.
|
||||||
@pyqtProperty(float, notify = timeElapsedChanged)
|
@pyqtProperty(float, notify = timeElapsedChanged)
|
||||||
|
|
|
@ -262,6 +262,7 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
put_request = QNetworkRequest(url)
|
put_request = QNetworkRequest(url)
|
||||||
put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
|
put_request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
|
||||||
self._manager.put(put_request, data.encode())
|
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.
|
||||||
|
|
||||||
## Cancels pre-heating the heated bed of the printer.
|
## Cancels pre-heating the heated bed of the printer.
|
||||||
#
|
#
|
||||||
|
@ -269,6 +270,8 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def cancelPreheatBed(self):
|
def cancelPreheatBed(self):
|
||||||
self.preheatBed(temperature = 0, duration = 0)
|
self.preheatBed(temperature = 0, duration = 0)
|
||||||
|
self._preheat_bed_timer.stop()
|
||||||
|
self._preheat_bed_timer.setInterval(0)
|
||||||
|
|
||||||
## Changes the target bed temperature on the printer.
|
## Changes the target bed temperature on the printer.
|
||||||
#
|
#
|
||||||
|
|
|
@ -288,23 +288,16 @@ Column
|
||||||
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.
|
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.
|
||||||
function update()
|
function update()
|
||||||
{
|
{
|
||||||
var now = new Date();
|
preheatCountdown.text = ""
|
||||||
if (now.getTime() < endTime.getTime())
|
if (connectedPrinter != null)
|
||||||
{
|
{
|
||||||
var remaining = endTime - now; //This is in milliseconds.
|
|
||||||
var minutes = Math.floor(remaining / 60 / 1000);
|
|
||||||
var seconds = Math.floor((remaining / 1000) % 60);
|
|
||||||
preheatCountdown.text = minutes + ":" + (seconds < 10 ? "0" + seconds : seconds);
|
|
||||||
preheatCountdown.visible = true;
|
preheatCountdown.visible = true;
|
||||||
|
preheatCountdown.text = connectedPrinter.preheatBedRemainingTime;
|
||||||
}
|
}
|
||||||
else
|
if (preheatCountdown.text == "") //Either time elapsed or not connected.
|
||||||
{
|
{
|
||||||
preheatCountdown.visible = false;
|
preheatCountdown.visible = false;
|
||||||
running = false;
|
stop();
|
||||||
if (connectedPrinter != null)
|
|
||||||
{
|
|
||||||
connectedPrinter.cancelPreheatBed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,17 +433,12 @@ Column
|
||||||
if (!preheatCountdownTimer.running)
|
if (!preheatCountdownTimer.running)
|
||||||
{
|
{
|
||||||
connectedPrinter.preheatBed(preheatTemperatureInput.text, connectedPrinter.preheatBedTimeout);
|
connectedPrinter.preheatBed(preheatTemperatureInput.text, connectedPrinter.preheatBedTimeout);
|
||||||
var now = new Date();
|
|
||||||
var end_time = new Date();
|
|
||||||
end_time.setTime(now.getTime() + connectedPrinter.preheatBedTimeout * 1000); //*1000 because time is in milliseconds here.
|
|
||||||
preheatCountdownTimer.endTime = end_time;
|
|
||||||
preheatCountdownTimer.start();
|
preheatCountdownTimer.start();
|
||||||
preheatCountdownTimer.update(); //Update once before the first timer is triggered.
|
preheatCountdownTimer.update(); //Update once before the first timer is triggered.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
connectedPrinter.cancelPreheatBed();
|
connectedPrinter.cancelPreheatBed();
|
||||||
preheatCountdownTimer.endTime = new Date();
|
|
||||||
preheatCountdownTimer.update();
|
preheatCountdownTimer.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue