Skip to content

Commit

Permalink
Removed unneeded properties on primary objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Oct 13, 2024
1 parent 99b3d2b commit a9da731
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 166 deletions.
45 changes: 18 additions & 27 deletions gramps/gen/lib/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def __init__(self, source=None):
PlaceBase.__init__(self, source)

if source:
self.__description = source.description
self.__type = EventType(source.type)
self.description = source.description
self.type = EventType(source.type)
else:
self.__description = ""
self.__type = EventType()
self.description = ""
self.type = EventType()

def serialize(self, no_text_date=False):
"""
Expand All @@ -123,9 +123,9 @@ def serialize(self, no_text_date=False):
return (
self.handle,
self.gramps_id,
self.__type.serialize(),
self.type.serialize(),
DateBase.serialize(self, no_text_date),
self.__description,
self.description,
self.place,
CitationBase.serialize(self),
NoteBase.serialize(self),
Expand Down Expand Up @@ -215,7 +215,7 @@ def unserialize(self, data):
self.gramps_id,
the_type,
date,
self.__description,
self.description,
self.place,
citation_list,
note_list,
Expand All @@ -226,8 +226,8 @@ def unserialize(self, data):
self.private,
) = data

self.__type = EventType()
self.__type.unserialize(the_type)
self.type = EventType()
self.type.unserialize(the_type)
DateBase.unserialize(self, date)
MediaBase.unserialize(self, media_list)
AttributeBase.unserialize(self, attribute_list)
Expand Down Expand Up @@ -286,7 +286,7 @@ def get_text_data_list(self):
:returns: Returns the list of all textual attributes of the object.
:rtype: list
"""
return [self.__description, str(self.__type), self.gramps_id]
return [self.description, str(self.type), self.gramps_id]

def get_text_data_child_list(self):
"""
Expand Down Expand Up @@ -353,8 +353,8 @@ def is_empty(self):
"""
date = self.get_date_object()
place = self.get_place_handle()
description = self.__description
the_type = self.__type
description = self.description
the_type = self.type
return (
the_type == EventType.CUSTOM
and date.is_empty()
Expand All @@ -375,9 +375,9 @@ def are_equal(self, other):
other = Event(None)

if (
self.__type != other.type
self.type != other.type
or ((self.place or other.place) and (self.place != other.place))
or self.__description != other.description
or self.description != other.description
or self.private != other.private
or (not self.get_date_object().is_equal(other.get_date_object()))
or len(self.get_citation_list()) != len(other.get_citation_list())
Expand Down Expand Up @@ -417,7 +417,7 @@ def set_type(self, the_type):
:param the_type: Type to assign to the Event
:type the_type: tuple
"""
self.__type.set(the_type)
self.type.set(the_type)

def get_type(self):
"""
Expand All @@ -426,9 +426,7 @@ def get_type(self):
:returns: Type of the Event
:rtype: tuple
"""
return self.__type

type = property(get_type, set_type, None, "Returns or sets type of the event")
return self.type

def set_description(self, description):
"""
Expand All @@ -439,7 +437,7 @@ def set_description(self, description):
:param description: Description to assign to the Event
:type description: str
"""
self.__description = description
self.description = description

def get_description(self):
"""
Expand All @@ -448,11 +446,4 @@ def get_description(self):
:returns: Returns the description of the Event
:rtype: str
"""
return self.__description

description = property(
get_description,
set_description,
None,
"Returns or sets description of the event",
)
return self.description
18 changes: 8 additions & 10 deletions gramps/gen/lib/eventref.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def __init__(self, source=None):
AttributeBase.__init__(self, source)
RefBase.__init__(self, source)
if source:
self.__role = EventRoleType(source.role)
self.role = EventRoleType(source.role)
else:
self.__role = EventRoleType()
self.role = EventRoleType()

def serialize(self):
"""
Expand All @@ -83,7 +83,7 @@ def serialize(self):
NoteBase.serialize(self),
AttributeBase.serialize(self),
RefBase.serialize(self),
self.__role.serialize(),
self.role.serialize(),
)

@classmethod
Expand Down Expand Up @@ -133,8 +133,8 @@ def unserialize(self, data):
NoteBase.unserialize(self, note_list)
AttributeBase.unserialize(self, attribute_list)
RefBase.unserialize(self, ref)
self.__role = EventRoleType()
self.__role.unserialize(role)
self.role = EventRoleType()
self.role.unserialize(role)
return self

def get_text_data_list(self):
Expand All @@ -144,7 +144,7 @@ def get_text_data_list(self):
:returns: Returns the list of all textual attributes of the object.
:rtype: list
"""
return [self.__role.string]
return [self.role.string]

def get_text_data_child_list(self):
"""
Expand Down Expand Up @@ -235,12 +235,10 @@ def get_role(self):
"""
Return the tuple corresponding to the preset role.
"""
return self.__role
return self.role

def set_role(self, role):
"""
Set the role according to the given argument.
"""
self.__role.set(role)

role = property(get_role, set_role, None, "Returns or sets role property")
self.role.set(role)
109 changes: 53 additions & 56 deletions gramps/gen/lib/grampstype.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@ class GrampsType(metaclass=GrampsTypeMeta):
__slots__ = ("__value", "__string")

def __getstate__(self):
return {"__value": self.__value, "__string": self.__string}
return {"__value": self.value, "__string": self.string}

def __setstate__(self, dict_):
self.__value = dict_["__value"]
if self.__value == self._CUSTOM:
self.__string = dict_["__string"]
self.value = dict_["__value"]
if self.value == self._CUSTOM:
self.string = dict_["__string"]
else:
self.__string = ""
self.string = ""

def __init__(self, value=None):
"""
Create a new type, initialize the value from one of several possible
states.
"""
self.__value = self._DEFAULT
self.__string = ""
self.value = self._DEFAULT
self.string = ""
if value is not None:
self.set(value)

Expand All @@ -143,29 +143,29 @@ def __set_tuple(self, value):
val = value[0]
if len(value) > 1 and val == self._CUSTOM:
strg = value[1]
self.__value = val
self.__string = strg
self.value = val
self.string = strg

def __set_int(self, value):
"Set the value/string properties from an integer."
self.__value = value
self.__string = ""
self.value = value
self.string = ""

def __set_instance(self, value):
"Set the value/string properties from another grampstype."
self.__value = value.value
if self.__value == self._CUSTOM:
self.__string = value.string
self.value = value.value
if self.value == self._CUSTOM:
self.string = value.string
else:
self.__string = ""
self.string = ""

def __set_str(self, value):
"Set the value/string properties from a string."
self.__value = self._S2IMAP.get(value, self._CUSTOM)
if self.__value == self._CUSTOM:
self.__string = value
self.value = self._S2IMAP.get(value, self._CUSTOM)
if self.value == self._CUSTOM:
self.string = value
else:
self.__string = ""
self.string = ""

def set(self, value):
"Set the value/string properties from the passed in value."
Expand All @@ -178,39 +178,39 @@ def set(self, value):
elif isinstance(value, str):
self.__set_str(value)
else:
self.__value = self._DEFAULT
self.__string = ""
self.value = self._DEFAULT
self.string = ""

def set_from_xml_str(self, value):
"""
This method sets the type instance based on the untranslated string
(obtained e.g. from XML).
"""
if value in self._E2IMAP:
self.__value = self._E2IMAP[value]
self.__string = ""
if self.__value == self._CUSTOM:
self.value = self._E2IMAP[value]
self.string = ""
if self.value == self._CUSTOM:
# if the custom event is actually 'Custom' then we should save it
# with that string value. That is, 'Custom' is in _E2IMAP
self.__string = value
self.string = value
else:
self.__value = self._CUSTOM
self.__string = value
self.value = self._CUSTOM
self.string = value

def xml_str(self):
"""
Return the untranslated string (e.g. suitable for XML) corresponding
to the type.
"""
if self.__value == self._CUSTOM:
return self.__string
if self.__value in self._I2EMAP:
return self._I2EMAP[self.__value]
if self.value == self._CUSTOM:
return self.string
if self.value in self._I2EMAP:
return self._I2EMAP[self.value]
return _UNKNOWN

def serialize(self):
"""Convert the object to a serialized tuple of data."""
return (self.__value, self.__string)
return (self.value, self.string)

@classmethod
def get_schema(cls):
Expand All @@ -231,18 +231,18 @@ def get_schema(cls):

def unserialize(self, data):
"""Convert a serialized tuple of data to an object."""
self.__value, self.__string = data
if self.__value != self._CUSTOM:
self.__string = ""
self.value, self.string = data
if self.value != self._CUSTOM:
self.string = ""
return self

def __str__(self):
if self.__value == self._CUSTOM:
return self.__string
return self._I2SMAP.get(self.__value, _UNKNOWN)
if self.value == self._CUSTOM:
return self.string
return self._I2SMAP.get(self.value, _UNKNOWN)

def __int__(self):
return self.__value
return self.value

def get_map(self):
return self._I2SMAP
Expand All @@ -265,11 +265,11 @@ def get_standard_xml(self):

def is_custom(self):
"""Return true if custom type."""
return self.__value == self._CUSTOM
return self.value == self._CUSTOM

def is_default(self):
"""Return true if default type."""
return self.__value == self._DEFAULT
return self.value == self._DEFAULT

def get_custom(self):
"""Return custom type."""
Expand All @@ -287,24 +287,21 @@ def get_menu_standard_xml(self):

def __eq__(self, value):
if isinstance(value, int):
return self.__value == value
return self.value == value
if isinstance(value, str):
if self.__value == self._CUSTOM:
return self.__string == value
return self._I2SMAP.get(self.__value) == value
if self.value == self._CUSTOM:
return self.string == value
return self._I2SMAP.get(self.value) == value
if isinstance(value, tuple):
if self.__value == self._CUSTOM:
return (self.__value, self.__string) == value
return self.__value == value[0]

if value.value == self._CUSTOM and self.__value == self._CUSTOM:
return self.__string == value.string
if self._CUSTOM not in [value.value, self.__value]:
return self.__value == value.value
if self.value == self._CUSTOM:
return (self.value, self.string) == value
return self.value == value[0]

if value.value == self._CUSTOM and self.value == self._CUSTOM:
return self.string == value.string
if self._CUSTOM not in [value.value, self.value]:
return self.value == value.value
return False

def __ne__(self, value):
return not self.__eq__(value)

value = property(__int__, __set_int, None, "Returns or sets integer value")
string = property(__str__, __set_str, None, "Returns or sets string value")
Loading

0 comments on commit a9da731

Please sign in to comment.