mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-10-10 15:27:53 -06:00
Use the global stack instance variable and account for it potentially being None
This commit is contained in:
parent
2e0205f174
commit
b1f887a70f
1 changed files with 76 additions and 41 deletions
|
@ -110,78 +110,111 @@ class MachineManagerModel(QObject):
|
||||||
|
|
||||||
@pyqtProperty(str, notify = globalContainerChanged)
|
@pyqtProperty(str, notify = globalContainerChanged)
|
||||||
def activeMachineName(self):
|
def activeMachineName(self):
|
||||||
return Application.getInstance().getGlobalContainerStack().getName()
|
if self._global_container_stack:
|
||||||
|
return self._global_container_stack.getName()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = globalContainerChanged)
|
@pyqtProperty(str, notify = globalContainerChanged)
|
||||||
def activeMachineId(self):
|
def activeMachineId(self):
|
||||||
return Application.getInstance().getGlobalContainerStack().getId()
|
if self._global_container_stack:
|
||||||
|
return self._global_container_stack.getId()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeMaterialChanged)
|
@pyqtProperty(str, notify = activeMaterialChanged)
|
||||||
def activeMaterialName(self):
|
def activeMaterialName(self):
|
||||||
material = Application.getInstance().getGlobalContainerStack().findContainer({"type":"material"})
|
if self._global_container_stack:
|
||||||
if material:
|
material = self._global_container_stack.findContainer({"type":"material"})
|
||||||
return material.getName()
|
if material:
|
||||||
|
return material.getName()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify=activeMaterialChanged)
|
@pyqtProperty(str, notify=activeMaterialChanged)
|
||||||
def activeMaterialId(self):
|
def activeMaterialId(self):
|
||||||
material = Application.getInstance().getGlobalContainerStack().findContainer({"type": "material"})
|
if self._global_container_stack:
|
||||||
if material:
|
material = self._global_container_stack.findContainer({"type": "material"})
|
||||||
return material.getId()
|
if material:
|
||||||
|
return material.getId()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify=activeQualityChanged)
|
@pyqtProperty(str, notify=activeQualityChanged)
|
||||||
def activeQualityName(self):
|
def activeQualityName(self):
|
||||||
quality = Application.getInstance().getGlobalContainerStack().findContainer({"type": "quality"})
|
if self._global_container_stack:
|
||||||
if quality:
|
quality = self._global_container_stack.findContainer({"type": "quality"})
|
||||||
return quality.getName()
|
if quality:
|
||||||
|
return quality.getName()
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify=activeQualityChanged)
|
@pyqtProperty(str, notify=activeQualityChanged)
|
||||||
def activeQualityId(self):
|
def activeQualityId(self):
|
||||||
quality = Application.getInstance().getGlobalContainerStack().findContainer({"type": "quality"})
|
if self._global_container_stack:
|
||||||
if quality:
|
quality = self._global_container_stack.findContainer({"type": "quality"})
|
||||||
return quality.getId()
|
if quality:
|
||||||
|
return quality.getId()
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveMaterial(self, material_id):
|
def setActiveMaterial(self, material_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=material_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=material_id)
|
||||||
old_material = Application.getInstance().getGlobalContainerStack().findContainer({"type":"material"})
|
if not containers or not self._global_container_stack:
|
||||||
|
return
|
||||||
|
|
||||||
|
old_material = self._global_container_stack.findContainer({"type":"material"})
|
||||||
if old_material:
|
if old_material:
|
||||||
material_index = Application.getInstance().getGlobalContainerStack().getContainerIndex(old_material)
|
material_index = self._global_container_stack.getContainerIndex(old_material)
|
||||||
Application.getInstance().getGlobalContainerStack().replaceContainer(material_index, containers[0])
|
self._global_container_stack.replaceContainer(material_index, containers[0])
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveVariant(self, variant_id):
|
def setActiveVariant(self, variant_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=variant_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id=variant_id)
|
||||||
old_variant = Application.getInstance().getGlobalContainerStack().findContainer({"type": "variant"})
|
if not containers or not self._global_container_stack:
|
||||||
|
return
|
||||||
|
|
||||||
|
old_variant = self._global_container_stack.findContainer({"type": "variant"})
|
||||||
if old_variant:
|
if old_variant:
|
||||||
variant_index = Application.getInstance().getGlobalContainerStack().getContainerIndex(old_variant)
|
variant_index = self._global_container_stack.getContainerIndex(old_variant)
|
||||||
Application.getInstance().getGlobalContainerStack().replaceContainer(variant_index, containers[0])
|
self._global_container_stack.replaceContainer(variant_index, containers[0])
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveQuality(self, quality_id):
|
def setActiveQuality(self, quality_id):
|
||||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = quality_id)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = quality_id)
|
||||||
old_quality = Application.getInstance().getGlobalContainerStack().findContainer({"type": "quality"})
|
if not containers or not self._global_container_stack:
|
||||||
|
return
|
||||||
|
|
||||||
|
old_quality = self._global_container_stack.findContainer({"type": "quality"})
|
||||||
if old_quality:
|
if old_quality:
|
||||||
quality_index = Application.getInstance().getGlobalContainerStack().getContainerIndex(old_quality)
|
quality_index = self._global_container_stack.getContainerIndex(old_quality)
|
||||||
Application.getInstance().getGlobalContainerStack().replaceContainer(quality_index, containers[0])
|
self._global_container_stack.replaceContainer(quality_index, containers[0])
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeVariantChanged)
|
@pyqtProperty(str, notify = activeVariantChanged)
|
||||||
def activeVariantName(self):
|
def activeVariantName(self):
|
||||||
variant = Application.getInstance().getGlobalContainerStack().findContainer({"type": "variant"})
|
if self._global_container_stack:
|
||||||
if variant:
|
variant = self._global_container_stack.findContainer({"type": "variant"})
|
||||||
return variant.getName()
|
if variant:
|
||||||
|
return variant.getName()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeVariantChanged)
|
@pyqtProperty(str, notify = activeVariantChanged)
|
||||||
def activeVariantId(self):
|
def activeVariantId(self):
|
||||||
variant = Application.getInstance().getGlobalContainerStack().findContainer({"type": "variant"})
|
if self._global_container_stack:
|
||||||
if variant:
|
variant = self._global_container_stack.findContainer({"type": "variant"})
|
||||||
return variant.getId()
|
if variant:
|
||||||
|
return variant.getId()
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtProperty(str, notify = globalContainerChanged)
|
@pyqtProperty(str, notify = globalContainerChanged)
|
||||||
def activeDefinitionId(self):
|
def activeDefinitionId(self):
|
||||||
definition = Application.getInstance().getGlobalContainerStack().getBottom()
|
if self._global_container_stack:
|
||||||
if definition:
|
definition = self._global_container_stack.getBottom()
|
||||||
return definition.id
|
if definition:
|
||||||
return None
|
return definition.id
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def renameMachine(self, machine_id, new_name):
|
def renameMachine(self, machine_id, new_name):
|
||||||
|
@ -193,17 +226,19 @@ class MachineManagerModel(QObject):
|
||||||
def removeMachine(self, machine_id):
|
def removeMachine(self, machine_id):
|
||||||
UM.Settings.ContainerRegistry.getInstance().removeContainer(machine_id)
|
UM.Settings.ContainerRegistry.getInstance().removeContainer(machine_id)
|
||||||
|
|
||||||
@pyqtProperty(bool)
|
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||||
def hasMaterials(self):
|
def hasMaterials(self):
|
||||||
# Todo: Still hardcoded.
|
if self._global_container_stack:
|
||||||
# We should implement this properly when it's clear how a machine notifies us if it can handle materials
|
return self._global_container_stack.getMetaDataEntry("has_materials", False)
|
||||||
return True
|
|
||||||
|
|
||||||
@pyqtProperty(bool)
|
return False
|
||||||
|
|
||||||
|
@pyqtProperty(bool, notify = globalContainerChanged)
|
||||||
def hasVariants(self):
|
def hasVariants(self):
|
||||||
# Todo: Still hardcoded.
|
if self._global_container_stack:
|
||||||
# We should implement this properly when it's clear how a machine notifies us if it can handle variants
|
return self._global_container_stack.getMetaDataEntry("has_variants", False)
|
||||||
return True
|
|
||||||
|
return False
|
||||||
|
|
||||||
def createMachineManagerModel(engine, script_engine):
|
def createMachineManagerModel(engine, script_engine):
|
||||||
return MachineManagerModel()
|
return MachineManagerModel()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue