mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
Code style
This commit is contained in:
parent
0966ef5338
commit
933ee408e4
1 changed files with 37 additions and 36 deletions
|
|
@ -26,6 +26,7 @@ class MachineSettingsAction(MachineAction):
|
||||||
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
||||||
self._qml_url = "MachineSettingsAction.qml"
|
self._qml_url = "MachineSettingsAction.qml"
|
||||||
|
|
||||||
|
self._global_container_stack = None
|
||||||
self._container_index = 0
|
self._container_index = 0
|
||||||
self._extruder_container_index = 0
|
self._extruder_container_index = 0
|
||||||
|
|
||||||
|
|
@ -37,17 +38,16 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._backend = Application.getInstance().getBackend()
|
self._backend = Application.getInstance().getBackend()
|
||||||
|
|
||||||
def _reset(self):
|
def _reset(self):
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
if not self._global_container_stack:
|
||||||
if not global_container_stack:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Make sure there is a definition_changes container to store the machine settings
|
# Make sure there is a definition_changes container to store the machine settings
|
||||||
definition_changes_container = global_container_stack.findContainer({"type": "definition_changes"})
|
definition_changes_container = self._global_container_stack.findContainer({"type": "definition_changes"})
|
||||||
if not definition_changes_container:
|
if not definition_changes_container:
|
||||||
definition_changes_container = self._createDefinitionChangesContainer(global_container_stack, global_container_stack.getName() + "_settings")
|
definition_changes_container = self._createDefinitionChangesContainer(self._global_container_stack, self._global_container_stack.getName() + "_settings")
|
||||||
|
|
||||||
# Notify the UI in which container to store the machine settings data
|
# Notify the UI in which container to store the machine settings data
|
||||||
container_index = global_container_stack.getContainerIndex(definition_changes_container)
|
container_index = self._global_container_stack.getContainerIndex(definition_changes_container)
|
||||||
if container_index != self._container_index:
|
if container_index != self._container_index:
|
||||||
self._container_index = container_index
|
self._container_index = container_index
|
||||||
self.containerIndexChanged.emit()
|
self.containerIndexChanged.emit()
|
||||||
|
|
@ -62,9 +62,8 @@ class MachineSettingsAction(MachineAction):
|
||||||
self._backend.tickle()
|
self._backend.tickle()
|
||||||
|
|
||||||
def _onActiveExtruderStackChanged(self):
|
def _onActiveExtruderStackChanged(self):
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
|
||||||
extruder_container_stack = ExtruderManager.getInstance().getActiveExtruderStack()
|
extruder_container_stack = ExtruderManager.getInstance().getActiveExtruderStack()
|
||||||
if not global_container_stack or not extruder_container_stack:
|
if not self._global_container_stack or not extruder_container_stack:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Make sure there is a definition_changes container to store the machine settings
|
# Make sure there is a definition_changes container to store the machine settings
|
||||||
|
|
@ -109,18 +108,19 @@ class MachineSettingsAction(MachineAction):
|
||||||
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey())
|
||||||
|
|
||||||
def _onGlobalContainerChanged(self):
|
def _onGlobalContainerChanged(self):
|
||||||
# This stub is needed because we cannot connect a UM.Signal directly to a pyqtSignal
|
self._global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
|
# This additional emit is needed because we cannot connect a UM.Signal directly to a pyqtSignal
|
||||||
self.globalContainerChanged.emit()
|
self.globalContainerChanged.emit()
|
||||||
|
|
||||||
globalContainerChanged = pyqtSignal()
|
globalContainerChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty(int, notify = globalContainerChanged)
|
@pyqtProperty(int, notify = globalContainerChanged)
|
||||||
def definedExtruderCount(self):
|
def definedExtruderCount(self):
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
if not self._global_container_stack:
|
||||||
if not global_container_stack:
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return len(global_container_stack.getMetaDataEntry("machine_extruder_trains"))
|
return len(self._global_container_stack.getMetaDataEntry("machine_extruder_trains"))
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def forceUpdate(self):
|
def forceUpdate(self):
|
||||||
|
|
@ -131,34 +131,35 @@ class MachineSettingsAction(MachineAction):
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def updateHasMaterialsMetadata(self):
|
def updateHasMaterialsMetadata(self):
|
||||||
# Updates the has_materials metadata flag after switching gcode flavor
|
# Updates the has_materials metadata flag after switching gcode flavor
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
if not self._global_container_stack:
|
||||||
if global_container_stack:
|
return
|
||||||
definition = global_container_stack.getBottom()
|
|
||||||
if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False):
|
|
||||||
has_materials = global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
|
|
||||||
|
|
||||||
material_container = global_container_stack.findContainer({"type": "material"})
|
definition = self._global_container_stack.getBottom()
|
||||||
material_index = global_container_stack.getContainerIndex(material_container)
|
if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False):
|
||||||
|
has_materials = self._global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
|
||||||
|
|
||||||
if has_materials:
|
material_container = self._global_container_stack.findContainer({"type": "material"})
|
||||||
if "has_materials" in global_container_stack.getMetaData():
|
material_index = self._global_container_stack.getContainerIndex(material_container)
|
||||||
global_container_stack.setMetaDataEntry("has_materials", True)
|
|
||||||
else:
|
|
||||||
global_container_stack.addMetaDataEntry("has_materials", True)
|
|
||||||
|
|
||||||
# Set the material container to a sane default
|
if has_materials:
|
||||||
if material_container.getId() == "empty_material":
|
if "has_materials" in self._global_container_stack.getMetaData():
|
||||||
search_criteria = { "type": "material", "definition": "fdmprinter", "id": "*pla*" }
|
self._global_container_stack.setMetaDataEntry("has_materials", True)
|
||||||
containers = self._container_registry.findInstanceContainers(**search_criteria)
|
|
||||||
if containers:
|
|
||||||
global_container_stack.replaceContainer(material_index, containers[0])
|
|
||||||
else:
|
else:
|
||||||
# The metadata entry is stored in an ini, and ini files are parsed as strings only.
|
self._global_container_stack.addMetaDataEntry("has_materials", True)
|
||||||
# Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
|
|
||||||
if "has_materials" in global_container_stack.getMetaData():
|
|
||||||
global_container_stack.removeMetaDataEntry("has_materials")
|
|
||||||
|
|
||||||
empty_material = self._container_registry.findInstanceContainers(id = "empty_material")[0]
|
# Set the material container to a sane default
|
||||||
global_container_stack.replaceContainer(material_index, empty_material)
|
if material_container.getId() == "empty_material":
|
||||||
|
search_criteria = { "type": "material", "definition": "fdmprinter", "id": "*pla*" }
|
||||||
|
containers = self._container_registry.findInstanceContainers(**search_criteria)
|
||||||
|
if containers:
|
||||||
|
self._global_container_stack.replaceContainer(material_index, containers[0])
|
||||||
|
else:
|
||||||
|
# The metadata entry is stored in an ini, and ini files are parsed as strings only.
|
||||||
|
# Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
|
||||||
|
if "has_materials" in self._global_container_stack.getMetaData():
|
||||||
|
self._global_container_stack.removeMetaDataEntry("has_materials")
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.emit()
|
empty_material = self._container_registry.findInstanceContainers(id = "empty_material")[0]
|
||||||
|
self._global_container_stack.replaceContainer(material_index, empty_material)
|
||||||
|
|
||||||
|
Application.getInstance().globalContainerStackChanged.emit()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue