mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-21 13:47:51 -06:00
Replace python timer with QTimer since python timer is unreliable
Python's timer::cancel() method will sometimes not actually cancel the timer. So instead, use a QTimer since those are more reliable.
This commit is contained in:
parent
d85cc0f0bf
commit
e679c0a2b0
1 changed files with 6 additions and 11 deletions
|
@ -14,6 +14,8 @@ import threading
|
||||||
import struct
|
import struct
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QTimer
|
||||||
|
|
||||||
class CuraEngineBackend(Backend):
|
class CuraEngineBackend(Backend):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -27,7 +29,10 @@ class CuraEngineBackend(Backend):
|
||||||
Application.getInstance().activeMachineChanged.connect(self._onActiveMachineChanged)
|
Application.getInstance().activeMachineChanged.connect(self._onActiveMachineChanged)
|
||||||
self._onActiveMachineChanged()
|
self._onActiveMachineChanged()
|
||||||
|
|
||||||
self._changeTimer = None
|
self._changeTimer = QTimer()
|
||||||
|
self._changeTimer.setInterval(500)
|
||||||
|
self._changeTimer.setSingleShot(True)
|
||||||
|
self._changeTimer.timeout.connect(self._onChangeTimerFinished)
|
||||||
|
|
||||||
self._message_handlers[Cura_pb2.SlicedObjectList] = self._onSlicedObjectListMessage
|
self._message_handlers[Cura_pb2.SlicedObjectList] = self._onSlicedObjectListMessage
|
||||||
self._message_handlers[Cura_pb2.Progress] = self._onProgressMessage
|
self._message_handlers[Cura_pb2.Progress] = self._onProgressMessage
|
||||||
|
@ -36,12 +41,9 @@ class CuraEngineBackend(Backend):
|
||||||
|
|
||||||
self._center = None
|
self._center = None
|
||||||
|
|
||||||
self._slice_interval = 0.5
|
|
||||||
|
|
||||||
self._slicing = False
|
self._slicing = False
|
||||||
self._restart = False
|
self._restart = False
|
||||||
|
|
||||||
self.changeTimerFinished.connect(self._onChangeTimerFinished)
|
|
||||||
self.backendConnected.connect(self._onBackendConnected)
|
self.backendConnected.connect(self._onBackendConnected)
|
||||||
|
|
||||||
def getEngineCommand(self):
|
def getEngineCommand(self):
|
||||||
|
@ -97,10 +99,6 @@ class CuraEngineBackend(Backend):
|
||||||
if not self._settings:
|
if not self._settings:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._changeTimer:
|
|
||||||
self._changeTimer.cancel()
|
|
||||||
|
|
||||||
self._changeTimer = threading.Timer(self._slice_interval, lambda: self.changeTimerFinished.emit())
|
|
||||||
self._changeTimer.start()
|
self._changeTimer.start()
|
||||||
|
|
||||||
def _onChangeTimerFinished(self):
|
def _onChangeTimerFinished(self):
|
||||||
|
@ -116,7 +114,6 @@ class CuraEngineBackend(Backend):
|
||||||
objects.append(node)
|
objects.append(node)
|
||||||
|
|
||||||
if not objects:
|
if not objects:
|
||||||
self._changeTimer = None
|
|
||||||
return #No point in slicing an empty build plate
|
return #No point in slicing an empty build plate
|
||||||
|
|
||||||
self._slicing = True
|
self._slicing = True
|
||||||
|
@ -152,8 +149,6 @@ class CuraEngineBackend(Backend):
|
||||||
|
|
||||||
self._socket.sendMessage(msg)
|
self._socket.sendMessage(msg)
|
||||||
|
|
||||||
self._changeTimer = None
|
|
||||||
|
|
||||||
def _sendSettings(self):
|
def _sendSettings(self):
|
||||||
self._sendSettings_neith() if self._settings.getSettingValueByKey('wireframe') else self._sendSettings_normal()
|
self._sendSettings_neith() if self._settings.getSettingValueByKey('wireframe') else self._sendSettings_normal()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue