* src/plugins/RelGraph.py: Convert to db. Change coding style.

Use FreeSans as a TrueType font.


svn: r3131
This commit is contained in:
Alex Roitman 2004-05-06 02:29:34 +00:00
parent fdb376639d
commit b3a0c19225
2 changed files with 217 additions and 207 deletions

View File

@ -1,3 +1,7 @@
2004-05-05 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/RelGraph.py: Convert to db. Change coding style.
Use FreeSans as a TrueType font.
2004-05-04 Don Allingham <donaldallingham@users.sourceforge.net> 2004-05-04 Don Allingham <donaldallingham@users.sourceforge.net>
* src/gramps_main.py: rebuild tree after importing * src/gramps_main.py: rebuild tree after importing
* src/plugins/ReadGedcom.py: destroy filechooser at proper time * src/plugins/ReadGedcom.py: destroy filechooser at proper time

View File

@ -1,8 +1,9 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2003 Donald N. Allingham # Copyright (C) 2000-2004 Donald N. Allingham
# Contributions by Lorenzo Cappelletti <lorenzo.cappelletti@email.it> # Contributions by Lorenzo Cappelletti <lorenzo.cappelletti@email.it>
# Modified by Alex Roitman: convert to database interface, change coding style.
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -52,7 +53,6 @@ import BaseDoc
import GenericFilter import GenericFilter
import Errors import Errors
from RelLib import Event
from gettext import gettext as _ from gettext import gettext as _
from latin_utf8 import utf8_to_latin from latin_utf8 import utf8_to_latin
@ -71,6 +71,9 @@ _pagecount_map = {
_("Multiple") : _multiple, _("Multiple") : _multiple,
} }
_PS_FONT = 'Helvetica'
_TT_FONT = 'FreeSans'
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# RelGraphDialog # RelGraphDialog
@ -89,7 +92,7 @@ class RelGraphDialog(Report.ReportDialog):
IncludeUrl = 1 IncludeUrl = 1
IncludeId = 0 IncludeId = 0
Colorize = 1 Colorize = 1
FontStyle = 'Arial' FontStyle = _TT_FONT
ArrowHeadStyle = 'none' ArrowHeadStyle = 'none'
ArrowTailStyle = 'normal' ArrowTailStyle = 'normal'
AdoptionsDashed = 1 AdoptionsDashed = 1
@ -182,12 +185,12 @@ class RelGraphDialog(Report.ReportDialog):
menu = gtk.Menu() menu = gtk.Menu()
menuitem = gtk.MenuItem(_("TrueType")) menuitem = gtk.MenuItem(_("TrueType"))
menuitem.set_data('t', 'Arial') menuitem.set_data('t', _TT_FONT)
menuitem.show() menuitem.show()
menu.append(menuitem) menu.append(menuitem)
menuitem = gtk.MenuItem(_("PostScript")) menuitem = gtk.MenuItem(_("PostScript"))
menuitem.set_data('t', 'Helvetica') menuitem.set_data('t', _PS_FONT)
menuitem.show() menuitem.show()
menu.append(menuitem) menu.append(menuitem)
@ -391,9 +394,9 @@ class RelGraphDialog(Report.ReportDialog):
self.File = open(self.target_path,"w") self.File = open(self.target_path,"w")
try: try:
self.IndividualSet =\ self.individual_set =\
Set(self.filter.apply(self.db, self.db.get_person_id_map().values())) Set(self.filter.apply(self.db, self.db.get_person_keys()))
self.IndividualSet.add(self.person) self.individual_set.add(self.person.get_id())
except Errors.FilterError, msg: except Errors.FilterError, msg:
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
(m1,m2) = msg.messages() (m1,m2) = msg.messages()
@ -403,8 +406,7 @@ class RelGraphDialog(Report.ReportDialog):
if self.print_report.get_active (): if self.print_report.get_active ():
os.environ["DOT"] = self.target_path os.environ["DOT"] = self.target_path
os.system ('dot -Tps "$DOT" | %s &' % os.system ('dot -Tps "$DOT" | %s &' % Report.get_print_dialog_app ())
Report.get_print_dialog_app ())
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -458,109 +460,107 @@ def _writeDot(self):
((self.VPages - 1)*1.0))) ((self.VPages - 1)*1.0)))
self.File.write("page=\"%3.1f,%3.1f\";\n" % (self.Width, self.Height)) self.File.write("page=\"%3.1f,%3.1f\";\n" % (self.Width, self.Height))
if len(self.IndividualSet) > 1: if len(self.individual_set) > 1:
if self.ShowAsStack: if self.ShowAsStack:
_writeGraphRecord(self) _write_graph_record(self)
else: else:
_writeGraphBox(self) _write_graph_box(self)
self.File.write("}\n// File end") self.File.write("}\n// File end")
self.File.close() self.File.close()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _writeGraphBox # _write_graph_box
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _writeGraphBox (self): def _write_graph_box (self):
"""Write out a graph body where all individuals are separated boxes""" """Write out a graph body where all individuals are separated boxes"""
individualNodes = Set() # list of individual graph nodes individual_nodes = Set() # list of individual graph nodes
familyNodes = Set() # list of family graph nodes family_nodes = Set() # list of family graph nodes
# Writes out a not for each individual # Writes out a not for each individual
self.File.write('\n// Individual nodes (box graph)\n') self.File.write('\n// Individual nodes (box graph)\n')
_writeNode(self.File, shape='box', color='black', fontname=self.FontStyle) _write_node(self.File, shape='box', color='black', fontname=self.FontStyle)
for individual in self.IndividualSet: for individual_id in self.individual_set:
individualNodes.add(individual) individual_nodes.add(individual_id)
individualId = _getIndividualId(individual) (color, url) = _get_individual_data(self, individual_id)
(color, url) = _getIndividualData(self, individual) label = _get_individual_label(self, individual_id)
label = _getIndividualLabel(self, individual) _write_node(self.File, individual_id, label, color, url,
_writeNode(self.File, individualId, label, color, url) fontname=self.FontStyle)
# Writes out a node for each family # Writes out a node for each family
if self.ShowFamilies: if self.ShowFamilies:
self.File.write('\n// Family nodes (box graph)\n') self.File.write('\n// Family nodes (box graph)\n')
_writeNode(self.File, shape='ellipse', color='black', _write_node(self.File, shape='ellipse', color='black',
fontname=self.FontStyle) fontname=self.FontStyle)
for individual in individualNodes: for individual_id in individual_nodes:
for family in individual.get_family_id_list(): individual = self.db.find_person_from_id(individual_id)
if family not in familyNodes: for family_id in individual.get_family_id_list():
familyNodes.add(family) if family_id not in family_nodes:
familyId = _get_family_idId(family) family_nodes.add(family_id)
label = _get_family_idLabel(self, family) label = _get_family_id_label(self, family_id)
_writeNode(self.File, familyId, label) _write_node(self.File, family_id, label,
fontname=self.FontStyle)
# Links each individual to their parents/family # Links each individual to their parents/family
self.File.write('\n// Individual edges\n') self.File.write('\n// Individual edges\n')
_writeEdge(self.File, style="solid", arrowHead=self.ArrowHeadStyle, _write_edge(self.File, style="solid",
arrowTail=self.ArrowTailStyle) arrowHead=self.ArrowHeadStyle,arrowTail=self.ArrowTailStyle)
for individual in individualNodes: for individual_id in individual_nodes:
individualId = _getIndividualId(individual) individual = self.db.find_person_from_id(individual_id)
for family, motherRelShip, fatherRelShip\ for family_id, mother_rel_ship, father_rel_ship\
in individual.get_parent_family_id_list(): in individual.get_parent_family_id_list():
father = family.get_father_id() family = self.db.find_family_from_id(family_id)
mother = family.get_mother_id() father_id = family.get_father_id()
if self.ShowFamilies and family in familyNodes: mother_id = family.get_mother_id()
if self.ShowFamilies and family_id in family_nodes:
# edge from an individual to their family # edge from an individual to their family
familyId = _get_family_idId(family) style = _get_edge_style(self, father_rel_ship, mother_rel_ship)
style = _getEdgeStyle(self, fatherRelShip, motherRelShip) _write_edge(self.File, individual_id, family_id, style)
_writeEdge(self.File, individualId, familyId, style)
else: else:
# edge from an individual to their parents # edge from an individual to their parents
if father and father in individualNodes: if father_id and father_id in individual_nodes:
fatherId = _getIndividualId(father) _write_edge(self.File, individual_id, father_id,
_writeEdge(self.File, individualId, fatherId, _get_edge_style(self, father_rel_ship))
_getEdgeStyle(self, fatherRelShip)) if mother_id and mother_id in individual_nodes:
if mother and mother in individualNodes: _write_edge(self.File, individual_id, mother_id,
motherId = _getIndividualId(mother) _get_edge_style(self, mother_rel_ship))
_writeEdge(self.File, individualId, motherId,
_getEdgeStyle(self, motherRelShip))
# Links each family to its components # Links each family to its components
if self.ShowFamilies: if self.ShowFamilies:
self.File.write('\n// Family edges (box graph)\n') self.File.write('\n// Family edges (box graph)\n')
_writeEdge(self.File, style="solid", arrowHead=self.ArrowHeadStyle, _write_edge(self.File, style="solid",
arrowTail=self.ArrowTailStyle) arrowHead=self.ArrowHeadStyle,arrowTail=self.ArrowTailStyle)
for family in familyNodes: for family_id in family_nodes:
familyId = _get_family_idId(family) family = self.db.find_family_from_id(family_id)
father = family.get_father_id() father_id = family.get_father_id()
if father and father in individualNodes: if father_id and father_id in individual_nodes:
fatherId = _getIndividualId(father) _write_edge(self.File, family_id, father_id)
_writeEdge(self.File, familyId, fatherId) mother_id = family.get_mother_id()
mother = family.get_mother_id() if mother_id and mother_id in individual_nodes:
if mother and mother in individualNodes: _write_edge(self.File, family_id, mother_id)
motherId = _getIndividualId(mother)
_writeEdge(self.File, familyId, motherId)
# Statistics # Statistics
males = 0 males = 0
females = 0 females = 0
unknowns = 0 unknowns = 0
for individual in individualNodes: for individual_id in individual_nodes:
individual = self.db.find_person_from_id(individual_id)
if individual.get_gender() == individual.male: if individual.get_gender() == individual.male:
males = males + 1 males = males + 1
elif individual.get_gender() == individual.female: elif individual.get_gender() == individual.female:
females = females + 1 females = females + 1
else: else:
unknowns = unknowns + 1 unknowns = unknowns + 1
_writeStats(self.File, males, females, unknowns, len(familyNodes)) _write_stats(self.File, males, females, unknowns, len(family_nodes))
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _writeGraphRecord # _writeGraphRecord
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _writeGraphRecord (self): def _write_graph_record (self):
"""Write out a graph body where families are rendered as records""" """Write out a graph body where families are rendered as records"""
# Builds a dictionary of family records. # Builds a dictionary of family records.
# Each record is made of an individual married with zero or # Each record is made of an individual married with zero or
# more individuals. # more individuals.
familyNodes = {} family_nodes = {}
if isinstance(self.filter.get_rules()[0], if isinstance(self.filter.get_rules()[0],
GenericFilter.IsDescendantFamilyOf): GenericFilter.IsDescendantFamilyOf):
# With the IsDescendantFamilyOf filter, the IndividualSet # With the IsDescendantFamilyOf filter, the IndividualSet
@ -572,121 +572,113 @@ def _writeGraphRecord (self):
# subset (in-law relatives). # subset (in-law relatives).
filter = GenericFilter.GenericFilter() filter = GenericFilter.GenericFilter()
filter.add_rule(GenericFilter.IsDescendantOf([self.person.get_id()])) filter.add_rule(GenericFilter.IsDescendantOf([self.person.get_id()]))
naturalRelatives =\ natural_relatives =\
Set(filter.apply(self.db, self.db.get_person_id_map().values())) Set(filter.apply(self.db, self.db.get_person_keys()))
naturalRelatives.add(self.person) natural_relatives.add(self.person.get_id())
else: else:
naturalRelatives = self.IndividualSet natural_relatives = self.individual_set
self.File.write('\n// Family nodes (record graph)\n') self.File.write('\n// Family nodes (record graph)\n')
_writeNode(self.File, shape='record', color='black', _write_node(self.File, shape='record', color='black',
fontname=self.FontStyle) fontname=self.FontStyle)
for individual in naturalRelatives: for individual_id in natural_relatives:
familyId = _getIndividualId(individual)
# If both husband and wife are members of the IndividualSet, # If both husband and wife are members of the IndividualSet,
# only one record, with the husband first, is displayed. # only one record, with the husband first, is displayed.
individual = self.db.find_person_from_id(individual_id)
if individual.get_gender() == individual.female: if individual.get_gender() == individual.female:
# There are exactly three cases where a female node is added: # There are exactly three cases where a female node is added:
family = None # no family family = None # no family
husbands = [] # filtered-in husbands (naturalRelatives) husbands = [] # filtered-in husbands (naturalRelatives)
unknownHusbands = 0 # filtered-out/unknown husbands unknown_husbands = 0 # filtered-out/unknown husbands
for family in individual.get_family_id_list(): for family_id in individual.get_family_id_list():
husband = family.get_father_id() family = self.db.find_family_from_id(family_id)
if husband and husband in self.IndividualSet: husband_id = family.get_father_id()
if husband not in naturalRelatives: if husband_id and husband_id in self.individual_set:
husbands.append(husband) if husband_id not in natural_relatives:
husbands.append(husband_id)
else: else:
unknownHusbands = 1 unknown_husbands = 1
if not family or len(husbands) or unknownHusbands: if not family_id or len(husbands) or unknown_husbands:
familyNodes[familyId] = [individual] + husbands family_nodes[individual_id] = [individual_id] + husbands
else: else:
familyNodes[familyId] = [individual] family_nodes[individual_id] = [individual_id]
for family in individual.get_family_id_list(): for family_id in individual.get_family_id_list():
wife = family.get_mother_id() family = self.db.find_family_from_id(family_id)
if wife in self.IndividualSet: wife_id = family.get_mother_id()
familyNodes[familyId].append(wife) if wife_id in self.individual_set:
family_nodes[individual_id].append(wife_id)
# Writes out all family records # Writes out all family records
for familyId, family in familyNodes.items(): for individual_id, family_id in family_nodes.items():
(color, url) = _getIndividualData(self, familyNodes[familyId][0]) (color, url) = _get_individual_data(self, family_nodes[individual_id][0])
label = _get_family_idRecordLabel(self, familyNodes[familyId]) label = _get_family_id_record_label(self, family_nodes[individual_id])
_writeNode(self.File, familyId, label, color, url) _write_node(self.File, individual_id, label, color, url,
fontname=self.FontStyle)
# Links individual's record to their parents' record # Links individual's record to their parents' record
# The arrow goes from the individual port of a family record # The arrow goes from the individual port of a family record
# to the parent port of the parent's family record. # to the parent port of the parent's family record.
self.File.write('\n// Individual edges\n') self.File.write('\n// Individual edges\n')
_writeEdge(self.File, style="solid", arrowHead=self.ArrowHeadStyle, _write_edge(self.File, style="solid",
arrowTail=self.ArrowTailStyle) arrowHead=self.ArrowHeadStyle,arrowTail=self.ArrowTailStyle)
for familyFromId, familyFrom in familyNodes.items(): for family_from_id, family_from_id2 in family_nodes.items():
for individualFrom in familyFrom: for individual_from_id in family_from_id:
individualFromId = _getIndividualId(individualFrom) individual_from = self.db.find_person_from_id(individual_from_id)
for family, motherRelShip, fatherRelShip\ for family_id, mother_rel_ship, father_rel_ship\
in individualFrom.get_parent_family_id_list(): in individual_from.get_parent_family_id_list():
father = family.get_father_id() father_id = family.get_father_id()
mother = family.get_mother_id() mother_id = family.get_mother_id()
# Things are complicated here because a parent may or # Things are complicated here because a parent may or
# or may not exist. # or may not exist.
if father: if not father_id:
fatherId = _getIndividualId(father) father_id = ""
else: if not mother_id:
fatherId = "" mother_id = ""
if mother: if family_nodes.has_key(father_id):
motherId = _getIndividualId(mother) if mother_id in family_nodes[father_id]:
else: _write_edge(self.File, family_from_id, father_id,
motherId = "" _get_edge_style(self, mother_rel_ship),
if familyNodes.has_key(fatherId): port_from=individual_from_id, port_to=mother_id)
if mother in familyNodes[fatherId]:
_writeEdge(self.File, familyFromId, fatherId,
_getEdgeStyle(self, motherRelShip),
portFrom=individualFromId, portTo=motherId)
else: else:
_writeEdge(self.File, familyFromId, fatherId, _write_edge(self.File, family_from_id, father_id,
_getEdgeStyle(self, fatherRelShip), _get_edge_style(self, mother_rel_ship),
portFrom=individualFromId) portFrom=individual_from_id)
if familyNodes.has_key(motherId): if family_nodes.has_key(mother_id):
if father in familyNodes[motherId]: if father_id in family_nodes[mother_id]:
_writeEdge(self.File, familyFromId, motherId, _write_edge(self.File, family_from_id, mother_id,
_getEdgeStyle(self, fatherRelShip), _get_edge_style(self, father_rel_ship),
portFrom=individualFromId, portTo=fatherId) portFrom=individual_from_id, portTo=father_id)
else: else:
_writeEdge(self.File, familyFromId, motherId, _write_edge(self.File, family_from_id, mother_id,
_getEdgeStyle(self, motherRelShip), _get_edge_style(self, mother_rel_ship),
portFrom=individualFromId) portFrom=individual_from_id)
# Stats (unique individuals) # Stats (unique individuals)
males = Set() males = Set()
females = Set() females = Set()
unknowns = Set() unknowns = Set()
marriages = 0 marriages = 0
for familyId, family in familyNodes.items(): for family_id, family_id2 in family_nodes.items():
marriages = marriages + (len(family) - 1) marriages = marriages + (len(family_id2) - 1)
for individual in family: for individual_id in family_id:
individual = self.db.find_person_from_id(individual_id)
if individual.get_gender() == individual.male\ if individual.get_gender() == individual.male\
and individual not in males: and individual_id not in males:
males.add(individual) males.add(individual_id)
elif individual.get_gender() == individual.female\ elif individual.get_gender() == individual.female\
and individual not in females: and individual_id not in females:
females.add(individual) females.add(individual_id)
elif individual.get_gender() == individual.unknown\ elif individual.get_gender() == individual.unknown\
and individual not in unknowns: and individual_id not in unknowns:
unknowns.add(individual) unknowns.add(individual_id)
_writeStats(self.File, len(males), len(females), len(unknowns), marriages) _write_stats(self.File, len(males), len(females), len(unknowns), marriages)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _getIndividualId # _get_individual_data
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _getIndividualId (individual): def _get_individual_data (self, individual_id):
"""Returns an individual id suitable for dot"""
return individual.get_id()
#------------------------------------------------------------------------
#
# _getIndividualData
#
#------------------------------------------------------------------------
def _getIndividualData (self, individual):
"""Returns a tuple of individual data""" """Returns a tuple of individual data"""
# color # color
color = '' color = ''
individual = self.db.find_person_from_id(individual_id)
if self.Colorize: if self.Colorize:
gender = individual.get_gender() gender = individual.get_gender()
if gender == individual.male: if gender == individual.male:
@ -696,37 +688,40 @@ def _getIndividualData (self, individual):
# url # url
url = '' url = ''
if self.IncludeUrl: if self.IncludeUrl:
url = "%s.html" % _getIndividualId(individual) url = "%s.html" % individual_id
return (color, url) return (color, url)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _getEventLabel # _get_event_label
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _getEventLabel (self, event): def _get_event_label (self, event_id):
"""Returns a formatted string of event data suitable for a label""" """Returns a formatted string of event data suitable for a label"""
if self.IncludeDates and event: if self.IncludeDates and event_id:
dateObj = event.get_date_object() event = self.db.find_event_from_id(event_id)
if dateObj.getYearValid(): date_obj = event.get_date_object()
if date_obj.get_year_valid():
if self.JustYear: if self.JustYear:
return "%i" % dateObj.getYear() return "%i" % date_obj.get_year_valid()
else: else:
return dateObj.get_date() return date_obj.get_date()
elif self.PlaceCause: elif self.PlaceCause:
if event.get_place_name(): place_id = event.get_place_id()
return event.get_place_name() if place_id:
place = self.db.find_place_from_id(place_id)
return place.get_title()
else: else:
return event.get_cause() return event.get_cause()
return '' return ''
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _getIndividualLabel # _get_individual_label
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _getIndividualLabel (self, individual, marriageEvent=None, family=None): def _get_individual_label (self, individual_id, marriage_event_id=None, family_id=None):
"""Returns a formatted string of individual data suitable for a label """Returns a formatted string of individual data suitable for a label
Returned string always includes individual's name and optionally Returned string always includes individual's name and optionally
@ -734,24 +729,23 @@ def _getIndividualLabel (self, individual, marriageEvent=None, family=None):
individual's and family's IDs. individual's and family's IDs.
""" """
# Get data ready # Get data ready
individualId = individual.get_id() individual = self.db.find_person_from_id(individual_id)
name = individual.get_primary_name().get_name() name = individual.get_primary_name().get_name()
if self.IncludeDates: if self.IncludeDates:
birth = _getEventLabel(self, individual.get_birth()) birth = _get_event_label(self, individual.get_birth_id())
death = _getEventLabel(self, individual.get_death()) death = _get_event_label(self, individual.get_death_id())
if marriageEvent != None: if marriage_event_id:
familyId = family.get_id() marriage = _get_event_label(self, marriage_event_id)
marriage = _getEventLabel(self, marriageEvent)
# Id # Id
if self.IncludeId: if self.IncludeId:
if marriageEvent != None: if marriage_event_id:
label = "%s (%s)\\n" % (familyId, individualId) label = "%s (%s)\\n" % (family_id, individual_id)
else: else:
label = "%s\\n" % individualId label = "%s\\n" % individual_id
else: else:
label = "" label = ""
# Marriage date # Marriage date
if self.IncludeDates and (marriageEvent != None and marriage): if self.IncludeDates and (marriage_event_id and marriage):
label = label + "%s\\n" % marriage label = label + "%s\\n" % marriage
# Individual's name # Individual's name
label = label + name label = label + name
@ -762,78 +756,90 @@ def _getIndividualLabel (self, individual, marriageEvent=None, family=None):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _getEdgeStyle # _get_edge_style
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _getEdgeStyle (self, fatherRelShip, motherRelShip="Birth"): def _get_edge_style (self, father_rel_ship, mother_rel_ship="Birth"):
"""Returns a edge style that depends on the relationships with parents""" """Returns a edge style that depends on the relationships with parents"""
if self.AdoptionsDashed and \ if self.AdoptionsDashed and \
(fatherRelShip != "Birth" or motherRelShip != "Birth"): (father_rel_ship != "Birth" or mother_rel_ship != "Birth"):
return "dashed" return "dashed"
#------------------------------------------------------------------------
#
# _get_family_idId
#
#------------------------------------------------------------------------
def _get_family_idId (family):
"""Returns a family id suitable for dot"""
return family.get_id()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _get_family_idLabel # _get_family_id_label
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _get_family_idLabel (self, family): def _get_family_id_label (self, family_id):
"""Returns a formatted string of family data suitable for a label""" """Returns a formatted string of family data suitable for a label"""
marriage = _getEventLabel(self, family.get_marriage())
fam = self.db.find_family_from_id(family_id)
for event_id in fam.get_event_list():
if event_id:
event = self.db.find_event_from_id(event_id)
if event.get_name() == "Marriage":
marriage_event_id = event_id
break
else:
marriage_event_id = None
marriage = _get_event_label(self, marriage_event_id)
if self.IncludeId: if self.IncludeId:
return "%s\\n%s" % (family.get_id(), marriage) return "%s\\n%s" % (family_id, marriage)
else: else:
return marriage return marriage
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _get_family_idRecordLabel # _get_family_id_record_label
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _get_family_idRecordLabel (self, record): def _get_family_id_record_label (self, record):
"""Returns a formatted string of a family record suitable for a label""" """Returns a formatted string of a family record suitable for a label"""
labels = [] labels = []
spouse = record[0] spouse_id = record[0]
for individual in record: spouse = self.db.find_person_from_id(spouse_id)
individualId = _getIndividualId(individual) for individual_id in record:
if spouse == individual: individual = self.db.find_person_from_id(individual_id)
label = _getIndividualLabel(self, individual) if spouse_id == individual_id:
label = _get_individual_label(self, individual_id)
else: else:
marriageEvent = Event() marriage_event_id = None
for individualFamily in individual.get_family_id_list(): for individual_family_id in individual.get_family_id_list():
if individualFamily in spouse.get_family_id_list(): if individual_family_id in spouse.get_family_id_list():
marriageEvent = individualFamily.get_marriage() individual_family = self.db.find_family_from_id(individual_family_id)
if not marriageEvent: for event_id in individual_family.get_event_list():
marriageEvent = Event() if event_id:
break event = self.db.find_event_from_id(event_id)
label = _getIndividualLabel(self, individual, marriageEvent, if event.get_name() == "Marriage":
individualFamily) marriage_event_id = event_id
break
label = _get_individual_label(self, individual_id,
marriage_event_id,individual_family_id)
label = string.replace(label, "|", r"\|") label = string.replace(label, "|", r"\|")
label = string.replace(label, "<", r"\<") label = string.replace(label, "<", r"\<")
label = string.replace(label, ">", r"\>") label = string.replace(label, ">", r"\>")
labels.append("<%s>%s" % (individualId, label)) labels.append("<%s>%s" % (individual_id, label))
return string.join(labels, "|") return string.join(labels, "|")
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _writeNode # _write_node
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _writeNode (file, node="node", label="", color="", url="", shape="", def _write_node (file, node="node", label="", color="", url="", shape="",
fontname=""): fontname=""):
"""Writes out an individual node""" """Writes out an individual node"""
file.write('%s [' % node) file.write('%s [' % node)
if label: if label:
file.write('label="%s" ' % if fontname == _TT_FONT:
utf8_to_latin(string.replace(label, '"', r'\"'))) file.write('label="%s" ' % label.replace('"', r'\"'))
else:
file.write('label="%s" ' %
utf8_to_latin(label.replace('"', r'\"')))
if color: if color:
file.write('color=%s ' % color) file.write('color=%s ' % color)
if url: if url:
@ -846,10 +852,10 @@ def _writeNode (file, node="node", label="", color="", url="", shape="",
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# _writeEdge # _write_edge
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _writeEdge (file, nodeFrom="", nodeTo="", style="", def _write_edge (file, nodeFrom="", nodeTo="", style="",
arrowHead="", arrowTail="", portFrom="", portTo=""): arrowHead="", arrowTail="", portFrom="", portTo=""):
"""Writes out an edge""" """Writes out an edge"""
if nodeFrom and nodeTo: if nodeFrom and nodeTo:
@ -877,7 +883,7 @@ def _writeEdge (file, nodeFrom="", nodeTo="", style="",
# _writeStats # _writeStats
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _writeStats (file, males, females, unknowns, marriages): def _write_stats (file, males, females, unknowns, marriages):
file.write('\n/* Statistics\n') file.write('\n/* Statistics\n')
file.write(' * individuals male : % 4d\n' % males) file.write(' * individuals male : % 4d\n' % males)
file.write(' * female : % 4d\n' % females) file.write(' * female : % 4d\n' % females)