mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-29 15:25:02 +08:00
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
# Copyright (c) 2018 Ultimaker B.V.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from UM.Application import Application
|
|
from UM.Qt.ListModel import ListModel
|
|
|
|
|
|
class NozzleModel(ListModel):
|
|
IdRole = Qt.UserRole + 1
|
|
HotendNameRole = Qt.UserRole + 2
|
|
ContainerNodeRole = Qt.UserRole + 3
|
|
|
|
def __init__(self, parent = None):
|
|
super().__init__(parent)
|
|
|
|
self.addRoleName(self.IdRole, "id")
|
|
self.addRoleName(self.HotendNameRole, "hotend_name")
|
|
self.addRoleName(self.ContainerNodeRole, "container_node")
|
|
|
|
Application.getInstance().globalContainerStackChanged.connect(self._update)
|
|
Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
|
|
Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
|
|
Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
|
|
|
|
def _update(self):
|
|
self.items.clear()
|
|
|
|
variant_manager = Application.getInstance()._variant_manager
|
|
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
|
if active_global_stack is None:
|
|
self.setItems([])
|
|
return
|
|
|
|
variant_node_dict = variant_manager.getVariantNodes(active_global_stack)
|
|
if not variant_node_dict:
|
|
self.setItems([])
|
|
return
|
|
|
|
item_list = []
|
|
for hotend_name, container_node in sorted(variant_node_dict.items(), key = lambda i: i[0]):
|
|
item = {"id": hotend_name,
|
|
"hotend_name": hotend_name,
|
|
"container_node": container_node
|
|
}
|
|
|
|
item_list.append(item)
|
|
|
|
self.setItems(item_list)
|