NozzleModel.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from PyQt5.QtCore import Qt
  2. from UM.Application import Application
  3. from UM.Qt.ListModel import ListModel
  4. class NozzleModel(ListModel):
  5. IdRole = Qt.UserRole + 1
  6. HotendNameRole = Qt.UserRole + 2
  7. ContainerNodeRole = Qt.UserRole + 3
  8. def __init__(self, parent = None):
  9. super().__init__(parent)
  10. self.addRoleName(self.IdRole, "id")
  11. self.addRoleName(self.HotendNameRole, "hotend_name")
  12. self.addRoleName(self.ContainerNodeRole, "container_node")
  13. Application.getInstance().globalContainerStackChanged.connect(self._update)
  14. Application.getInstance().getMachineManager().activeVariantChanged.connect(self._update)
  15. Application.getInstance().getMachineManager().activeStackChanged.connect(self._update)
  16. Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._update)
  17. def _update(self):
  18. self.items.clear()
  19. variant_manager = Application.getInstance()._variant_manager
  20. active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
  21. if active_global_stack is None:
  22. self.setItems([])
  23. return
  24. variant_group_dict = variant_manager.getVariantNodes(active_global_stack)
  25. if not variant_group_dict:
  26. self.setItems([])
  27. return
  28. item_list = []
  29. for hotend_name, container_node in sorted(variant_group_dict.items(), key = lambda i: i[0]):
  30. item = {"id": hotend_name,
  31. "hotend_name": hotend_name,
  32. "container_node": container_node
  33. }
  34. item_list.append(item)
  35. self.setItems(item_list)