mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 01:07:52 -06:00
Turn if-clause into simple input check
Makes the code more readable in my opinion. Contributes to issue CURA-2006.
This commit is contained in:
parent
35fedbdad6
commit
9ba9e90a8f
1 changed files with 41 additions and 13 deletions
|
@ -489,7 +489,10 @@ class MachineManager(QObject):
|
||||||
old_variant = self._active_container_stack.findContainer({"type": "variant"})
|
old_variant = self._active_container_stack.findContainer({"type": "variant"})
|
||||||
old_material = self._active_container_stack.findContainer({"type": "material"})
|
old_material = self._active_container_stack.findContainer({"type": "material"})
|
||||||
old_quality = self._active_container_stack.findContainer({"type": "quality"})
|
old_quality = self._active_container_stack.findContainer({"type": "quality"})
|
||||||
if old_material:
|
if not old_material:
|
||||||
|
Logger.log("w", "While trying to set the active material, no material was found to replace it.")
|
||||||
|
return
|
||||||
|
|
||||||
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
|
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
|
||||||
|
|
||||||
material_index = self._active_container_stack.getContainerIndex(old_material)
|
material_index = self._active_container_stack.getContainerIndex(old_material)
|
||||||
|
@ -502,8 +505,6 @@ class MachineManager(QObject):
|
||||||
preferred_quality_name = old_quality.getName()
|
preferred_quality_name = old_quality.getName()
|
||||||
|
|
||||||
self.setActiveQuality(self._updateQualityContainer(self._global_container_stack.getBottom(), old_variant, containers[0], preferred_quality_name).id)
|
self.setActiveQuality(self._updateQualityContainer(self._global_container_stack.getBottom(), old_variant, containers[0], preferred_quality_name).id)
|
||||||
else:
|
|
||||||
Logger.log("w", "While trying to set the active material, no material was found to replace.")
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setActiveVariant(self, variant_id):
|
def setActiveVariant(self, variant_id):
|
||||||
|
@ -827,6 +828,33 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
return self._empty_quality_container
|
return self._empty_quality_container
|
||||||
|
|
||||||
|
## Finds a quality-changes container to use if any other container
|
||||||
|
# changes.
|
||||||
|
#
|
||||||
|
# \param quality_type The quality type to find a quality-changes for.
|
||||||
|
# \param preferred_quality_changes_name The name of the quality-changes to
|
||||||
|
# pick, if any such quality-changes profile is available.
|
||||||
|
def _updateQualityChangesContainer(self, quality_type, preferred_quality_changes_name = None):
|
||||||
|
container_registry = UM.Settings.ContainerRegistry.getInstance() # Cache.
|
||||||
|
search_criteria = { "type": "quality_changes" }
|
||||||
|
|
||||||
|
search_criteria["quality"] = quality_type
|
||||||
|
if preferred_quality_changes_name:
|
||||||
|
search_criteria["name"] = preferred_quality_changes_name
|
||||||
|
|
||||||
|
# Try to search with the name in the criteria first, since we prefer to have the correct name.
|
||||||
|
containers = container_registry.findInstanceContainers(**search_criteria)
|
||||||
|
if containers: # Found one!
|
||||||
|
return containers[0]
|
||||||
|
|
||||||
|
if "name" in search_criteria:
|
||||||
|
del search_criteria["name"] # Not found, then drop the name requirement (if we had one) and search again.
|
||||||
|
containers = container_registry.findInstanceContainers(**search_criteria)
|
||||||
|
if containers:
|
||||||
|
return containers[0]
|
||||||
|
|
||||||
|
return self._empty_quality_changes_container # Didn't find anything with the required quality_type.
|
||||||
|
|
||||||
def _onMachineNameChanged(self):
|
def _onMachineNameChanged(self):
|
||||||
self.globalContainerChanged.emit()
|
self.globalContainerChanged.emit()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue