def write_people(self): """ write the people """ self.doc.add_comment('') # If we're going to attempt to include images, then use the HTML style # of .gv file. use_html_output = False if self._incimages: use_html_output = True # loop through all the people we need to output for handle in sorted(self._people): # enable a diff person = self._db.get_person_from_handle(handle) name = self._name_display.display(person) p_id = person.get_gramps_id() # figure out what colour to use gender = person.get_gender() colour = self._colorunknown if gender == Person.MALE: colour = self._colormales elif gender == Person.FEMALE: colour = self._colorfemales # see if we have surname colours that match this person surname = person.get_primary_name().get_surname() surname = surname.encode('iso-8859-1', 'xmlcharrefreplace') if surname in self._surnamecolors: colour = self._surnamecolors[surname] # see if we have a birth/death or fallback dates we can use if self._incdates or self._incplaces: bth_event = get_birth_or_fallback(self._db, person) dth_event = get_death_or_fallback(self._db, person) else: bth_event = None dth_event = None # output the birth or fallback event birth_str = None if bth_event and self._incdates: date = bth_event.get_date_object() if self._just_years and date.get_year_valid(): birth_str = self._get_date( # localized year Date(date.get_year())) else: birth_str = self._get_date(date) # get birth place (one of: hamlet, village, town, city, parish, # county, province, region, state or country) birthplace = None if bth_event and self._incplaces: birthplace = self.get_event_place(bth_event) # see if we have a deceased date we can use death_str = None if dth_event and self._incdates: date = dth_event.get_date_object() if self._just_years and date.get_year_valid(): death_str = self._get_date( # localized year Date(date.get_year())) else: death_str = self._get_date(date) # get death place (one of: hamlet, village, town, city, parish, # county, province, region, state or country) deathplace = None if dth_event and self._incplaces: deathplace = self.get_event_place(dth_event) # see if we have an image to use for this person image_path = None if self._incimages: media_list = person.get_media_list() if len(media_list) > 0: media_handle = media_list[0].get_reference_handle() media = self._db.get_media_from_handle(media_handle) media_mime_type = media.get_mime_type() if media_mime_type[0:5] == "image": image_path = get_thumbnail_path( media_path_full(self._db, media.get_path()), rectangle=media_list[0].get_rectangle(), size=self._imagesize) # put the label together and output this person label = "" line_delimiter = '\\n' if use_html_output: line_delimiter = '<BR/>' # if we have an image, then start an HTML table; # remember to close the table afterwards! if image_path: label = ('<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" ' 'CELLBORDER="0"><TR><TD><IMG SRC="%s"/></TD>' % image_path) if self._imageonside == 0: label += '</TR><TR>' label += '<TD>' # at the very least, the label must have the person's name name = name.replace('"', '"') label += name.replace('<', '<').replace('>', '>') if self.includeid == 1: # same line label += " (%s)" % p_id elif self.includeid == 2: # own line label += "%s(%s)" % (line_delimiter, p_id) if birth_str or death_str: label += '%s(' % line_delimiter if birth_str: label += '%s' % birth_str label += ' – ' if death_str: label += '%s' % death_str label += ')' if birthplace or deathplace: if birthplace == deathplace: deathplace = None # no need to print the same name twice label += '%s' % line_delimiter if birthplace: label += '%s' % birthplace if birthplace and deathplace: label += ' / ' if deathplace: label += '%s' % deathplace # see if we have a table that needs to be terminated if image_path: label += '</TD></TR></TABLE>' else: # non html label is enclosed by "" so escape other " label = label.replace('"', '\\\"') shape = "box" style = "solid" border = colour fill = colour # do not use colour if this is B&W outline if self._colorize == 'outline': border = "" fill = "" if gender == person.FEMALE and ("f" in self._useroundedcorners): style = "rounded" elif gender == person.MALE and ("m" in self._useroundedcorners): style = "rounded" elif gender == person.UNKNOWN: shape = "hexagon" # if we're filling the entire node: if self._colorize == 'filled': style += ",filled" border = "" # we're done -- add the node self.doc.add_node(p_id, label=label, shape=shape, color=border, style=style, fillcolor=fill, htmloutput=use_html_output)
def get_person_label(self, person): "return person label string" # see if we have an image to use for this person image_path = None if self.use_html_output: media_list = person.get_media_list() if len(media_list) > 0: media_handle = media_list[0].get_reference_handle() media = self._db.get_media_from_handle(media_handle) media_mime_type = media.get_mime_type() if media_mime_type[0:5] == "image": image_path = get_thumbnail_path( media_path_full(self._db, media.get_path()), rectangle=media_list[0].get_rectangle()) # test if thumbnail actually exists in thumbs # (import of data means media files might not be present image_path = find_file(image_path) label = "" line_delimiter = '\\n' # If we have an image, then start an HTML table; remember to close # the table afterwards! # # This isn't a free-form HTML format here...just a few keywords that # happen to be # similar to keywords commonly seen in HTML. For additional # information on what # is allowed, see: # # http://www.graphviz.org/info/shapes.html#html # if self.use_html_output and image_path: line_delimiter = '<BR/>' label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" ' label += 'CELLBORDER="0"><TR><TD></TD><TD>' label += '<IMG SRC="%s"/></TD><TD></TD>' % image_path if self.imgpos == 0: #trick it into not stretching the image label += '</TR><TR><TD COLSPAN="3">' else: label += '<TD>' else: #no need for html label with this person self.use_html_output = False # at the very least, the label must have the person's name p_name = self._name_display.display(person) if self.use_html_output: # avoid < and > in the name, as this is html text label += p_name.replace('<', '<').replace('>', '>') else: label += p_name p_id = person.get_gramps_id() if self.includeid == 1: # same line label += " (%s)" % p_id elif self.includeid == 2: # own line label += "%s(%s)" % (line_delimiter, p_id) if self.event_choice != 0: b_date, d_date, b_place, d_place, b_type, d_type = \ self.get_event_strings(person) if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date): label += '%s(' % line_delimiter if b_date: label += '%s' % b_date label += ' - ' if d_date: label += '%s' % d_date label += ')' if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place) and not (self.event_choice == 3 and (b_date or d_date)) ): label += '%s(' % line_delimiter if b_place: label += '%s' % b_place label += ' - ' if d_place: label += '%s' % d_place label += ')' if self.event_choice == 7: if b_type: label += '%s%s' % (line_delimiter, b_type.get_abbreviation()) if b_date: label += ' %s' % b_date if b_place: label += ' %s' % b_place if d_type: label += '%s%s' % (line_delimiter, d_type.get_abbreviation()) if d_date: label += ' %s' % d_date if d_place: label += ' %s' % d_place if self.increlname and self.center_person != person: # display relationship info if self.advrelinfo: (relationship, _ga, _gb) = self.rel_calc.get_one_relationship( self._db, self.center_person, person, extra_info=True, olocale=self._locale) if relationship: label += "%s(%s Ga=%d Gb=%d)" % (line_delimiter, relationship, _ga, _gb) else: relationship = self.rel_calc.get_one_relationship( self._db, self.center_person, person, olocale=self._locale) if relationship: label += "%s(%s)" % (line_delimiter, relationship) if self.occupation > 0: event_refs = person.get_primary_event_ref_list() events = [event for event in [self._db.get_event_from_handle(ref.ref) for ref in event_refs] if event.get_type() == EventType(EventType.OCCUPATION)] if len(events) > 0: events.sort(key=lambda x: x.get_date_object()) if self.occupation == 1: occupation = events[-1].get_description() if occupation: label += "%s(%s)" % (line_delimiter, occupation) elif self.occupation == 2: for evt in events: date = self.get_date_string(evt) place = self.get_place_string(evt) desc = evt.get_description() if not date and not desc and not place: continue label += '%s(' % line_delimiter if date: label += '%s' % date if desc: label += ' ' if desc: label += '%s' % desc if place: if date or desc: label += self._(', ') # Arabic OK label += '%s' % place label += ')' # see if we have a table that needs to be terminated if self.use_html_output: label += '</TD></TR></TABLE>' return label else: # non html label is enclosed by "" so escape other " return label.replace('"', '\\\"')
def get_person_label(self, person): "return person label string" # see if we have an image to use for this person image_path = None if self.use_html_output: media_list = person.get_media_list() if len(media_list) > 0: media_handle = media_list[0].get_reference_handle() media = self._db.get_media_from_handle(media_handle) media_mime_type = media.get_mime_type() if media_mime_type[0:5] == "image": image_path = get_thumbnail_path( media_path_full(self._db, media.get_path()), rectangle=media_list[0].get_rectangle()) # test if thumbnail actually exists in thumbs # (import of data means media files might not be present image_path = find_file(image_path) label = "" line_delimiter = '\\n' # If we have an image, then start an HTML table; remember to close # the table afterwards! # # This isn't a free-form HTML format here...just a few keywords that # happen to be # similar to keywords commonly seen in HTML. For additional # information on what # is allowed, see: # # http://www.graphviz.org/info/shapes.html#html # if self.use_html_output and image_path: line_delimiter = '<BR/>' label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" ' label += 'CELLBORDER="0"><TR><TD></TD><TD>' label += '<IMG SRC="%s"/></TD><TD></TD>' % image_path if self.imgpos == 0: #trick it into not stretching the image label += '</TR><TR><TD COLSPAN="3">' else: label += '<TD>' else: #no need for html label with this person self.use_html_output = False # at the very least, the label must have the person's name p_name = self._name_display.display(person) if self.use_html_output: # avoid < and > in the name, as this is html text label += p_name.replace('<', '<').replace('>', '>') else: label += p_name p_id = person.get_gramps_id() if self.includeid == 1: # same line label += " (%s)" % p_id elif self.includeid == 2: # own line label += "%s(%s)" % (line_delimiter, p_id) if self.event_choice != 0: b_date, d_date, b_place, d_place, b_type, d_type = \ self.get_event_strings(person) if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date): label += '%s(' % line_delimiter if b_date: label += '%s' % b_date label += ' - ' if d_date: label += '%s' % d_date label += ')' if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place) and not (self.event_choice == 3 and (b_date or d_date))): label += '%s(' % line_delimiter if b_place: label += '%s' % b_place label += ' - ' if d_place: label += '%s' % d_place label += ')' if self.event_choice == 7: if b_type: label += '%s%s' % (line_delimiter, b_type.get_abbreviation()) if b_date: label += ' %s' % b_date if b_place: label += ' %s' % b_place if d_type: label += '%s%s' % (line_delimiter, d_type.get_abbreviation()) if d_date: label += ' %s' % d_date if d_place: label += ' %s' % d_place if self.increlname and self.center_person != person: # display relationship info if self.advrelinfo: (relationship, _ga, _gb) = self.rel_calc.get_one_relationship( self._db, self.center_person, person, extra_info=True, olocale=self._locale) if relationship: label += "%s(%s Ga=%d Gb=%d)" % (line_delimiter, relationship, _ga, _gb) else: relationship = self.rel_calc.get_one_relationship( self._db, self.center_person, person, olocale=self._locale) if relationship: label += "%s(%s)" % (line_delimiter, relationship) if self.occupation > 0: event_refs = person.get_primary_event_ref_list() events = [ event for event in [ self._db.get_event_from_handle(ref.ref) for ref in event_refs ] if event.get_type() == EventType(EventType.OCCUPATION) ] if len(events) > 0: events.sort(key=lambda x: x.get_date_object()) if self.occupation == 1: occupation = events[-1].get_description() if occupation: label += "%s(%s)" % (line_delimiter, occupation) elif self.occupation == 2: for evt in events: date = self.get_date_string(evt) place = self.get_place_string(evt) desc = evt.get_description() if not date and not desc and not place: continue label += '%s(' % line_delimiter if date: label += '%s' % date if desc: label += ' ' if desc: label += '%s' % desc if place: if date or desc: label += ', ' label += '%s' % place label += ')' # see if we have a table that needs to be terminated if self.use_html_output: label += '</TD></TR></TABLE>' return label else: # non html label is enclosed by "" so escape other " return label.replace('"', '\\\"')
def __write_gallery(self, thumbs, mediapath): """ This procedure writes out the media """ LOG.info('Looking at gallery') from gramps.gen.utils.thumbnails import get_thumbnail_path # full clear line for proper styling fullclear = Html("div", class_="fullclear", inline=True) LOG.info('Start to enumerate for gallery') #LOG.debug(thumbs) for i, thumb in enumerate(thumbs): # list of tuples [('',''),('','')] if (list(thumb)[0])[0] == 'src': src = (list(thumb)[0])[1] else: src = 'No src' #LOG.debug(src) if (list(thumb)[1])[0] == 'mime': mime = (list(thumb)[1])[1] else: mime = 'No mime' #LOG.debug(mime) if (list(thumb)[2])[0] == 'checksum': checksum = (list(thumb)[2])[1] else: checksum = 'No checksum' #LOG.debug(checksum) if (list(thumb)[2])[0] == 'description': description = (list(thumb)[2])[1] elif len(thumb) == 4: description = (list(thumb)[3])[1] else: description = 'No description' #LOG.debug(description) # relative and absolute paths src = os.path.join(mediapath, src) # windows OS ??? if not src.startswith("/"): src = os.path.join(USER_HOME, src) #LOG.debug(src) # only images if mime.startswith("image"): thumb = get_thumbnail_path(str(src), mtype=None, rectangle=None) #LOG.debug(thumb) self.text += Html('img', src=str(thumb), mtype=str(mime)) self.text += fullclear self.text += Html('a', str(description), href=str(src), target='blank', title=str(mime)) self.text += fullclear return self.text
def get_person_label(self, person): "return person label string" # see if we have an image to use for this person imagePath = None if self.bUseHtmlOutput: mediaList = person.get_media_list() if len(mediaList) > 0: mediaHandle = mediaList[0].get_reference_handle() media = self.database.get_object_from_handle(mediaHandle) mediaMimeType = media.get_mime_type() if mediaMimeType[0:5] == "image": imagePath = get_thumbnail_path( media_path_full(self.database, media.get_path()), rectangle=mediaList[0].get_rectangle()) # test if thumbnail actually exists in thumbs # (import of data means media files might not be present imagePath = find_file(imagePath) label = "" lineDelimiter = '\\n' # If we have an image, then start an HTML table; remember to close # the table afterwards! # # This isn't a free-form HTML format here...just a few keywords that # happen to be # similar to keywords commonly seen in HTML. For additional # information on what # is allowed, see: # # http://www.graphviz.org/info/shapes.html#html # if self.bUseHtmlOutput and imagePath: lineDelimiter = '<BR/>' label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" CELLBORDER="0"><TR><TD></TD><TD><IMG SRC="%s"/></TD><TD></TD>' % imagePath if self.imgpos == 0: #trick it into not stretching the image label += '</TR><TR><TD COLSPAN="3">' else : label += '<TD>' else : #no need for html label with this person self.bUseHtmlOutput = False # at the very least, the label must have the person's name nm = self._name_display.display(person) if self.bUseHtmlOutput : # avoid < and > in the name, as this is html text label += nm.replace('<', '<').replace('>', '>') else : label += nm p_id = person.get_gramps_id() if self.includeid == 1: # same line label += " (%s)" % p_id elif self.includeid == 2: # own line label += "%s(%s)" % (lineDelimiter, p_id) if self.event_choice != 0: b_date, d_date, b_place, d_place = self.get_event_strings(person) if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date): label += '%s(' % lineDelimiter if b_date: label += '%s' % b_date label += ' - ' if d_date: label += '%s' % d_date label += ')' if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place) and not (self.event_choice == 3 and (b_date or d_date)) ): label += '%s(' % lineDelimiter if b_place: label += '%s' % b_place label += ' - ' if d_place: label += '%s' % d_place label += ')' if self.increlname and self.center_person != person: # display relationship info if self.advrelinfo: (relationship, Ga, Gb) = self.rel_calc.get_one_relationship( self.database, self.center_person, person, extra_info=True, olocale=self._locale) if relationship: label += "%s(%s Ga=%d Gb=%d)" % (lineDelimiter, relationship, Ga, Gb) else: relationship = self.rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relationship: label += "%s(%s)" % (lineDelimiter, relationship) # see if we have a table that needs to be terminated if self.bUseHtmlOutput: label += '</TD></TR></TABLE>' return label else : # non html label is enclosed by "" so escape other " return label.replace('"', '\\\"')
def get_person_label(self, person): "return person label string" # see if we have an image to use for this person imagePath = None if self.bUseHtmlOutput: mediaList = person.get_media_list() if len(mediaList) > 0: mediaHandle = mediaList[0].get_reference_handle() media = self.database.get_object_from_handle(mediaHandle) mediaMimeType = media.get_mime_type() if mediaMimeType[0:5] == "image": imagePath = get_thumbnail_path( media_path_full(self.database, media.get_path()), rectangle=mediaList[0].get_rectangle()) # test if thumbnail actually exists in thumbs # (import of data means media files might not be present imagePath = find_file(imagePath) label = "" lineDelimiter = '\\n' # If we have an image, then start an HTML table; remember to close # the table afterwards! # # This isn't a free-form HTML format here...just a few keywords that # happen to be # similar to keywords commonly seen in HTML. For additional # information on what # is allowed, see: # # http://www.graphviz.org/info/shapes.html#html # if self.bUseHtmlOutput and imagePath: lineDelimiter = '<BR/>' label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" CELLBORDER="0"><TR><TD></TD><TD><IMG SRC="%s"/></TD><TD></TD>' % imagePath if self.imgpos == 0: #trick it into not stretching the image label += '</TR><TR><TD COLSPAN="3">' else: label += '<TD>' else: #no need for html label with this person self.bUseHtmlOutput = False # at the very least, the label must have the person's name nm = self._name_display.display(person) if self.bUseHtmlOutput: # avoid < and > in the name, as this is html text label += nm.replace('<', '<').replace('>', '>') else: label += nm p_id = person.get_gramps_id() if self.includeid == 1: # same line label += " (%s)" % p_id elif self.includeid == 2: # own line label += "%s(%s)" % (lineDelimiter, p_id) if self.event_choice != 0: b_date, d_date, b_place, d_place = self.get_event_strings(person) if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date): label += '%s(' % lineDelimiter if b_date: label += '%s' % b_date label += ' - ' if d_date: label += '%s' % d_date label += ')' if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place) and not (self.event_choice == 3 and (b_date or d_date))): label += '%s(' % lineDelimiter if b_place: label += '%s' % b_place label += ' - ' if d_place: label += '%s' % d_place label += ')' if self.increlname and self.center_person != person: # display relationship info if self.advrelinfo: (relationship, Ga, Gb) = self.rel_calc.get_one_relationship(self.database, self.center_person, person, extra_info=True, olocale=self._locale) if relationship: label += "%s(%s Ga=%d Gb=%d)" % (lineDelimiter, relationship, Ga, Gb) else: relationship = self.rel_calc.get_one_relationship( self.database, self.center_person, person, olocale=self._locale) if relationship: label += "%s(%s)" % (lineDelimiter, relationship) # see if we have a table that needs to be terminated if self.bUseHtmlOutput: label += '</TD></TR></TABLE>' return label else: # non html label is enclosed by "" so escape other " return label.replace('"', '\\\"')
def write_person(self, person): newline = '<br/>' label = '<table border="0" cellspacing="2" cellpadding="0" cellborder="0"><tr><td>' media_list = person.get_media_list() if len(media_list) > 0: media_handle = media_list[0].get_reference_handle() media = self.database.get_media_from_handle(media_handle) media_mime_type = media.get_mime_type() if media_mime_type[0:5] == "image": image_path = get_thumbnail_path( media_path_full(self.database, media.get_path()), rectangle=media_list[0].get_rectangle()) if image_path: label += '<img src="%s"/></td><td>' % image_path label += self._name_display.display(person) label += ' %s' % self.symbols[person.get_gender()] for event_ref in person.get_primary_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) if event.get_type() == EventType.NOB_TITLE: label += '<br/>%s' % place_displayer.display_event( self.database, event) if event.get_description(): label += ' (%s)' % event.get_description() label += ' %s' % self._get_date(event.get_date_object()) birth = get_birth_or_fallback(self.database, person) if birth: birth_symbol = self.symbols['birth'] fam_handle = person.get_main_parents_family_handle() if fam_handle: family = self.database.get_family_from_handle(fam_handle) if (family.type == FamilyRelType.UNMARRIED): birth_symbol = self.symbols['illegitimate'] birthdate = self._get_date(birth.get_date_object()) birthplace = place_displayer.display_event(self.database, birth) label += '<br/>%s' % birth_symbol if birthdate: label += ' %s' % birthdate if birth.description: label += ' (%s)' % birth.description if birthplace: label += ' %s' % birthplace death = get_death_or_fallback(self.database, person) if death: deathdate = self._get_date(death.get_date_object()) deathplace = place_displayer.display_event(self.database, death) label += '<br/>%s ' % self.symbols['death'] if deathdate: label += ' %s' % deathdate if death.description: label += ' (%s)' % death.description if deathplace: label += ' %s' % deathplace for event_ref in person.get_primary_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) if event.get_type() == EventType.MILITARY_SERV: for attribute in event_ref.get_attribute_list(): if ((attribute.get_type() == AttributeType.DESCRIPTION) and (attribute.get_value() == 'Killed in Action')): label += '<br/>%s %s' % (self.symbols['kia'], event.get_description()) label += '</td></tr></table>' self.doc.add_node(node_id=person.get_gramps_id(), label=label, shape=self.nodeshape[person.get_gender()], style='%s,filled' % self.nodestyle[person.get_gender()], fillcolor=self.fillcolor[person.get_gender()], htmloutput=True)
def __write_gallery(self, thumbs, mediapath): """ This procedure writes out the media """ LOG.info("Looking at gallery") from gramps.gen.utils.thumbnails import get_thumbnail_path # full clear line for proper styling fullclear = Html("div", class_="fullclear", inline=True) LOG.info("Start to enumerate for gallery") # LOG.debug(thumbs) for i, thumb in enumerate(thumbs): # list of tuples [('',''),('','')] if (list(thumb)[0])[0] == "src": src = (list(thumb)[0])[1] else: src = "No src" # LOG.debug(src) if (list(thumb)[1])[0] == "mime": mime = (list(thumb)[1])[1] else: mime = "No mime" # LOG.debug(mime) if (list(thumb)[2])[0] == "checksum": checksum = (list(thumb)[2])[1] else: checksum = "No checksum" # LOG.debug(checksum) if (list(thumb)[2])[0] == "description": description = (list(thumb)[2])[1] elif len(thumb) == 4: description = (list(thumb)[3])[1] else: description = "No description" # LOG.debug(description) # relative and absolute paths src = os.path.join(mediapath, src) # windows OS ??? if not src.startswith("/"): src = os.path.join(USER_HOME, src) # LOG.debug(src) # only images if mime.startswith("image"): thumb = get_thumbnail_path(str(src), mtype=None, rectangle=None) # LOG.debug(thumb) self.text += Html("img", src=str(thumb), mtype=str(mime)) self.text += fullclear self.text += Html("a", str(description), href=str(src), target="blank", title=str(mime)) self.text += fullclear return self.text