Add some timers to sceneChanged

This commit is contained in:
Jaime van Kessel 2020-01-03 10:17:54 +01:00
parent c261065d68
commit 5da77472e7
No known key found for this signature in database
GPG key ID: 3710727397403C91
2 changed files with 24 additions and 10 deletions

View file

@ -1,6 +1,6 @@
from UM.Logger import Logger from UM.Logger import Logger
from PyQt5.QtCore import Qt, pyqtSlot, QObject from PyQt5.QtCore import Qt, pyqtSlot, QObject, QTimer
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from UM.Scene.Camera import Camera from UM.Scene.Camera import Camera
@ -26,16 +26,23 @@ class CuraSceneController(QObject):
self._last_selected_index = 0 self._last_selected_index = 0
self._max_build_plate = 1 # default self._max_build_plate = 1 # default
self._change_timer = QTimer()
self._change_timer.setInterval(100)
self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self.updateMaxBuildPlate)
Application.getInstance().getController().getScene().sceneChanged.connect(self.updateMaxBuildPlateDelayed)
Application.getInstance().getController().getScene().sceneChanged.connect(self.updateMaxBuildPlate) # it may be a bit inefficient when changing a lot simultaneously def updateMaxBuildPlateDelayed(self, *args):
def updateMaxBuildPlate(self, *args):
if args: if args:
source = args[0] source = args[0]
else: else:
source = None source = None
if not isinstance(source, SceneNode) or isinstance(source, Camera): if not isinstance(source, SceneNode) or isinstance(source, Camera):
return return
self._change_timer.start()
def updateMaxBuildPlate(self, *args):
max_build_plate = self._calcMaxBuildPlate() max_build_plate = self._calcMaxBuildPlate()
changed = False changed = False
if max_build_plate != self._max_build_plate: if max_build_plate != self._max_build_plate:

View file

@ -7,7 +7,7 @@ import os
import unicodedata import unicodedata
from typing import Dict, List, Optional, TYPE_CHECKING from typing import Dict, List, Optional, TYPE_CHECKING
from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot, QTimer
from UM.Logger import Logger from UM.Logger import Logger
from UM.Qt.Duration import Duration from UM.Qt.Duration import Duration
@ -47,7 +47,12 @@ class PrintInformation(QObject):
if self._backend: if self._backend:
self._backend.printDurationMessage.connect(self._onPrintDurationMessage) self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
self._application.getController().getScene().sceneChanged.connect(self._onSceneChanged) self._application.getController().getScene().sceneChanged.connect(self._onSceneChangedDelayed)
self._change_timer = QTimer()
self._change_timer.setInterval(100)
self._change_timer.setSingleShot(True)
self._change_timer.timeout.connect(self._onSceneChanged)
self._is_user_specified_job_name = False self._is_user_specified_job_name = False
self._base_name = "" self._base_name = ""
@ -418,12 +423,14 @@ class PrintInformation(QObject):
self._onPrintDurationMessage(build_plate, temp_message, temp_material_amounts) self._onPrintDurationMessage(build_plate, temp_message, temp_material_amounts)
## Listen to scene changes to check if we need to reset the print information def _onSceneChangedDelayed(self, scene_node: SceneNode) -> None:
def _onSceneChanged(self, scene_node: SceneNode) -> None:
# Ignore any changes that are not related to sliceable objects # Ignore any changes that are not related to sliceable objects
if not isinstance(scene_node, SceneNode)\ if not isinstance(scene_node, SceneNode) \
or not scene_node.callDecoration("isSliceable")\ or not scene_node.callDecoration("isSliceable") \
or not scene_node.callDecoration("getBuildPlateNumber") == self._active_build_plate: or not scene_node.callDecoration("getBuildPlateNumber") == self._active_build_plate:
return return
self._change_timer.start()
## Listen to scene changes to check if we need to reset the print information
def _onSceneChanged(self) -> None:
self.setToZeroPrintInformation(self._active_build_plate) self.setToZeroPrintInformation(self._active_build_plate)