mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -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.InstanceContainer import InstanceContainer
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
from UM.Settings.Interfaces import ContainerInterface
|
||||||
|
|
||||||
from . import Exceptions
|
from . import Exceptions
|
||||||
|
|
||||||
|
@ -121,6 +122,18 @@ class GlobalStack(ContainerStack):
|
||||||
def removeContainer(self, index: int) -> None:
|
def removeContainer(self, index: int) -> None:
|
||||||
raise Exceptions.InvalidOperationError("Cannot remove a container from Global stack")
|
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)
|
@override(ContainerStack)
|
||||||
def deserialize(self, contents: str) -> None:
|
def deserialize(self, contents: str) -> None:
|
||||||
super().deserialize(contents)
|
super().deserialize(contents)
|
||||||
|
@ -152,8 +165,8 @@ class GlobalStack(ContainerStack):
|
||||||
|
|
||||||
self._containers = new_containers
|
self._containers = new_containers
|
||||||
|
|
||||||
## private:
|
|
||||||
|
|
||||||
|
## private:
|
||||||
global_stack_mime = MimeType(
|
global_stack_mime = MimeType(
|
||||||
name = "application/x-cura-globalstack",
|
name = "application/x-cura-globalstack",
|
||||||
comment = "Cura Global Stack",
|
comment = "Cura Global Stack",
|
||||||
|
@ -163,6 +176,7 @@ global_stack_mime = MimeType(
|
||||||
MimeTypeDatabase.addMimeType(global_stack_mime)
|
MimeTypeDatabase.addMimeType(global_stack_mime)
|
||||||
ContainerRegistry.addContainerTypeByName(GlobalStack, "global_stack", global_stack_mime.name)
|
ContainerRegistry.addContainerTypeByName(GlobalStack, "global_stack", global_stack_mime.name)
|
||||||
|
|
||||||
|
|
||||||
class _ContainerIndexes:
|
class _ContainerIndexes:
|
||||||
UserChanges = 0
|
UserChanges = 0
|
||||||
QualityChanges = 1
|
QualityChanges = 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue