mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 10:47:49 -06:00
Override replaceContainer and add some type checking
type in this case being container type Contributes to CURA-3497
This commit is contained in:
parent
dc0c666a54
commit
de1dbfbc07
1 changed files with 16 additions and 2 deletions
|
@ -10,6 +10,7 @@ from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackErro
|
|||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
|
||||
from . import Exceptions
|
||||
|
||||
|
@ -121,6 +122,18 @@ class GlobalStack(ContainerStack):
|
|||
def removeContainer(self, index: int) -> None:
|
||||
raise Exceptions.InvalidOperationError("Cannot remove a container from Global stack")
|
||||
|
||||
## Overridden from ContainerStack
|
||||
@override(ContainerStack)
|
||||
def replaceContainer(self, index: int, container: ContainerInterface, postpone_emit: bool = False) -> None:
|
||||
expected_type = _ContainerIndexes.IndexTypeMap[index]
|
||||
if expected_type == "definition" and not isinstance(container, DefinitionContainer):
|
||||
raise Exceptions.InvalidContainerError("Cannot replace container at index {index} with a container that is not a DefinitionContainer".format(index = index))
|
||||
if container != self._empty_instance_container and container.getMetaDataEntry("type") != expected_type:
|
||||
raise Exceptions.InvalidContainerError("Cannot replace container at index {index} with a container that is not of {type} type".format(index = index, type = expected_type))
|
||||
|
||||
super().replaceContainer(index, container, postpone_emit)
|
||||
|
||||
## Overridden from ContainerStack
|
||||
@override(ContainerStack)
|
||||
def deserialize(self, contents: str) -> None:
|
||||
super().deserialize(contents)
|
||||
|
@ -152,17 +165,18 @@ class GlobalStack(ContainerStack):
|
|||
|
||||
self._containers = new_containers
|
||||
|
||||
## private:
|
||||
|
||||
## private:
|
||||
global_stack_mime = MimeType(
|
||||
name = "application/x-cura-globalstack",
|
||||
comment = "Cura Global Stack",
|
||||
suffixes = [ "global.cfg" ]
|
||||
suffixes = ["global.cfg"]
|
||||
)
|
||||
|
||||
MimeTypeDatabase.addMimeType(global_stack_mime)
|
||||
ContainerRegistry.addContainerTypeByName(GlobalStack, "global_stack", global_stack_mime.name)
|
||||
|
||||
|
||||
class _ContainerIndexes:
|
||||
UserChanges = 0
|
||||
QualityChanges = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue