mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Update MachineListModel to optionally take a list of global stack to show in list instead of searching the container registry.
Add option not to listen to container change events in MachineListModel. CURA-9424
This commit is contained in:
parent
ccb4d181e6
commit
1ebf5bb650
1 changed files with 26 additions and 10 deletions
|
@ -5,7 +5,7 @@
|
||||||
# online cloud connected printers are represented within this ListModel. Additional information such as the number of
|
# online cloud connected printers are represented within this ListModel. Additional information such as the number of
|
||||||
# connected printers for each printer type is gathered.
|
# connected printers for each printer type is gathered.
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional, List
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ from UM.Settings.ContainerStack import ContainerStack
|
||||||
from UM.Settings.Interfaces import ContainerInterface
|
from UM.Settings.Interfaces import ContainerInterface
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
|
|
||||||
|
|
||||||
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
|
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
|
||||||
from cura.Settings.GlobalStack import GlobalStack
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
@ -30,10 +29,11 @@ class MachineListModel(ListModel):
|
||||||
IsAbstractMachineRole = Qt.ItemDataRole.UserRole + 7
|
IsAbstractMachineRole = Qt.ItemDataRole.UserRole + 7
|
||||||
ComponentTypeRole = Qt.ItemDataRole.UserRole + 8
|
ComponentTypeRole = Qt.ItemDataRole.UserRole + 8
|
||||||
|
|
||||||
def __init__(self, parent: Optional[QObject] = None) -> None:
|
def __init__(self, parent: Optional[QObject] = None, machines: List[GlobalStack] = None, listenToChanges: bool = True) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._show_cloud_printers = False
|
self._show_cloud_printers = False
|
||||||
|
self._machines = machines
|
||||||
|
|
||||||
self._catalog = i18nCatalog("cura")
|
self._catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class MachineListModel(ListModel):
|
||||||
self._change_timer.setSingleShot(True)
|
self._change_timer.setSingleShot(True)
|
||||||
self._change_timer.timeout.connect(self._update)
|
self._change_timer.timeout.connect(self._update)
|
||||||
|
|
||||||
# Listen to changes
|
if listenToChanges:
|
||||||
CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged)
|
CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerChanged)
|
||||||
CuraContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerChanged)
|
CuraContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerChanged)
|
||||||
CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
|
CuraContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChanged)
|
||||||
|
@ -79,16 +79,32 @@ class MachineListModel(ListModel):
|
||||||
def _updateDelayed(self) -> None:
|
def _updateDelayed(self) -> None:
|
||||||
self._change_timer.start()
|
self._change_timer.start()
|
||||||
|
|
||||||
|
def _getMachineStacks(self) -> List[ContainerStack]:
|
||||||
|
if self._machines is not None:
|
||||||
|
return self._machines
|
||||||
|
return CuraContainerRegistry.getInstance().findContainerStacks(type="machine")
|
||||||
|
|
||||||
|
def _getAbstractMachineStacks(self) -> List[ContainerStack]:
|
||||||
|
if self._machines is not None:
|
||||||
|
return list(filter(lambda machine: parseBool(machine.getMetaDataEntry("is_abstract_machine", False)), self._machines))
|
||||||
|
return CuraContainerRegistry.getInstance().findContainerStacks(is_abstract_machine = "True")
|
||||||
|
|
||||||
|
def update(self, machines: List[ContainerStack] = None) -> None:
|
||||||
|
if machines is not None:
|
||||||
|
self._machines = machines
|
||||||
|
|
||||||
|
self._update()
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
machines_manager = CuraApplication.getInstance().getMachineManager()
|
machines_manager = CuraApplication.getInstance().getMachineManager()
|
||||||
|
|
||||||
other_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="machine")
|
other_machine_stacks = self._getMachineStacks()
|
||||||
other_machine_stacks.sort(key = lambda machine: machine.getName().upper())
|
other_machine_stacks.sort(key = lambda machine: machine.getName().upper())
|
||||||
|
|
||||||
abstract_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(is_abstract_machine = "True")
|
abstract_machine_stacks = self._getAbstractMachineStacks()
|
||||||
abstract_machine_stacks.sort(key = lambda machine: machine.getName().upper(), reverse = True)
|
abstract_machine_stacks.sort(key = lambda machine: machine.getName().upper(), reverse = True)
|
||||||
for abstract_machine in abstract_machine_stacks:
|
for abstract_machine in abstract_machine_stacks:
|
||||||
definition_id = abstract_machine.definition.getId()
|
definition_id = abstract_machine.definition.getId()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue