mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Remove hardcoded container index
This commit is contained in:
parent
29e04bb825
commit
1325c31882
2 changed files with 28 additions and 16 deletions
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2016 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot
|
||||
|
||||
from cura.MachineAction import MachineAction
|
||||
import cura.Settings.CuraContainerRegistry
|
||||
|
@ -19,23 +19,35 @@ class MachineSettingsAction(MachineAction):
|
|||
super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
|
||||
self._qml_url = "MachineSettingsAction.qml"
|
||||
|
||||
self._container_index = 0
|
||||
|
||||
cura.Settings.CuraContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)
|
||||
|
||||
def _reset(self):
|
||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
variant = global_container_stack.findContainer({"type": "variant"})
|
||||
if variant and variant.getId() == "empty_variant":
|
||||
if variant:
|
||||
variant_index = global_container_stack.getContainerIndex(variant)
|
||||
self._createVariant(global_container_stack, variant_index)
|
||||
if variant_index != self._container_index:
|
||||
self._container_index = variant_index
|
||||
self.containerIndexChanged.emit()
|
||||
if variant.getId() == "empty_variant":
|
||||
self._createVariant(global_container_stack, self._container_index)
|
||||
|
||||
def _createVariant(self, global_container_stack, variant_index):
|
||||
def _createVariant(self, global_container_stack):
|
||||
# Create and switch to a variant to store the settings in
|
||||
new_variant = UM.Settings.InstanceContainer(global_container_stack.getName() + "_variant")
|
||||
new_variant.addMetaDataEntry("type", "variant")
|
||||
new_variant.setDefinition(global_container_stack.getBottom())
|
||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_variant)
|
||||
global_container_stack.replaceContainer(variant_index, new_variant)
|
||||
global_container_stack.replaceContainer(self._container_index, new_variant)
|
||||
|
||||
containerIndexChanged = pyqtSignal()
|
||||
|
||||
@pyqtProperty(int, notify = containerIndexChanged)
|
||||
def containerIndex(self):
|
||||
return self._container_index
|
||||
|
||||
def _onContainerAdded(self, container):
|
||||
# Add this action as a supported action to all machine definitions
|
||||
|
|
|
@ -377,7 +377,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_width"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -387,7 +387,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_depth"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -397,7 +397,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_height"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -407,7 +407,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_heated_bed"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -417,7 +417,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_center_is_zero"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -427,7 +427,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_gcode_flavor"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -437,7 +437,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_nozzle_size"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -447,7 +447,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "gantry_height"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -457,7 +457,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_head_with_fans_polygon"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
|
||||
|
@ -468,7 +468,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_start_gcode"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
UM.SettingPropertyProvider
|
||||
|
@ -478,7 +478,7 @@ Cura.MachineAction
|
|||
containerStackId: Cura.MachineManager.activeMachineId
|
||||
key: "machine_end_gcode"
|
||||
watchedProperties: [ "value" ]
|
||||
storeIndex: 4
|
||||
storeIndex: manager.containerIndex
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue