Merge pull request #197 from prculley/FTM_photo_42

Bug (Feature) 9580 Gedcom import of FTM file containing _PHOTO tags
This commit is contained in:
Doug Blank 2016-07-16 11:23:15 -04:00 committed by GitHub
commit 3e21084f02

View File

@ -268,6 +268,7 @@ TOKEN__MAR = 128
TOKEN__MARN = 129 TOKEN__MARN = 129
TOKEN__ADPN = 130 TOKEN__ADPN = 130
TOKEN__FSFTID = 131 TOKEN__FSFTID = 131
TOKEN__PHOTO = 132
TOKENS = { TOKENS = {
"HEAD" : TOKEN_HEAD, "MEDI" : TOKEN_MEDI, "HEAD" : TOKEN_HEAD, "MEDI" : TOKEN_MEDI,
@ -374,6 +375,7 @@ TOKENS = {
"_URL" : TOKEN_URL, "URL" : TOKEN_URL, "_URL" : TOKEN_URL, "URL" : TOKEN_URL,
"_MAR" : TOKEN__MAR, "_MARN" : TOKEN__MARN, "_MAR" : TOKEN__MAR, "_MARN" : TOKEN__MARN,
"_ADPN" : TOKEN__ADPN, "_FSFTID" : TOKEN__FSFTID, "_ADPN" : TOKEN__ADPN, "_FSFTID" : TOKEN__FSFTID,
"_PHOTO" : TOKEN__PHOTO,
} }
ADOPT_NONE = 0 ADOPT_NONE = 0
@ -1624,6 +1626,7 @@ class CurrentState(object):
self.repo_ref = None self.repo_ref = None
self.place = None self.place = None
self.media = None self.media = None
self.photo = "" # Person primary photo
def __getattr__(self, name): def __getattr__(self, name):
""" """
@ -2089,6 +2092,7 @@ class GedcomParser(UpdateCallback):
TOKEN_URL : self.__person_url, TOKEN_URL : self.__person_url,
TOKEN__TODO : self.__skip_record, TOKEN__TODO : self.__skip_record,
TOKEN_TITL : self.__person_titl, TOKEN_TITL : self.__person_titl,
TOKEN__PHOTO: self.__person_photo,
} }
self.func_list.append(self.indi_parse_tbl) self.func_list.append(self.indi_parse_tbl)
@ -3597,6 +3601,9 @@ class GedcomParser(UpdateCallback):
# Add a default tag if provided # Add a default tag if provided
self.__add_default_tag(person) self.__add_default_tag(person)
# Set up primary photo if present
self.__do_photo(state)
self.__check_msgs(_("INDI (individual) Gramps ID %s") % self.__check_msgs(_("INDI (individual) Gramps ID %s") %
person.get_gramps_id(), state, person) person.get_gramps_id(), state, person)
# commit the person to the database # commit the person to the database
@ -3799,6 +3806,13 @@ class GedcomParser(UpdateCallback):
self.__add_msg(_("Form omitted"), line, state) self.__add_msg(_("Form omitted"), line, state)
self.build_media_object(state.person, form, filename, title, note) self.build_media_object(state.person, form, filename, title, note)
def __person_photo(self, line, state):
"""
This handles the FTM _PHOTO feature, which identifies an OBJE to use
as the person's primary photo.
"""
state.photo = line.data # Just save it for now.
def __person_name(self, line, state): def __person_name(self, line, state):
""" """
Parsers the NAME token in a GEDCOM file. The text is in the format Parsers the NAME token in a GEDCOM file. The text is in the format
@ -7652,6 +7666,30 @@ class GedcomParser(UpdateCallback):
event_ref.set_reference_handle(event.handle) event_ref.set_reference_handle(event.handle)
return event_ref return event_ref
def __do_photo(self, state):
"""
Choose the primary photo from the list of media present for this
person. Supports FTM _PHOTO feature.
0 INDI
+1 _PHOTO @<XREF:OBJE>@ {1:1}
Since Gramps currently uses the first media in the list as the
primary, find the primary photo if already in the list, if present,
move to beginning. If not present, add at the beginning.
This is run after all of the person processing is complete but before
committing the person.
"""
if state.photo:
gramps_id = self.oid_map[state.photo]
handle = self.__find_object_handle(gramps_id)
for mref in state.person.media_list:
if handle == mref.ref:
state.person.media_list.remove(mref)
state.person.media_list.insert(0, mref)
return
mref = MediaRef()
mref.set_reference_handle(handle)
state.person.media_list.insert(0, mref)
def __extract_temple(self, line): def __extract_temple(self, line):
def get_code(code): def get_code(code):
if TEMPLES.is_valid_code(code): if TEMPLES.is_valid_code(code):