Merge branch 'master' into exportgedcom

This commit is contained in:
Paul Culley 2017-01-24 07:57:01 -06:00 committed by GitHub
commit 8739412351
86 changed files with 661 additions and 2447 deletions

View File

@ -89,6 +89,7 @@
</object>
<object handle="_0000000900000009" change="1472500307" id="M5">
<file src="test.jpg" mime="image/jpeg" description="Multimedia link to linked form FTM style file"/>
<datestr val="6/4/2016 9:33:57 AM"/>
<noteref hlink="_0000001d0000001d"/>
<noteref hlink="_0000001e0000001e"/>
<noteref hlink="_0000001f0000001f"/>

View File

@ -63,7 +63,7 @@ class DateHandlerTest(unittest.TestCase):
self.assertTrue(test_date.is_equal(new_date),
"{} -> {}\n{} -> {}".format(
test_date, new_date,
test_date.to_struct(), new_date.to_struct()))
test_date.__dict__, new_date.__dict__))
def test_simple(self):

View File

@ -67,49 +67,6 @@ class Address(SecondaryObject, PrivacyBase, CitationBase, NoteBase, DateBase,
DateBase.serialize(self),
LocationBase.serialize(self))
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Address",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"location": LocationBase.to_struct(self)
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Address()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
DateBase.from_struct(struct.get("date", {})),
LocationBase.from_struct(struct.get("location", {}))
)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -59,37 +59,6 @@ class AddressBase:
"""
return [addr.serialize() for addr in self.address_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [addr.to_struct() for addr in self.address_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Address.from_struct(addr) for addr in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -65,37 +65,6 @@ class AttributeRootBase:
"""
return [attr.serialize() for attr in self.attribute_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [attr.to_struct() for attr in self.attribute_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [cls._CLASS.from_struct(attr) for attr in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -77,43 +77,6 @@ class AttributeRoot(SecondaryObject, PrivacyBase):
return (PrivacyBase.serialize(self),
self.type.serialize(), self.value)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": self.__class__.__name__,
"private": PrivacyBase.serialize(self),
"type": self.type.to_struct(),
"value": self.value}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Attribute()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
AttributeType.from_struct(struct.get("type", {})),
struct.get("value", default.value))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.
@ -246,46 +209,6 @@ class Attribute(AttributeRoot, CitationBase, NoteBase):
NoteBase.serialize(self),
self.type.serialize(), self.value)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Attribute",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"type": self.type.to_struct(),
"value": self.value}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return (PrivacyBase.from_struct(struct["private"]),
CitationBase.from_struct(struct["citation_list"]),
NoteBase.from_struct(struct["note_list"]),
AttributeType.from_struct(struct["type"]),
struct["value"])
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -56,43 +56,6 @@ class BaseObject(metaclass=ABCMeta):
Convert a serialized tuple of data to an object.
"""
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def matches_string(self, pattern, case_sensitive=False):
"""
Return True if any text data in the object or any of it's child

View File

@ -75,49 +75,6 @@ class ChildRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
self.frel.serialize(),
self.mrel.serialize())
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "ChildRef",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"ref": Handle("Person", self.ref),
"frel": self.frel.to_struct(),
"mrel": self.mrel.to_struct()}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = ChildRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
ChildRefType.from_struct(struct.get("frel", {})),
ChildRefType.from_struct(struct.get("mrel", {})))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -136,61 +136,6 @@ class Citation(MediaBase, NoteBase, SrcAttributeBase, IndirectCitationBase,
TagBase.serialize(self), # 10
self.private) # 11
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Citation",
"handle": Handle("Citation", self.handle), # 0
"gramps_id": self.gramps_id, # 1
"date": DateBase.to_struct(self), # 2
"page": str(self.page), # 3
"confidence": self.confidence, # 4
"source_handle": Handle("Source", self.source_handle), # 5
"note_list": NoteBase.to_struct(self), # 6
"media_list": MediaBase.to_struct(self), # 7
"srcattr_list": SrcAttributeBase.to_struct(self),# 8
"change": self.change, # 9
"tag_list": TagBase.to_struct(self), # 10
"private": self.private} # 11
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Citation()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
DateBase.from_struct(struct.get("date", {})),
struct.get("page", default.page),
struct.get("confidence", default.confidence),
Handle.from_struct(struct.get("source_handle", default.source_handle)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
MediaBase.from_struct(struct.get("media_list", default.media_list)),
SrcAttributeBase.from_struct(struct.get("srcattr_list", [])),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -75,37 +75,6 @@ class CitationBase:
"""
return self.citation_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle("Citation", c) for c in self.citation_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(handle) for handle in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -671,55 +671,6 @@ class Date:
return (self.calendar, self.modifier, self.quality,
self.dateval, text, self.sortval, self.newyear)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Date",
"calendar": self.calendar,
"modifier": self.modifier,
"quality": self.quality,
"dateval": self.dateval,
"text": self.text,
"sortval": self.sortval,
"newyear": self.newyear}
@classmethod
def from_struct(cls, struct, full=False):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Date()
retval = (struct.get("calendar", default.calendar),
struct.get("modifier", default.modifier),
struct.get("quality", default.quality),
struct.get("dateval", default.dateval),
struct.get("text", default.text),
struct.get("sortval", default.sortval),
struct.get("newyear", default.newyear))
if not full and retval == (0, 0, 0, (0, 0, 0, False), '', 0, 0):
return None
else:
return retval
def unserialize(self, data):
"""
Load from the format created by serialize.
@ -1701,7 +1652,7 @@ class Date:
self.__compare(sanity.dateval, value, year_delta)
except DateError as err:
LOG.debug("Sanity check failed - self: {}, sanity: {}".
format(self.to_struct(), sanity.to_struct()))
format(self.__dict__, sanity.__dict__))
err.date = self
raise

View File

@ -61,41 +61,6 @@ class DateBase:
date = self.date.serialize(no_text_date)
return date
def to_struct(self, no_text_date=False):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
if self.date is None:
date = Date().to_struct()
else:
date = self.date.to_struct()
return date
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return Date.from_struct(struct)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -118,41 +118,6 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
AttributeBase.serialize(self),
self.change, TagBase.serialize(self), self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Event",
"handle": Handle("Event", self.handle),
"gramps_id": self.gramps_id,
"type": self.__type.to_struct(),
"date": DateBase.to_struct(self),
"description": self.__description,
"place": Handle("Place", self.place),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def get_schema(cls):
"""
@ -199,28 +164,6 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
"private": _("Private"),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Event()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
EventType.from_struct(struct.get("type", {})),
DateBase.from_struct(struct.get("date", {})),
struct.get("description", default.description),
Handle.from_struct(struct.get("place", default.place)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
MediaBase.from_struct(struct.get("media_list", default.media_list)),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -79,35 +79,6 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
self.__role.serialize()
)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "EventRef",
"private": PrivacyBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"ref": Handle("Event", self.ref),
"role": self.__role.to_struct()
}
@classmethod
def get_schema(cls):
"""
@ -142,22 +113,6 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
"role": _("Role"),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = EventRef()
return (
PrivacyBase.from_struct(struct.get("private", default.private)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
EventRoleType.from_struct(struct.get("role", {}))
)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -127,78 +127,6 @@ class Family(CitationBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase,
NoteBase.serialize(self),
self.change, TagBase.serialize(self), self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Family",
"handle": Handle("Family", self.handle),
"gramps_id": self.gramps_id,
"father_handle": Handle("Person", self.father_handle),
"mother_handle": Handle("Person", self.mother_handle),
"child_ref_list": [cr.to_struct() for cr in self.child_ref_list],
"type": self.type.to_struct(),
"event_ref_list": [er.to_struct() for er in self.event_ref_list],
"media_list": MediaBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"lds_ord_list": LdsOrdBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Family()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
Handle.from_struct(struct.get("father_handle",
default.father_handle)),
Handle.from_struct(struct.get("mother_handle",
default.mother_handle)),
[ChildRef.from_struct(cr)
for cr in struct.get("child_ref_list",
default.child_ref_list)],
FamilyRelType.from_struct(struct.get("type", {})),
[EventRef.from_struct(er)
for er in struct.get("event_ref_list",
default.event_ref_list)],
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
LdsOrdBase.from_struct(struct.get("lds_ord_list",
default.lds_ord_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
@classmethod
def get_schema(cls):
from .mediaref import MediaRef

View File

@ -215,44 +215,6 @@ class GrampsType(object, metaclass=GrampsTypeMeta):
"string": _("Family Relationship"),
}
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": self.__class__.__name__,
"value": self.__value,
"string": str(self)}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = cls()
if struct.get("value", cls._CUSTOM) == cls._CUSTOM:
return (struct.get("value", default.value),
struct.get("string", ""))
else:
return (struct.get("value", default.value), '')
def unserialize(self, data):
"""Convert a serialized tuple of data to an object."""
self.__value, self.__string = data

View File

@ -53,7 +53,3 @@ def Handle(_classname, handle):
classname = _classname
h = MyHandleClass(handle)
return h
def __from_struct(struct):
return struct
Handle.from_struct = __from_struct

View File

@ -144,57 +144,6 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
self.type, self.place,
self.famc, self.temple, self.status, self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "LdsOrd",
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"type": self.type,
"place": self.place,
"famc": self.famc,
"temple": self.temple,
"status": self.status,
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = LdsOrd()
return (CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
DateBase.from_struct(struct.get("date", {})),
struct.get("type", {}),
struct.get("place", default.place),
struct.get("famc", default.famc),
struct.get("temple", default.temple),
struct.get("status", default.status),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -64,37 +64,6 @@ class LdsOrdBase:
"""
return [lds_ord.serialize() for lds_ord in self.lds_ord_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [lds_ord.to_struct() for lds_ord in self.lds_ord_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [LdsOrd.from_struct(lds_ord) for lds_ord in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object

View File

@ -63,55 +63,6 @@ class Location(SecondaryObject, LocationBase):
"""
return (LocationBase.serialize(self), self.parish)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Location",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone,
"parish": self.parish}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Location()
return ((struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("country", default.country),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone)),
struct.get("parish", default.parish))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -64,55 +64,6 @@ class LocationBase:
return (self.street, self.locality, self.city, self.county, self.state,
self.country, self.postal, self.phone)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "LocationBase",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = LocationBase()
return (struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("county", default.county),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -118,41 +118,6 @@ class Media(CitationBase, NoteBase, DateBase, AttributeBase,
TagBase.serialize(self),
self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Media",
"handle": Handle("Media", self.handle),
"gramps_id": self.gramps_id,
"path": self.path,
"mime": self.mime,
"desc": self.desc,
"checksum": self.checksum,
"attribute_list": AttributeBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"date": DateBase.to_struct(self),
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def get_schema(cls):
"""
@ -205,28 +170,6 @@ class Media(CitationBase, NoteBase, DateBase, AttributeBase,
"private": _("Private"),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Media()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("path", default.path),
struct.get("mime", default.mime),
struct.get("desc", default.desc),
struct.get("checksum", default.checksum),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
DateBase.from_struct(struct.get("date", {})),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -56,37 +56,6 @@ class MediaBase:
"""
return [mref.serialize() for mref in self.media_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [mref.to_struct() for mref in self.media_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [MediaRef.from_struct(mref) for mref in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -70,34 +70,6 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
RefBase.serialize(self),
self.rect)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "MediaRef",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"ref": Handle("Media", self.ref),
"rect": self.rect if self.rect != (0, 0, 0, 0) else None}
@classmethod
def get_schema(cls):
"""
@ -118,24 +90,6 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
"rect": tuple, # or None if (0,0,0,0)
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = MediaRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("rect", default.rect))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -129,70 +129,6 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
self.group_as, self.sort_as, self.display_as, self.call,
self.nick, self.famnick)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Name",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"first_name": self.first_name,
"surname_list": SurnameBase.to_struct(self),
"suffix": self.suffix,
"title": self.title,
"type": self.type.to_struct(),
"group_as": self.group_as,
"sort_as": self.sort_as,
"display_as": self.display_as,
"call": self.call,
"nick": self.nick,
"famnick": self.famnick}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Name()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
DateBase.from_struct(struct.get("date", {})),
struct.get("first_name", default.first_name),
SurnameBase.from_struct(struct.get("surname_list",
default.surname_list)),
struct.get("suffix", default.suffix),
struct.get("title", default.title),
NameType.from_struct(struct.get("type", {})),
struct.get("group_as", default.group_as),
struct.get("sort_as", default.sort_as),
struct.get("display_as", default.display_as),
struct.get("call", default.call),
struct.get("nick", default.nick),
struct.get("famnick", default.famnick))
@classmethod
def get_labels(cls, _):
return {

View File

@ -95,36 +95,6 @@ class Note(BasicPrimaryObject):
self.type.serialize(), self.change, TagBase.serialize(self),
self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Note",
"handle": Handle("Note", self.handle),
"gramps_id": self.gramps_id,
"text": self.text.to_struct(),
"format": self.format,
"type": self.type.to_struct(),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def get_schema(cls):
"""
@ -154,23 +124,6 @@ class Note(BasicPrimaryObject):
"private": _("Private"),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Note()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
StyledText.from_struct(struct.get("text", {})),
struct.get("format", default.format),
NoteType.from_struct(struct.get("type", {})),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""Convert a serialized tuple of data to an object.

View File

@ -53,37 +53,6 @@ class NoteBase:
"""
return self.note_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle("Note", n) for n in self.note_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(n) for n in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -157,56 +157,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
[pr.serialize() for pr in self.person_ref_list] # 20
)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "Person",
"handle": Handle("Person", self.handle), # 0
"gramps_id": self.gramps_id, # 1
"gender": self.__gender, # 2
"primary_name": self.primary_name.to_struct(), # 3
"alternate_names": [name.to_struct()
for name in self.alternate_names], # 4
"death_ref_index": self.death_ref_index, # 5
"birth_ref_index": self.birth_ref_index, # 6
"event_ref_list": [er.to_struct()
for er in self.event_ref_list], # 7
"family_list": [Handle("Family", f) for f in
self.family_list], # 8
"parent_family_list": [Handle("Family", f) for f in
self.parent_family_list], # 9
"media_list": MediaBase.to_struct(self), # 10
"address_list": AddressBase.to_struct(self), # 11
"attribute_list": AttributeBase.to_struct(self), # 12
"urls": UrlBase.to_struct(self), # 13
"lds_ord_list": LdsOrdBase.to_struct(self), # 14
"citation_list": CitationBase.to_struct(self), # 15
"note_list": NoteBase.to_struct(self), # 16
"change": self.change, # 17
"tag_list": TagBase.to_struct(self), # 18
"private": self.private, # 19
"person_ref_list": [pr.to_struct()
for pr in self.person_ref_list] # 20
}
@classmethod
def get_labels(cls, _):
return {
@ -234,49 +184,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
"probably_alive": _("Probably alive"),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Person()
return (
Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("gender", default.gender),
Name.from_struct(struct.get("primary_name", {})),
[Name.from_struct(name)
for name in struct.get("alternate_names",
default.alternate_names)],
struct.get("death_ref_index", default.death_ref_index),
struct.get("birth_ref_index", default.birth_ref_index),
[EventRef.from_struct(er)
for er in struct.get("event_ref_list", default.event_ref_list)],
[Handle.from_struct(handle)
for handle in struct.get("family_list", default.family_list)],
[Handle.from_struct(handle)
for handle in struct.get("parent_family_list",
default.parent_family_list)],
MediaBase.from_struct(struct.get("media_list", default.media_list)),
AddressBase.from_struct(struct.get("address_list",
default.address_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
UrlBase.from_struct(struct.get("urls", default.urls)),
LdsOrdBase.from_struct(struct.get("lds_ord_list",
default.lds_ord_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private),
[PersonRef.from_struct(p)
for p in struct.get("person_ref_list", default.person_ref_list)]
)
@classmethod
def get_schema(cls):
"""

View File

@ -72,47 +72,6 @@ class PersonRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
RefBase.serialize(self),
self.rel)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "PersonRef",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"ref": Handle("Person", self.ref),
"rel": self.rel}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PersonRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("rel", default.rel))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -166,78 +166,6 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
"private": bool
}
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Place",
"handle": Handle("Place", self.handle),
"gramps_id": self.gramps_id,
"title": self.title,
"long": self.long,
"lat": self.lat,
"placeref_list": [pr.to_struct() for pr in self.placeref_list],
"name": self.name.to_struct(),
"alt_names": [an.to_struct() for an in self.alt_names],
"place_type": self.place_type.to_struct(),
"code": self.code,
"alt_loc": [al.to_struct() for al in self.alt_loc],
"urls": UrlBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Place()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("title", default.title),
struct.get("long", default.long),
struct.get("lat", default.lat),
[PlaceRef.from_struct(pr)
for pr in struct.get("placeref_list", default.placeref_list)],
PlaceName.from_struct(struct.get("name", {})),
[PlaceName.from_struct(an)
for an in struct.get("alt_names", default.alt_names)],
PlaceType.from_struct(struct.get("place_type", {})),
struct.get("code", default.code),
[Location.from_struct(al)
for al in struct.get("alt_loc", default.alt_loc)],
UrlBase.from_struct(struct.get("urls", default.urls)),
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -71,47 +71,6 @@ class PlaceName(SecondaryObject, DateBase):
self.lang
)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "PlaceName",
"value": self.value,
"date": DateBase.to_struct(self),
"lang": self.lang
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PlaceName()
return (
struct.get("value", default.value),
DateBase.from_struct(struct.get("date", {})),
struct.get("lang", default.lang)
)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -63,45 +63,6 @@ class PlaceRef(RefBase, DateBase, SecondaryObject):
DateBase.serialize(self)
)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "PlaceRef",
"ref": Handle("Place", self.ref),
"date": DateBase.to_struct(self)
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PlaceRef()
return (
RefBase.from_struct(struct.get("ref", default.ref)),
DateBase.from_struct(struct.get("date", {}))
)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -90,43 +90,6 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
Convert a serialized tuple of data to an object.
"""
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def set_gramps_id(self, gramps_id):
"""
Set the Gramps ID for the primary object.
@ -278,43 +241,6 @@ class PrimaryObject(BasicPrimaryObject):
Convert a serialized tuple of data to an object.
"""
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def has_handle_reference(self, classname, handle):
"""
Return True if the object has reference to a given handle of given

View File

@ -55,37 +55,6 @@ class PrivacyBase:
"""
return self.private
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: bool
"""
return self.private
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return struct
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -53,15 +53,6 @@ class RefBase(metaclass=ABCMeta):
"""
return self.ref
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return str(struct)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -104,57 +104,6 @@ class Repository(NoteBase, AddressBase, UrlBase, IndirectCitationBase,
"private": bool
}
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Repository",
"handle": Handle("Repository", self.handle),
"gramps_id": self.gramps_id,
"type": self.type.to_struct(),
"name": str(self.name),
"note_list": NoteBase.to_struct(self),
"address_list": AddressBase.to_struct(self),
"urls": UrlBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Repository()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
RepositoryType.from_struct(struct.get("type", {})),
struct.get("name", default.name),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
AddressBase.from_struct(struct.get("address_list", default.address_list)),
UrlBase.from_struct(struct.get("urls", default.urls)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -69,51 +69,6 @@ class RepoRef(SecondaryObject, PrivacyBase, NoteBase, RefBase):
PrivacyBase.serialize(self),
)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "RepositoryRef",
"note_list": NoteBase.to_struct(self),
"ref": Handle("Repository", self.ref),
"call_number": self.call_number,
"media_type": self.media_type.to_struct(),
"private": PrivacyBase.serialize(self),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = RepoRef()
return (
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("call_number", default.call_number),
SourceMediaType.from_struct(struct.get("media_type", {})),
struct.get("private", default.private),
)
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -60,59 +60,6 @@ class Researcher(LocationBase):
return (LocationBase.serialize(self),
self.name, self.addr, self.email)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Researcher",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone,
"name": self.name,
"address": self.addr,
"email": self.email}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Researcher()
return (struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("country", default.country),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone),
struct.get("name", default.name),
struct.get("address", default.addr),
struct.get("email", default.email))
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -59,43 +59,6 @@ class SecondaryObject(BaseObject):
Convert a serialized tuple of data to an object.
"""
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def is_equal(self, source):
return self.serialize() == source.serialize()

View File

@ -0,0 +1,89 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2017 Nick Hall
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""
Serialization utilities for Gramps.
"""
#------------------------------------------------------------------------
#
# Python modules
#
#------------------------------------------------------------------------
import json
#------------------------------------------------------------------------
#
# Gramps modules
#
#------------------------------------------------------------------------
import gramps.gen.lib as lib
def __default(obj):
obj_dict = {'_class': obj.__class__.__name__}
if isinstance(obj, lib.GrampsType):
obj_dict['string'] = getattr(obj, 'string')
if isinstance(obj, lib.Date):
if obj.is_empty() and not obj.text:
return None
for key, value in obj.__dict__.items():
if not key.startswith('_'):
obj_dict[key] = value
for key, value in obj.__class__.__dict__.items():
if isinstance(value, property):
if key != 'year':
obj_dict[key] = getattr(obj, key)
return obj_dict
def __object_hook(obj_dict):
obj = getattr(lib, obj_dict['_class'])()
for key, value in obj_dict.items():
if key != '_class':
if key in ('dateval', 'rect') and value is not None:
value = tuple(value)
if key == 'ranges':
value = [tuple(item) for item in value]
setattr(obj, key, value)
if obj_dict['_class'] == 'Date':
if obj.is_empty() and not obj.text:
return None
return obj
def to_json(obj):
"""
Encode a Gramps object in JSON format.
:param obj: The object to be serialized.
:type obj: object
:returns: A JSON string.
:rtype: str
"""
return json.dumps(obj, default=__default)
def from_json(data):
"""
Decode JSON data into a Gramps object hierarchy.
:param data: The JSON string to be unserialized.
:type data: str
:returns: A Gramps object.
:rtype: object
"""
return json.loads(data, object_hook=__object_hook)

View File

@ -121,67 +121,6 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, IndirectCitationBase,
"private": bool
}
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Source",
"handle": Handle("Source", self.handle),
"gramps_id": self.gramps_id,
"title": str(self.title),
"author": str(self.author),
"pubinfo": str(self.pubinfo),
"note_list": NoteBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"abbrev": str(self.abbrev),
"change": self.change,
"srcattr_list": SrcAttributeBase.to_struct(self),
"reporef_list": [rr.to_struct() for rr in self.reporef_list],
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
from .srcattribute import SrcAttribute
default = Source()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("title", default.title),
struct.get("author", default.author),
struct.get("pubinfo", default.pubinfo),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
struct.get("abbrev", default.abbrev),
struct.get("change", default.change),
SrcAttributeBase.from_struct(struct.get("srcattr_list", {})),
[RepoRef.from_struct(rr)
for rr in struct.get("reporef_list", default.reporef_list)],
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data):
"""
Convert the data held in a tuple created by the serialize method

View File

@ -288,47 +288,6 @@ class StyledText:
return (self._string, the_tags)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:return: Returns a struct containing the data of the object.
:rtype: dict
"""
if self._tags:
the_tags = [tag.to_struct() for tag in self._tags]
else:
the_tags = []
return {"_class": "StyledText",
"string": self._string,
"tags": the_tags}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:return: Returns a serialized object
"""
default = StyledText()
return (struct.get("string", default.string),
[StyledTextTag.from_struct(t)
for t in struct.get("tags", default.tags)])
@classmethod
def get_schema(cls):
"""
@ -372,14 +331,29 @@ class StyledText:
"""
return self._tags
def set_tags(self, tags):
"""
Set the list of formatting tags.
:param tags: The formatting tags applied on the text.
:type tags: list of 0 or more :py:class:`.StyledTextTag` instances.
"""
self._tags = tags
def get_string(self):
"""
Accessor for the associated string.
"""
return self._string
tags = property(get_tags)
string = property(get_string)
def set_string(self, string):
"""
Setter for the associated string.
"""
self._string = string
tags = property(get_tags, set_tags)
string = property(get_string, set_string)
if __name__ == '__main__':
from .styledtexttagtype import StyledTextTagType

View File

@ -72,43 +72,6 @@ class StyledTextTag:
"""
return (self.name.serialize(), self.value, self.ranges)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:return: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "StyledTextTag",
"name": self.name.to_struct(),
"value": self.value,
"ranges": self.ranges}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:return: Returns a serialized object
"""
default = StyledTextTag()
return (StyledTextTagType.from_struct(struct.get("name", {})),
struct.get("value", default.value),
struct.get("ranges", default.ranges))
def unserialize(self, data):
"""Convert a serialized tuple of data to an object.

View File

@ -71,33 +71,6 @@ class Surname(SecondaryObject):
return (self.surname, self.prefix, self.primary,
self.origintype.serialize(), self.connector)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Surname",
"surname": self.surname,
"prefix": self.prefix,
"primary": self.primary,
"origintype": self.origintype.to_struct(),
"connector": self.connector}
@classmethod
def get_schema(cls):
return {
@ -119,20 +92,6 @@ class Surname(SecondaryObject):
"connector": _("Connector")
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Surname()
return (struct.get("surname", default.surname),
struct.get("prefix", default.prefix),
struct.get("primary", default.primary),
NameOriginType.from_struct(struct.get("origintype", {})),
struct.get("connector", default.connector))
def is_empty(self):
"""
Indicate if the surname is empty.

View File

@ -60,37 +60,6 @@ class SurnameBase:
"""
return [surname.serialize() for surname in self.surname_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [surname.to_struct() for surname in self.surname_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Surname.from_struct(surname) for surname in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -92,43 +92,6 @@ class TableObject(BaseObject):
Convert a serialized tuple of data to an object.
"""
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def get_change_time(self):
"""
Return the time that the data was last changed.

View File

@ -225,46 +225,5 @@ class Tag(TableObject):
"""
return self.__priority
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Tag",
"handle": Handle("Tag", self.handle),
"name": self.__name,
"color": self.__color,
"priority": self.__priority,
"change": self.change}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Tag()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("name", default.name),
struct.get("color", default.color),
struct.get("priority", default.priority),
struct.get("change", default.change))
priority = property(get_priority, set_priority, None,
'Returns or sets priority of the tag')

View File

@ -55,37 +55,6 @@ class TagBase:
"""
return self.tag_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle('Tag', t) for t in self.tag_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(t) for t in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -245,7 +245,8 @@ class ParserDateTest(BaseDateTest):
"dateval fails is_equal in format %d:\n"
" '%s' != '%s'\n"
" '%s' != '%s'\n" %
(date_format, dateval, ndate, dateval.to_struct(), ndate.to_struct()))
(date_format, dateval, ndate,
dateval.__dict__, ndate.__dict__))
def test_basic(self):
self.do_case("basic test")
@ -380,7 +381,7 @@ class MatchDateTest(BaseDateTest):
d1,
("did not match" if expected else "matched"),
d2,
date1.to_struct(), date2.to_struct()))
date1.__dict__, date2.__dict__))
def test_match(self):
for testdata in self.tests:

View File

@ -18,13 +18,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
""" Unittest for to_struct, from_struct """
""" Unittest for to_json, from_json """
import unittest
import os
from .. import (Person, Family, Event, Source, Place, Citation,
Repository, Media, Note, Tag)
from .. import (Person, Family, Event, Source, Place, Citation,
Repository, Media, Note, Tag)
from ..serialize import to_json, from_json
from gramps.gen.db.utils import import_as_dict
from gramps.cli.user import User
from gramps.gen.const import DATA_DIR
@ -33,14 +34,15 @@ TEST_DIR = os.path.abspath(os.path.join(DATA_DIR, "tests"))
EXAMPLE = os.path.join(TEST_DIR, "example.gramps")
class BaseCheck:
def test_from_struct(self):
struct = self.object.to_struct()
serialized = self.cls.from_struct(struct)
self.assertEqual(self.object.serialize(), serialized)
def test_from_json(self):
data = to_json(self.object)
obj = from_json(data)
self.assertEqual(self.object.serialize(), obj.serialize())
def test_from_empty_struct(self):
serialized = self.cls.from_struct({})
self.assertEqual(self.object.serialize(), serialized)
def test_from_empty_json(self):
data = '{"_class": "%s"}' % self.cls.__name__
obj = from_json(data)
self.assertEqual(self.object.serialize(), obj.serialize())
class PersonCheck(unittest.TestCase, BaseCheck):
def setUp(self):
@ -99,10 +101,10 @@ def generate_case(obj):
"""
Dynamically generate tests and attach to DatabaseCheck.
"""
struct = obj.to_struct()
serialized = obj.__class__.from_struct(struct)
data = to_json(obj)
obj2 = from_json(data)
def test(self):
self.assertEqual(obj.serialize(), serialized)
self.assertEqual(obj.serialize(), obj2.serialize())
name = "test_serialize_%s_%s" % (obj.__class__.__name__, obj.handle)
setattr(DatabaseCheck, name, test)
####

View File

@ -67,45 +67,6 @@ class Url(SecondaryObject, PrivacyBase):
def serialize(self):
return (self.private, self.path, self.desc, self.type.serialize())
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Url",
"private": self.private,
"path": self.path,
"desc": self.desc,
"type": self.type.to_struct()}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Url()
return (struct.get("private", default.private),
struct.get("path", default.path),
struct.get("desc", default.desc),
UrlType.from_struct(struct.get("type", {})))
def unserialize(self, data):
(self.private, self.path, self.desc, type_value) = data
self.type.unserialize(type_value)

View File

@ -58,37 +58,6 @@ class UrlBase:
"""
return [url.serialize() for url in self.urls]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [url.to_struct() for url in self.urls]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Url.from_struct(url) for url in struct]
def unserialize(self, data):
"""
Convert a serialized tuple of data to an object.

View File

@ -22,11 +22,20 @@
This package implements an object difference engine.
"""
import json
from gramps.cli.user import User
from ..db.utils import import_as_dict
from ..lib.serialize import to_json
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
def to_struct(obj):
"""
Convert an object into a struct.
"""
return json.loads(to_json(obj))
def diff_dates(json1, json2):
"""
Compare two json date objects. Returns True if different.
@ -110,7 +119,7 @@ def diff_dbs(db1, db2, user=None):
if handles1[p1] == handles2[p2]: # in both
item1 = db1.get_table_func(item,"handle_func")(handles1[p1])
item2 = db2.get_table_func(item,"handle_func")(handles2[p2])
diff = diff_items(item, item1.to_struct(), item2.to_struct())
diff = diff_items(item, to_struct(item1), to_struct(item2))
if diff:
diffs += [(item, item1, item2)]
# else same!

View File

@ -258,7 +258,7 @@ class EditDate(ManagedWindow):
newyear=the_newyear)
# didn't throw yet?
self.validated_date = d
LOG.debug("validated_date set to: {0}".format(d.to_struct()))
LOG.debug("validated_date set to: {0}".format(d.__dict__))
self.ok_button.set_sensitive(1)
self.calendar_box.set_sensitive(1)
return True

View File

@ -61,7 +61,9 @@ class EditTagList(ManagedWindow):
"""
Initiate and display the dialog.
"""
ManagedWindow.__init__(self, uistate, track, self)
ManagedWindow.__init__(self, uistate, track, self, modal=True)
# the self.window.run() below makes Gtk make it modal, so any change
# to the previous line's "modal" would require that line to be changed
self.namemodel = None
top = self._create_dialog()
@ -78,6 +80,8 @@ class EditTagList(ManagedWindow):
self.show()
while True:
# the self.window.run() makes Gtk make it modal, so any change to
# that line means the ManagedWindow.__init__ must be changed also
response = self.window.run()
if response == Gtk.ResponseType.HELP:
display_help(webpage=WIKI_HELP_PAGE,
@ -97,9 +101,7 @@ class EditTagList(ManagedWindow):
Create a dialog box to select tags.
"""
# pylint: disable-msg=E1101
title = _("%(title)s - Gramps") % {'title': _("Edit Tags")}
top = Gtk.Dialog(title, self.uistate.window)
top.set_modal(True)
top = Gtk.Dialog(parent=self.uistate.window)
top.vbox.set_spacing(5)
columns = [('', -1, 300),
@ -116,10 +118,9 @@ class EditTagList(ManagedWindow):
top.add_button(_('_Help'), Gtk.ResponseType.HELP)
top.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL)
top.add_button(_('_OK'), Gtk.ResponseType.OK)
top.show_all()
return top
def build_menu_names(self, obj):
def build_menu_names(self, obj): # meaningless while it's modal
"""
Define the menu entry for the ManagedWindows.
"""

View File

@ -266,7 +266,7 @@ class GrampsWindowManager:
if not isinstance(item, list):
def func(obj):
if item.window_id and self.id2item.get(item.window_id):
self.id2item[item.window_id].__present()
self.id2item[item.window_id]._present()
else:
def func(obj):
pass
@ -418,7 +418,7 @@ class ManagedWindow:
self.other_modal_window = None
if uistate and uistate.gwm.get_item_from_id(window_key):
uistate.gwm.get_item_from_id(window_key).__present()
uistate.gwm.get_item_from_id(window_key)._present()
raise WindowActiveError('This window is already active')
else:
self.window_id = window_key
@ -568,7 +568,7 @@ class ManagedWindow:
self.other_modal_window.set_modal(True)
self.parent_window.present()
def __present(self):
def _present(self):
"""
Present window (unroll/unminimize/bring to top).
"""

View File

@ -154,7 +154,7 @@ class MergePlace(ManagedWindow):
rbutton_label1 = self.get_widget("label_handle_btn1")
rbutton_label2 = self.get_widget("label_handle_btn2")
rbutton_label1.set_label(title1 + " [" + gramps1 + "] " + str(self.pl1.place_type))
rbutton_label2.set_label(title2 + " [" + gramps2 + "] " + str(self.pl1.place_type))
rbutton_label2.set_label(title2 + " [" + gramps2 + "] " + str(self.pl2.place_type))
rbutton1.connect("toggled", self.on_handle1_toggled)
self.connect_button('place_help', self.cb_help)

View File

@ -257,14 +257,12 @@ def run_report(dbstate, uistate, category, handle, pdata, container=None,
elif category == CATEGORY_QR_CITATION :
obj = dbstate.db.get_citation_from_handle(handle)
elif category == CATEGORY_QR_SOURCE_OR_CITATION :
source = dbstate.db.get_source_from_handle(handle)
citation = dbstate.db.get_citation_from_handle(handle)
if (not source and not citation) or (source and citation):
raise ValueError("selection must be either source or citation")
if citation:
obj = citation
if dbstate.db.has_source_handle(handle):
obj = dbstate.db.get_source_from_handle(handle)
elif dbstate.db.has_citation_handle(handle):
obj = dbstate.db.get_citation_from_handle(handle)
else:
obj = source
raise ValueError("selection must be either source or citation")
elif category == CATEGORY_QR_PLACE :
obj = dbstate.db.get_place_from_handle(handle)
elif category == CATEGORY_QR_MEDIA :

View File

@ -268,11 +268,10 @@ class BaseSelector(ManagedWindow):
#reset the model with correct sorting
self.clear_model()
self.model = self.get_model_class()(self.db, self.sort_col,
self.sortorder,
sort_map=self.column_order(),
skip=self.skip_list,
search=filter_info)
self.model = self.get_model_class()(
self.db, self.uistate, self.sort_col, self.sortorder,
sort_map=self.column_order(), skip=self.skip_list,
search=filter_info)
self.tree.set_model(self.model)
@ -317,11 +316,10 @@ class BaseSelector(ManagedWindow):
def show_toggle(self, obj):
filter_info = None if obj.get_active() else self.filter
self.clear_model()
self.model = self.get_model_class()(self.db, self.sort_col,
self.sortorder,
sort_map=self.column_order(),
skip=self.skip_list,
search=filter_info)
self.model = self.get_model_class()(
self.db, self.uistate, self.sort_col, self.sortorder,
sort_map=self.column_order(), skip=self.skip_list,
search=filter_info)
self.tree.set_model(self.model)
self.tree.grab_focus()

View File

@ -96,7 +96,7 @@ class TipOfDay(ManagedWindow):
self.index = 0
self.next_tip_cb()
window.show_all()
self.show()
def escape(self,text):
text = text.replace('&','&amp;'); # Must be first

View File

@ -91,7 +91,7 @@ class UndoHistory(ManagedWindow):
Gtk.ResponseType.CLOSE)
self.set_window(window, None, self.title)
self.setup_configs('interface.undohistory', 400, 200)
self.setup_configs('interface.undohistory', 500, 200)
self.window.connect('response', self._response)
scrolled_window = Gtk.ScrolledWindow()
@ -119,7 +119,6 @@ class UndoHistory(ManagedWindow):
scrolled_window.add(self.tree)
self.window.vbox.pack_start(scrolled_window, True, True, 0)
self.window.show_all()
self._build_model()
self._update_ui()

View File

@ -50,6 +50,7 @@ from gi.repository import Gtk
#-------------------------------------------------------------------------
from ..display import display_help
from ..listmodel import ListModel
from ..managedwindow import ManagedWindow
from gramps.gen.utils.db import navigation_label
from gramps.gen.const import URL_MANUAL_PAGE
from gramps.gen.const import GRAMPS_LOCALE as glocale
@ -98,14 +99,6 @@ class Bookmarks(metaclass=ABCMeta):
self.dbstate.connect('database-changed', self.db_changed)
self.dbstate.connect("no-database", self.undisplay)
# initialise attributes
self.namemodel = None
self.namemodel_cols = None
self.top = None
self.modified = None
self.response = None
self.namelist = None
def db_changed(self, data):
"""
Reconnect the signals on a database changed.
@ -222,13 +215,50 @@ class Bookmarks(metaclass=ABCMeta):
if modified:
self.redraw_and_report_change()
def edit(self):
"""
Display the bookmark editor.
The current bookmarked people are inserted into the namelist,
attaching the person object to the corresponding row. The currently
selected row is attached to the name list. This is either 0 if the
list is not empty, or -1 if it is.
"""
BookmarksDialog(self)
class BookmarksDialog(ManagedWindow):
"""
A dialog to enable the user to organize bookmarks.
"""
def __init__(self, bm_class):
self.bm_class = bm_class
self.bookmarks = bm_class.bookmarks
self.dbstate = bm_class.dbstate
self.make_label = bm_class.make_label
uistate = bm_class.uistate
self.namemodel = None
self.top = None
self.modified = None
self.response = None
self.namelist = None
ManagedWindow.__init__(self, uistate, [], self.__class__, modal=True)
# the self.top.run() below makes Gtk make it modal, so any change to
# the previous line's "modal" would require that line to be changed
self.draw_window()
self.set_window(self.top, None, _("Organize Bookmarks"))
self.setup_configs('interface.bookmarksdialog', 400, 350)
self.show()
self.edit()
self.close()
def draw_window(self):
"""Draw the bookmark dialog box."""
title = _("%(title)s - Gramps") % {'title': _("Organize Bookmarks")}
self.top = Gtk.Dialog(title)
self.top.set_default_size(400, 350)
self.top.set_modal(True)
self.top.set_transient_for(self.uistate.window)
self.top = Gtk.Dialog(parent=self.parent_window)
self.top.vbox.set_spacing(5)
label = Gtk.Label(label='<span size="larger" weight="bold">%s</span>'
% _("Organize Bookmarks"))
@ -240,7 +270,6 @@ class Bookmarks(metaclass=ABCMeta):
name_titles = [(_('Name'), -1, 200), (_('ID'), -1, 50), ('', -1, 0)]
self.namelist = Gtk.TreeView()
self.namemodel = ListModel(self.namelist, name_titles)
self.namemodel_cols = len(name_titles)
slist = Gtk.ScrolledWindow()
slist.add(self.namelist)
@ -262,11 +291,6 @@ class Bookmarks(metaclass=ABCMeta):
bbox.add(down)
bbox.add(delete)
box.pack_start(bbox, 0, 0, 5)
self.top.show_all()
def close(self, widget, event):
"""Stop the bookmark organizer"""
self.top.response(Gtk.ResponseType.CLOSE)
def edit(self):
"""
@ -277,7 +301,6 @@ class Bookmarks(metaclass=ABCMeta):
selected row is attached to the name list. This is either 0 if the
list is not empty, or -1 if it is.
"""
self.draw_window()
for handle in self.bookmarks.get():
name, obj = self.make_label(handle)
if obj:
@ -287,13 +310,14 @@ class Bookmarks(metaclass=ABCMeta):
self.modified = False
while True:
# the self.top.run() makes Gtk make it modal, so any change to that
# line would require the ManagedWindow.__init__ to be changed also
self.response = self.top.run()
if self.response == Gtk.ResponseType.HELP:
self.help_clicked()
elif self.response == Gtk.ResponseType.CLOSE:
if self.modified:
self.redraw_and_report_change()
self.top.destroy()
self.bm_class.redraw_and_report_change()
break
def delete_clicked(self, obj):
@ -329,6 +353,9 @@ class Bookmarks(metaclass=ABCMeta):
"""Display the relevant portion of GRAMPS manual."""
display_help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
def build_menu_names(self, obj): # this is meaningless while it's modal
return (_('Organize Bookmarks'), None)
class ListBookmarks(Bookmarks):
""" Derived class from which all the specific type bookmark handlers are in
turn derived"""

View File

@ -320,9 +320,9 @@ class ListView(NavigationView):
if self.model:
self.list.set_model(None)
self.model.destroy()
self.model = self.make_model(self.dbstate.db, self.sort_col,
search=filter_info,
sort_map=self.column_order())
self.model = self.make_model(
self.dbstate.db, self.uistate, self.sort_col,
search=filter_info, sort_map=self.column_order())
else:
#the entire data to show is already in memory.
#run only the part that determines what to show
@ -647,10 +647,9 @@ class ListView(NavigationView):
self.model.reverse_order()
self.list.set_model(self.model)
else:
self.model = self.make_model(self.dbstate.db, self.sort_col,
self.sort_order,
search=filter_info,
sort_map=self.column_order())
self.model = self.make_model(
self.dbstate.db, self.uistate, self.sort_col, self.sort_order,
search=filter_info, sort_map=self.column_order())
self.list.set_model(self.model)

View File

@ -56,8 +56,8 @@ class CitationListModel(CitationBaseModel, FlatBaseModel):
"""
Flat citation model. (Original code in CitationBaseModel).
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.map = db.get_raw_citation_data
self.gen_cursor = db.get_citation_cursor
self.fmap = [
@ -94,8 +94,8 @@ class CitationListModel(CitationBaseModel, FlatBaseModel):
self.citation_src_chan,
self.citation_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -65,8 +65,8 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel):
"""
Hierarchical citation model.
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.db = db
self.number_items = self.db.get_number_of_sources
self.map = self.db.get_raw_source_data
@ -100,7 +100,7 @@ class CitationTreeModel(CitationBaseModel, TreeBaseModel):
self.source_src_tag_color
]
TreeBaseModel.__init__(self, self.db, scol=scol, order=order,
TreeBaseModel.__init__(self, self.db, uistate, scol=scol, order=order,
search=search, skip=skip, sort_map=sort_map,
nrgroups=1,
group_can_have_handle=True,

View File

@ -71,8 +71,8 @@ INVALID_DATE_FORMAT = config.get('preferences.invalid-date-format')
#-------------------------------------------------------------------------
class EventModel(FlatBaseModel):
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.gen_cursor = db.get_event_cursor
self.map = db.get_raw_event_data
@ -100,8 +100,8 @@ class EventModel(FlatBaseModel):
self.column_participant,
self.column_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -56,8 +56,8 @@ invalid_date_format = config.get('preferences.invalid-date-format')
#-------------------------------------------------------------------------
class FamilyModel(FlatBaseModel):
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.gen_cursor = db.get_family_cursor
self.map = db.get_raw_family_data
self.fmap = [
@ -82,8 +82,8 @@ class FamilyModel(FlatBaseModel):
self.sort_change,
self.column_tag_color,
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -450,7 +450,7 @@ class FlatBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
so as to have localized sort
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING,
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(),
sort_map=None):
cput = time.clock()

View File

@ -52,8 +52,8 @@ from .flatbasemodel import FlatBaseModel
#-------------------------------------------------------------------------
class MediaModel(FlatBaseModel):
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.gen_cursor = db.get_media_cursor
self.map = db.get_raw_media_data
@ -80,8 +80,8 @@ class MediaModel(FlatBaseModel):
self.sort_change,
self.column_tag_color,
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -52,8 +52,8 @@ from gramps.gen.lib import (Note, NoteType, StyledText)
class NoteModel(FlatBaseModel):
"""
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
"""Setup initial values for instance variables."""
self.gen_cursor = db.get_note_cursor
self.map = db.get_raw_note_data
@ -75,8 +75,8 @@ class NoteModel(FlatBaseModel):
self.sort_change,
self.column_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -573,11 +573,11 @@ class PersonListModel(PeopleBaseModel, FlatBaseModel):
"""
Listed people model.
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
PeopleBaseModel.__init__(self, db)
FlatBaseModel.__init__(self, db, search=search, skip=skip, scol=scol,
order=order, sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, search=search, skip=skip,
scol=scol, order=order, sort_map=sort_map)
def destroy(self):
"""
@ -590,11 +590,11 @@ class PersonTreeModel(PeopleBaseModel, TreeBaseModel):
"""
Hierarchical people model.
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
PeopleBaseModel.__init__(self, db)
TreeBaseModel.__init__(self, db, search=search, skip=skip, scol=scol,
order=order, sort_map=sort_map)
TreeBaseModel.__init__(self, db, uistate, search=search, skip=skip,
scol=scol, order=order, sort_map=sort_map)
def destroy(self):
"""

View File

@ -230,12 +230,12 @@ class PlaceListModel(PlaceBaseModel, FlatBaseModel):
"""
Flat place model. (Original code in PlaceBaseModel).
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
PlaceBaseModel.__init__(self, db)
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""
@ -253,11 +253,11 @@ class PlaceTreeModel(PlaceBaseModel, TreeBaseModel):
"""
Hierarchical place model.
"""
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
PlaceBaseModel.__init__(self, db)
TreeBaseModel.__init__(self, db, scol=scol, order=order,
TreeBaseModel.__init__(self, db, uistate, scol=scol, order=order,
search=search, skip=skip, sort_map=sort_map,
nrgroups=3,
group_can_have_handle=True)

View File

@ -49,8 +49,8 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
#-------------------------------------------------------------------------
class RepositoryModel(FlatBaseModel):
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.gen_cursor = db.get_repository_cursor
self.get_handles = db.get_repository_handles
self.map = db.get_raw_repository_data
@ -92,8 +92,8 @@ class RepositoryModel(FlatBaseModel):
self.column_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -49,8 +49,8 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
#-------------------------------------------------------------------------
class SourceModel(FlatBaseModel):
def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING, search=None,
skip=set(), sort_map=None):
def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
search=None, skip=set(), sort_map=None):
self.map = db.get_raw_source_data
self.gen_cursor = db.get_source_cursor
self.fmap = [
@ -75,8 +75,8 @@ class SourceModel(FlatBaseModel):
self.sort_change,
self.column_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search, skip=skip,
sort_map=sort_map)
FlatBaseModel.__init__(self, db, uistate, scol, order, search=search,
skip=skip, sort_map=sort_map)
def destroy(self):
"""

View File

@ -274,12 +274,9 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
secondary object type.
"""
def __init__(self, db,
search=None, skip=set(),
scol=0, order=Gtk.SortType.ASCENDING, sort_map=None,
nrgroups = 1,
group_can_have_handle = False,
has_secondary=False):
def __init__(self, db, uistate, search=None, skip=set(), scol=0,
order=Gtk.SortType.ASCENDING, sort_map=None, nrgroups = 1,
group_can_have_handle = False, has_secondary=False):
cput = time.clock()
GObject.GObject.__init__(self)
BaseModel.__init__(self)
@ -295,6 +292,7 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
self.prev_handle = None
self.prev_data = None
self.uistate = uistate
self.__reverse = (order == Gtk.SortType.DESCENDING)
self.scol = scol
self.nrgroups = nrgroups
@ -530,11 +528,11 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
Rebuild the data map for a single Gramps object type, where a search
condition is applied.
"""
pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
popup_time=2)
status = progressdlg.LongOpStatus(msg=_("Building View"),
total_steps=items, interval=items//20,
can_cancel=True)
pmon = progressdlg.ProgressMonitor(
progressdlg.StatusProgress, (self.uistate,), popup_time=2,
title=_("Loading items..."))
status = progressdlg.LongOpStatus(total_steps=items,
interval=items // 20)
pmon.add_op(status)
with gen_cursor() as cursor:
for handle, data in cursor:
@ -542,16 +540,13 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
if not isinstance(handle, str):
handle = handle.decode('utf-8')
status.heartbeat()
if status.should_cancel():
break
self.__total += 1
if not (handle in skip or (dfilter and not
dfilter.match(handle, self.db))):
_LOG.debug(" add %s %s" % (handle, data))
self.__displayed += 1
add_func(handle, data)
if not status.was_cancelled():
status.end()
status.end()
def _rebuild_filter(self, dfilter, dfilter2, skip):
"""
@ -581,28 +576,29 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
Rebuild the data map for a single Gramps object type, where a filter
is applied.
"""
pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
popup_time=2)
status = progressdlg.LongOpStatus(msg=_("Building View"),
total_steps=3, interval=1)
pmon.add_op(status)
status_ppl = progressdlg.LongOpStatus(msg=_("Loading items..."),
total_steps=items, interval=items//10)
pmon = progressdlg.ProgressMonitor(
progressdlg.StatusProgress, (self.uistate,), popup_time=2,
title=_("Loading items..."))
status_ppl = progressdlg.LongOpStatus(total_steps=items,
interval=items // 20)
pmon.add_op(status_ppl)
self.__total += items
assert not skip
if dfilter:
for handle in dfilter.apply(self.db,
cb_progress=status_ppl.heartbeat):
data = data_map(handle)
add_func(handle, data)
self.__displayed += 1
else:
with gen_cursor() as cursor:
for handle, data in cursor:
status_ppl.heartbeat()
add_func(handle, data)
self.__displayed += 1
with gen_cursor() as cursor:
for handle, data in cursor:
if not isinstance(handle, str):
handle = handle.decode('utf-8')
status_ppl.heartbeat()
if not handle in skip:
if not dfilter or dfilter.match(handle, self.db):
add_func(handle, data)
self.__displayed += 1
status_ppl.end()
status.end()
def add_node(self, parent, child, sortkey, handle, add_parent=True,
secondary=False):

View File

@ -591,6 +591,118 @@ class GtkProgressDialog(Gtk.Dialog):
def close(self):
self.destroy()
#-------------------------------------------------------------------------
#
# Gramps main status bar Progress indicator
#
#-------------------------------------------------------------------------
class StatusProgress:
"""
A gtk progress in main Gramps window status bar to display the status
of a long running process.
"""
def __init__(self, window_params, title):
"""
:param title: The title to display on the top of the window.
:type title: string
"""
# self.set_title(title)
self.uistate = window_params[0]
self.title = title
self._old_val = -1
self._progress_bars = False
def add(self, long_op_status):
"""
Add a new status object to the statusbar progress.
:param long_op_status: the status object.
:type long_op_status: :class:`.LongOpStatus`
:returns: a key that can be used as the ``pbar_idx`` to the other
methods.
:rtype: int
"""
assert(not self._progress_bars)
self._pbar = self.uistate.progress
self._pbar_max = (long_op_status.get_total_steps() /
long_op_status.get_interval())
self._pbar_index = 0.0
self._pbar.set_fraction(
((100 / float(long_op_status.get_total_steps()) *
float(long_op_status.get_interval()))) / 100.0)
self.uistate.status.push(
self.uistate.status_id, self.title)
self._pbar.show()
return True
def remove(self, pbar_idx):
"""
Remove the specified status object from the progress dialog.
:param pbar_idx: the index as returned from :meth:`add` (not used)
:type pbar_idx: int
"""
self._progress_bars = False
self._pbar.hide()
def step(self, pbar_idx):
"""
Click the progress bar over to the next value. Be paranoid
and insure that it doesn't go over 100%.
:param pbar_idx: the index as returned from :meth:`add` (not used)
:type pbar_idx: int
"""
self._pbar_index = self._pbar_index + 1.0
if self._pbar_index > self._pbar_max:
self._pbar_index = self._pbar_max
try:
val = int(100 * self._pbar_index / self._pbar_max)
except ZeroDivisionError:
val = 0
if val != self._old_val:
self._pbar.set_text("%d%%" % val)
self._pbar.set_fraction(val / 100.0)
self._pbar.old_val = val
self._process_events()
def _process_events(self):
while Gtk.events_pending():
Gtk.main_iteration()
def show(self):
"""
Show the dialog and process any events.
"""
self._pbar.show()
self._process_events()
def hide(self):
"""
Hide the dialog and process any events.
"""
self._pbar.hide()
self.uistate.status.pop(
self.uistate.status_id)
self._process_events()
def _warn(self, x, y):
return True
def close(self):
# self.destroy()
pass
if __name__ == '__main__':
def test(a, b):

View File

@ -128,6 +128,8 @@ class DBAPI(DbGeneric):
"""
Create and update schema.
"""
self.dbapi.begin()
# make sure schema is up to date:
self.dbapi.execute('CREATE TABLE person '
'('
@ -261,6 +263,7 @@ class DBAPI(DbGeneric):
self.dbapi.execute('CREATE INDEX reference_obj_handle '
'ON reference(obj_handle)')
self.dbapi.commit()
def _close(self):
self.dbapi.close()

View File

@ -909,7 +909,7 @@ class GeneWebParser:
LOG.warning(_(
"Invalid date {date} in {gw_snippet}, "
"preserving date as text."
).format(date=e.date.to_struct(), gw_snippet=field))
).format(date=e.date.__dict__, gw_snippet=field))
date.set(modifier=Date.MOD_TEXTONLY, text=field)
return date
else:

View File

@ -2499,7 +2499,7 @@ class GrampsParser(UpdateCallback):
# TRANSLATORS: leave the {date} and {xml} untranslated in the format string,
# but you may re-order them if needed.
LOG.warning(_("Invalid date {date} in XML {xml}, preserving XML as text"
).format(date=date_error.date.to_struct(), xml=xml))
).format(date=date_error.date.__dict__, xml=xml))
date_value.set(modifier=Date.MOD_TEXTONLY, text=xml)
def start_datestr(self, attrs):

View File

@ -207,7 +207,7 @@ refitems = [(CATEGORY_QR_PERSON, 'person', _("Person")),
(CATEGORY_QR_MEDIA, 'media', _("Media")),
(CATEGORY_QR_NOTE, 'note', _("Note")),
(CATEGORY_QR_CITATION, 'citation', _("Citation")),
(CATEGORY_QR_SOURCE_OR_CITATION, 'source or citation',
(CATEGORY_QR_SOURCE_OR_CITATION, 'source_or_citation',
_("Source or Citation"))
]

View File

@ -30,7 +30,7 @@ from unittest.mock import patch
#import logging
from gramps.gen.db.utils import import_as_dict
from gramps.gen.merge.diff import diff_dbs
from gramps.gen.merge.diff import diff_dbs, to_struct
from gramps.gen.simple import SimpleAccess
from gramps.gen.utils.id import set_det_id
from gramps.cli.user import User
@ -75,8 +75,8 @@ class CompleteCheck(unittest.TestCase):
if diffs:
for diff in diffs:
obj_type, item1, item2 = diff
msg = self._report_diff(obj_type, item1.to_struct(),
item2.to_struct())
msg = self._report_diff(obj_type, to_struct(item1),
to_struct(item2))
if msg != "":
if hasattr(item1, "gramps_id"):
self.msg += "%s: %s handle=%s\n" % \

View File

@ -116,7 +116,7 @@ def cross_table_duplicates(db, uistate):
parent = uistate.window
else:
parent = None
progress = ProgressMeter(_('Checking Database'), '', parent)
progress = ProgressMeter(_('Checking Database'), '', parent=parent)
progress.set_pass(_('Looking for cross table duplicates'), 9)
logging.info('Looking for cross table duplicates')
total_nr_handles = 0

View File

@ -24,12 +24,23 @@
Tools/Debug/Dump Gender Statistics
"""
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gi.repository import Gtk
from gramps.gui.listmodel import ListModel, INTEGER
from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.plug import tool
_GENDER = [ _('female'), _('male'), _('unknown') ]
@ -45,9 +56,6 @@ class DumpGenderStats(tool.Tool, ManagedWindow):
uistate = user.uistate
self.label = _("Gender Statistics tool")
tool.Tool.__init__(self, dbstate, options_class, name)
if uistate:
ManagedWindow.__init__(self,uistate,[],
self.__class__)
stats_list = []
for name, value in dbstate.db.genderStats.stats.items():
@ -58,33 +66,51 @@ class DumpGenderStats(tool.Tool, ManagedWindow):
)
if uistate:
titles = [
(_('Name'),0,100),
(_('Male'),1,70,INTEGER),
(_('Female'),2,70,INTEGER),
(_('Unknown'),3,70,INTEGER),
(_('Guess'),4,70)
]
ManagedWindow.__init__(self, uistate, [], self.__class__)
titles = [(_('Name'), 0, 100),
(_('Male'), 1, 70, INTEGER),
(_('Female'), 2, 70, INTEGER),
(_('Unknown'), 3, 90, INTEGER),
(_('Guess'), 4, 70)]
treeview = Gtk.TreeView()
model = ListModel(treeview, titles)
for entry in sorted(stats_list):
model.add(entry, entry[0])
window = Gtk.Window() # TODO there needs to be a way to "close" it
s = Gtk.ScrolledWindow()
s.add(treeview)
window.add(s)
window.show_all()
self.set_window(window, None, self.label)
self.setup_configs('interface.dumpgenderstats', 400, 300)
dialog = Gtk.Dialog()
dialog.add_button(_('_Close'), Gtk.ResponseType.CLOSE)
dialog.connect('response', self._response)
dialog.vbox.pack_start(s, expand=True, fill=True, padding=0)
self.set_window(dialog, None, self.label)
self.setup_configs('interface.dumpgenderstats', 420, 300)
self.show()
else:
print('\t%s'*5 % ('Name','Male','Female','Unknown','Guess'))
if len(_('Name')) < 16:
print('%s%s%s' % (_('Name'),
" " * (16 - len(_('Name'))),
_('Male')),
'\t%s'*3 % (_('Female'), _('Unknown'), _('Guess')))
else:
print(_('Name'), '\t%s'*4 % (_('Male'), _('Female'),
_('Unknown'), _('Guess')))
print()
for entry in stats_list:
print('\t%s'*5 % entry)
for entry in sorted(stats_list):
if len(entry[0]) < 16:
print('%s%s%s' % (entry[0],
" " * (16 - len(entry[0])),
entry[1]),
'\t%s'*3 % (entry[2:]))
else:
print(entry[0], '\t%s'*4 % (entry[1:]))
def _response(self, obj, response_id):
if response_id == Gtk.ResponseType.CLOSE:
self.close()
def build_menu_names(self, obj):
return (self.label,None)

View File

@ -57,6 +57,7 @@ from gramps.gen.utils.file import media_path_full, relative_path, media_path
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from gramps.gen.mime import get_type, is_image_type
from gramps.gui.managedwindow import ManagedWindow
#-------------------------------------------------------------------------
#
@ -71,23 +72,24 @@ WIKI_HELP_SEC = _('manual|Media_Manager...')
# This is an Assistant implementation to guide the user
#
#-------------------------------------------------------------------------
class MediaMan(tool.Tool):
class MediaMan(ManagedWindow, tool.Tool):
def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate
tool.Tool.__init__(self, dbstate, options_class, name)
self.uistate = uistate
ManagedWindow.__init__(self, uistate, [], self.__class__)
self.callback = uistate.pulse_progressbar
self.batch_ops = []
self.build_batch_ops()
self.assistant = Gtk.Assistant()
self.set_window(self.assistant, None, _('Media Manager'))
self.setup_configs('interface.mediaman', 780, 600)
self.assistant.set_title(_('Gramps Media Manager'))
self.assistant.connect('close', self.close)
self.assistant.connect('cancel', self.close)
self.assistant.connect('close', self.do_close)
self.assistant.connect('cancel', self.do_close)
self.assistant.connect('apply', self.run)
self.assistant.connect('prepare', self.prepare)
@ -104,14 +106,21 @@ class MediaMan(tool.Tool):
self.conclusion = ConclusionPage(self.assistant)
self.add_page(self.conclusion, Gtk.AssistantPageType.SUMMARY)
self.assistant.show()
self.show()
self.assistant.set_forward_page_func(self.forward_page, None)
def close(self, assistant):
def build_menu_names(self, obj):
"""Override :class:`.ManagedWindow` method."""
return (_('Media Manager'), None)
def do_close(self, assistant):
"""
Close the assistant.
"""
position = self.window.get_position() # crock
self.assistant.hide()
self.window.move(position[0], position[1])
self.close()
def forward_page(self, page, data):
"""

View File

@ -164,6 +164,7 @@ gramps/gen/lib/repo.py
gramps/gen/lib/reporef.py
gramps/gen/lib/researcher.py
gramps/gen/lib/secondaryobj.py
gramps/gen/lib/serialize.py
gramps/gen/lib/src.py
gramps/gen/lib/srcbase.py
gramps/gen/lib/srcref.py

356
po/ru.po

File diff suppressed because it is too large Load Diff