App: fixes #10460: App::PropertyPythonObject is not saving data
Since Py3.11 the methods names __setstate__ and __getstate__ conflict with the method names added to the object class. Thus rename them to 'loads' and 'dumps'
This commit is contained in:
@@ -85,7 +85,7 @@ class DraftObject(object):
|
||||
# Object properties are updated when the document is opened.
|
||||
self.props_changed_clear()
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
"""Return a tuple of all serializable objects or None.
|
||||
|
||||
When saving the document this object gets stored
|
||||
@@ -102,7 +102,7 @@ class DraftObject(object):
|
||||
"""
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self, state):
|
||||
def loads(self, state):
|
||||
"""Set some internal properties for all restored objects.
|
||||
|
||||
When a document is restored this method is used to set some properties
|
||||
|
||||
@@ -82,11 +82,11 @@ class DraftAnnotation(object):
|
||||
if multiplier is not None:
|
||||
vobj.ScaleMultiplier = multiplier
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
|
||||
return
|
||||
|
||||
def __setstate__(self,state):
|
||||
def loads(self,state):
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -64,17 +64,17 @@ class DraftLink(DraftObject):
|
||||
if obj:
|
||||
self.attach(obj)
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
"""Return a tuple of all serializable objects or None."""
|
||||
return self.__dict__
|
||||
|
||||
def __setstate__(self, state):
|
||||
def loads(self, state):
|
||||
"""Set some internal properties for all restored objects."""
|
||||
if isinstance(state, dict):
|
||||
self.__dict__ = state
|
||||
else:
|
||||
self.use_link = False
|
||||
super(DraftLink, self).__setstate__(state)
|
||||
super(DraftLink, self).loads(state)
|
||||
|
||||
def attach(self, obj):
|
||||
"""Set up the properties when the object is attached."""
|
||||
|
||||
@@ -67,11 +67,11 @@ class Hatch(DraftObject):
|
||||
|
||||
self.setProperties(obj)
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
def loads(self,state):
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -80,11 +80,11 @@ class Layer:
|
||||
_wrn("v0.19, " + obj.Label + ", "
|
||||
+ translate("draft", "added missing view properties"))
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
"""Return a tuple of objects to save or None."""
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self, state):
|
||||
def loads(self, state):
|
||||
"""Set the internal properties from the restored state."""
|
||||
if state:
|
||||
self.Type = state
|
||||
@@ -126,12 +126,12 @@ class LayerContainer:
|
||||
group.sort(key=lambda layer: layer.Label)
|
||||
obj.Group = group
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
"""Return a tuple of objects to save or None."""
|
||||
if hasattr(self, "Type"):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self, state):
|
||||
def loads(self, state):
|
||||
"""Set the internal properties from the restored state."""
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
@@ -76,7 +76,7 @@ class Text(DraftAnnotation):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
# See __setstate__: self.Type is None for new objects.
|
||||
# See loads: self.Type is None for new objects.
|
||||
if self.Type is not None \
|
||||
and hasattr(obj, "ViewObject") \
|
||||
and obj.ViewObject:
|
||||
@@ -93,7 +93,7 @@ class Text(DraftAnnotation):
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
|
||||
|
||||
def __setstate__(self,state):
|
||||
def loads(self,state):
|
||||
# Before update_properties_0v21 the self.Type value was stored.
|
||||
# We use this to identify older objects that need to be updated.
|
||||
self.Type = state
|
||||
|
||||
@@ -70,10 +70,10 @@ class WorkingPlaneProxy:
|
||||
def getNormal(self,obj):
|
||||
return obj.Shape.Faces[0].normalAt(0,0)
|
||||
|
||||
def __getstate__(self):
|
||||
def dumps(self):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self,state):
|
||||
def loads(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
|
||||
Reference in New Issue
Block a user