mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-19 12:47:49 -06:00
Let IntentModel update on a timer
This prevents some double updates
This commit is contained in:
parent
1fae17ecac
commit
7954f6633f
1 changed files with 12 additions and 4 deletions
|
@ -2,7 +2,7 @@
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
from typing import Optional, Dict, Any, Set, List
|
from typing import Optional, Dict, Any, Set, List
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QObject, pyqtProperty, pyqtSignal
|
from PyQt5.QtCore import Qt, QObject, pyqtProperty, pyqtSignal, QTimer
|
||||||
|
|
||||||
import cura.CuraApplication
|
import cura.CuraApplication
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
@ -32,9 +32,14 @@ class IntentModel(ListModel):
|
||||||
|
|
||||||
self._intent_category = "engineering"
|
self._intent_category = "engineering"
|
||||||
|
|
||||||
|
self._update_timer = QTimer()
|
||||||
|
self._update_timer.setInterval(100)
|
||||||
|
self._update_timer.setSingleShot(True)
|
||||||
|
self._update_timer.timeout.connect(self._update)
|
||||||
|
|
||||||
machine_manager = cura.CuraApplication.CuraApplication.getInstance().getMachineManager()
|
machine_manager = cura.CuraApplication.CuraApplication.getInstance().getMachineManager()
|
||||||
machine_manager.globalContainerChanged.connect(self._update)
|
machine_manager.globalContainerChanged.connect(self._updateDelayed)
|
||||||
machine_manager.extruderChanged.connect(self._update) # We also need to update if an extruder gets disabled
|
machine_manager.extruderChanged.connect(self._updateDelayed) # We also need to update if an extruder gets disabled
|
||||||
ContainerRegistry.getInstance().containerAdded.connect(self._onChanged)
|
ContainerRegistry.getInstance().containerAdded.connect(self._onChanged)
|
||||||
ContainerRegistry.getInstance().containerRemoved.connect(self._onChanged)
|
ContainerRegistry.getInstance().containerRemoved.connect(self._onChanged)
|
||||||
self._layer_height_unit = "" # This is cached
|
self._layer_height_unit = "" # This is cached
|
||||||
|
@ -52,9 +57,12 @@ class IntentModel(ListModel):
|
||||||
def intentCategory(self) -> str:
|
def intentCategory(self) -> str:
|
||||||
return self._intent_category
|
return self._intent_category
|
||||||
|
|
||||||
|
def _updateDelayed(self):
|
||||||
|
self._update_timer.start()
|
||||||
|
|
||||||
def _onChanged(self, container):
|
def _onChanged(self, container):
|
||||||
if container.getMetaDataEntry("type") == "intent":
|
if container.getMetaDataEntry("type") == "intent":
|
||||||
self._update()
|
self._updateDelayed()
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
new_items = [] # type: List[Dict[str, Any]]
|
new_items = [] # type: List[Dict[str, Any]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue