From 5da77472e7e3451e8494691799ef2fcee2203938 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 3 Jan 2020 10:17:54 +0100 Subject: [PATCH] Add some timers to sceneChanged --- cura/Scene/CuraSceneController.py | 15 +++++++++++---- cura/UI/PrintInformation.py | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cura/Scene/CuraSceneController.py b/cura/Scene/CuraSceneController.py index 91ff26cadc..36d9e68c8f 100644 --- a/cura/Scene/CuraSceneController.py +++ b/cura/Scene/CuraSceneController.py @@ -1,6 +1,6 @@ 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 UM.Scene.Camera import Camera @@ -26,16 +26,23 @@ class CuraSceneController(QObject): self._last_selected_index = 0 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 updateMaxBuildPlate(self, *args): + def updateMaxBuildPlateDelayed(self, *args): if args: source = args[0] else: source = None + if not isinstance(source, SceneNode) or isinstance(source, Camera): return + self._change_timer.start() + + def updateMaxBuildPlate(self, *args): max_build_plate = self._calcMaxBuildPlate() changed = False if max_build_plate != self._max_build_plate: diff --git a/cura/UI/PrintInformation.py b/cura/UI/PrintInformation.py index e33ab13b69..c39314dc02 100644 --- a/cura/UI/PrintInformation.py +++ b/cura/UI/PrintInformation.py @@ -7,7 +7,7 @@ import os import unicodedata 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.Qt.Duration import Duration @@ -47,7 +47,12 @@ class PrintInformation(QObject): if self._backend: 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._base_name = "" @@ -418,12 +423,14 @@ class PrintInformation(QObject): self._onPrintDurationMessage(build_plate, temp_message, temp_material_amounts) - ## Listen to scene changes to check if we need to reset the print information - def _onSceneChanged(self, scene_node: SceneNode) -> None: + def _onSceneChangedDelayed(self, scene_node: SceneNode) -> None: # Ignore any changes that are not related to sliceable objects - if not isinstance(scene_node, SceneNode)\ - or not scene_node.callDecoration("isSliceable")\ + if not isinstance(scene_node, SceneNode) \ + or not scene_node.callDecoration("isSliceable") \ or not scene_node.callDecoration("getBuildPlateNumber") == self._active_build_plate: 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)