2003-07-31 17:28:08 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-15 14:46:45 +05:30
|
|
|
# Copyright (C) 2003-2006, 2008 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2003-07-31 17:28:08 +05:30
|
|
|
#
|
|
|
|
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-12-07 04:35:52 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
"Export to Web Family Tree"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".WriteFtree")
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
2009-04-17 00:59:40 +05:30
|
|
|
from Filters import GenericFilter, Rules, build_filter_model
|
2003-08-02 07:52:34 +05:30
|
|
|
import Errors
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2009-04-17 00:59:40 +05:30
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-05-01 09:42:42 +05:30
|
|
|
def writeData(database, filename, msg_callback, option_box=None, callback=None):
|
|
|
|
writer = FtreeWriter(database, msg_callback, filename, option_box, callback)
|
2008-01-15 14:46:45 +05:30
|
|
|
return writer.export_data()
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class FtreeWriterOptionBox(object):
|
2005-02-20 00:35:48 +05:30
|
|
|
"""
|
|
|
|
Create a VBox with the option widgets and define methods to retrieve
|
|
|
|
the options.
|
|
|
|
"""
|
2008-01-15 14:46:45 +05:30
|
|
|
def __init__(self, person):
|
2003-09-16 07:05:09 +05:30
|
|
|
self.person = person
|
2008-11-04 09:42:51 +05:30
|
|
|
self.restrict = True
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
def get_option_box(self):
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top = Glade()
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2009-04-17 00:59:40 +05:30
|
|
|
self.filters = self.top.get_object("filter")
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2006-05-03 06:32:54 +05:30
|
|
|
all = GenericFilter()
|
2005-02-20 00:35:48 +05:30
|
|
|
all.set_name(_("Entire Database"))
|
2006-05-03 11:59:07 +05:30
|
|
|
all.add_rule(Rules.Person.Everyone([]))
|
2006-10-11 10:29:26 +05:30
|
|
|
|
|
|
|
the_filters = [all]
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2005-07-09 01:54:54 +05:30
|
|
|
if self.person:
|
2006-05-03 06:32:54 +05:30
|
|
|
des = GenericFilter()
|
2005-07-09 01:54:54 +05:30
|
|
|
des.set_name(_("Descendants of %s") %
|
|
|
|
self.person.get_primary_name().get_name())
|
2006-05-03 11:59:07 +05:30
|
|
|
des.add_rule(Rules.Person.IsDescendantOf(
|
2005-07-09 01:54:54 +05:30
|
|
|
[self.person.get_gramps_id(),1]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2006-05-03 06:32:54 +05:30
|
|
|
ans = GenericFilter()
|
2005-07-09 01:54:54 +05:30
|
|
|
ans.set_name(_("Ancestors of %s")
|
|
|
|
% self.person.get_primary_name().get_name())
|
2006-05-03 11:59:07 +05:30
|
|
|
ans.add_rule(Rules.Person.IsAncestorOf(
|
2005-07-09 01:54:54 +05:30
|
|
|
[self.person.get_gramps_id(),1]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2006-05-03 06:32:54 +05:30
|
|
|
com = GenericFilter()
|
2005-07-09 01:54:54 +05:30
|
|
|
com.set_name(_("People with common ancestor with %s") %
|
|
|
|
self.person.get_primary_name().get_name())
|
2006-05-03 11:59:07 +05:30
|
|
|
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
2005-07-09 01:54:54 +05:30
|
|
|
[self.person.get_gramps_id()]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2008-02-03 08:20:09 +05:30
|
|
|
the_filters += [des, ans, com]
|
2006-10-11 10:29:26 +05:30
|
|
|
|
|
|
|
from Filters import CustomFilters
|
|
|
|
the_filters.extend(CustomFilters.get_filters('Person'))
|
2009-04-17 00:59:40 +05:30
|
|
|
self.filter_menu = build_filter_model(the_filters)
|
|
|
|
self.filters.set_model(self.filter_menu)
|
|
|
|
self.filters.set_active(0)
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2009-04-17 00:59:40 +05:30
|
|
|
the_box = self.top.get_object("vbox1")
|
|
|
|
the_parent = self.top.get_object('dialog-vbox1')
|
2005-02-20 00:35:48 +05:30
|
|
|
the_parent.remove(the_box)
|
2009-05-15 01:45:59 +05:30
|
|
|
self.top.toplevel.destroy()
|
2005-02-20 00:35:48 +05:30
|
|
|
return the_box
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
def parse_options(self):
|
2009-04-17 00:59:40 +05:30
|
|
|
self.restrict = self.top.get_object("restrict").get_active()
|
|
|
|
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FtreeWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class FtreeWriter(object):
|
2003-12-07 04:35:52 +05:30
|
|
|
|
2010-05-01 09:42:42 +05:30
|
|
|
def __init__(self, database, msg_callback, filename="", option_box=None,
|
2008-01-15 14:46:45 +05:30
|
|
|
callback = None):
|
2005-02-20 00:35:48 +05:30
|
|
|
self.db = database
|
|
|
|
self.option_box = option_box
|
|
|
|
self.filename = filename
|
2006-05-10 01:15:18 +05:30
|
|
|
self.callback = callback
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback = msg_callback
|
2008-07-14 21:17:15 +05:30
|
|
|
if callable(self.callback): # callback is really callable
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update = self.update_real
|
|
|
|
else:
|
|
|
|
self.update = self.update_empty
|
2005-02-20 00:35:48 +05:30
|
|
|
|
|
|
|
self.plist = {}
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
if not option_box:
|
|
|
|
self.cl_setup()
|
2003-08-02 07:52:34 +05:30
|
|
|
else:
|
2005-02-20 00:35:48 +05:30
|
|
|
self.option_box.parse_options()
|
|
|
|
|
|
|
|
self.restrict = self.option_box.restrict
|
2008-06-16 20:31:46 +05:30
|
|
|
if self.option_box.cfilter is None:
|
2009-07-04 01:53:41 +05:30
|
|
|
self.plist.update((p,1)
|
|
|
|
for p in self.db.iter_person_handles())
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
else:
|
|
|
|
try:
|
2009-07-04 01:53:41 +05:30
|
|
|
self.plist.update((p,1)
|
|
|
|
for p in self.option_box.cfilter.apply(
|
|
|
|
self.db, self.db.iter_person_handles()))
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
except Errors.FilterError, msg:
|
2008-01-15 14:46:45 +05:30
|
|
|
(m1, m2) = msg.messages()
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback(m1, m2)
|
2005-02-20 00:35:48 +05:30
|
|
|
return
|
|
|
|
|
2006-05-10 01:15:18 +05:30
|
|
|
def update_empty(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_real(self):
|
|
|
|
self.count += 1
|
|
|
|
newval = int(100*self.count/self.total)
|
|
|
|
if newval != self.oldval:
|
|
|
|
self.callback(newval)
|
|
|
|
self.oldval = newval
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
def cl_setup(self):
|
|
|
|
self.restrict = True
|
2009-07-04 01:53:41 +05:30
|
|
|
self.plist.update((p,1)
|
|
|
|
for p in self.db.iter_person_handles())
|
2005-02-20 00:35:48 +05:30
|
|
|
|
|
|
|
def export_data(self):
|
2003-07-31 17:28:08 +05:30
|
|
|
name_map = {}
|
|
|
|
id_map = {}
|
|
|
|
id_name = {}
|
2006-05-10 01:15:18 +05:30
|
|
|
self.count = 0
|
|
|
|
self.oldval = 0
|
|
|
|
self.total = 2*len(self.plist)
|
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update()
|
2004-08-07 10:46:57 +05:30
|
|
|
pn = self.db.get_person_from_handle(key).get_primary_name()
|
2004-02-14 11:10:30 +05:30
|
|
|
sn = pn.get_surname()
|
|
|
|
items = pn.get_first_name().split()
|
2009-04-17 00:59:40 +05:30
|
|
|
n = ("%s %s" % (items[0], sn)) if items else sn
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
count = -1
|
2008-07-17 23:40:32 +05:30
|
|
|
if n in name_map:
|
2003-07-31 17:28:08 +05:30
|
|
|
count = 0
|
|
|
|
while 1:
|
2008-01-15 14:46:45 +05:30
|
|
|
nn = "%s%d" % (n, count)
|
2008-07-17 23:40:32 +05:30
|
|
|
if nn not in name_map:
|
2003-07-31 17:28:08 +05:30
|
|
|
break;
|
2003-09-25 04:19:51 +05:30
|
|
|
count += 1
|
2003-07-31 17:28:08 +05:30
|
|
|
name_map[nn] = key
|
|
|
|
id_map[key] = nn
|
|
|
|
else:
|
|
|
|
name_map[n] = key
|
|
|
|
id_map[key] = n
|
2008-01-15 14:46:45 +05:30
|
|
|
id_name[key] = get_name(pn, count)
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
f = open(self.filename,"w")
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2006-05-10 01:15:18 +05:30
|
|
|
self.update()
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_person_from_handle(key)
|
2003-07-31 17:28:08 +05:30
|
|
|
name = id_name[key]
|
2009-04-17 00:59:40 +05:30
|
|
|
father = mother = email = web = ""
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
family_handle = p.get_main_parents_family_handle()
|
|
|
|
if family_handle:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2009-04-17 00:59:40 +05:30
|
|
|
if family.get_father_handle() and \
|
|
|
|
family.get_father_handle() in id_map:
|
2005-02-20 00:35:48 +05:30
|
|
|
father = id_map[family.get_father_handle()]
|
2009-04-17 00:59:40 +05:30
|
|
|
if family.get_mother_handle() and \
|
|
|
|
family.get_mother_handle() in id_map:
|
2005-02-20 00:35:48 +05:30
|
|
|
mother = id_map[family.get_mother_handle()]
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
#
|
|
|
|
# Calculate Date
|
|
|
|
#
|
2006-05-10 01:15:18 +05:30
|
|
|
birth_ref = p.get_birth_ref()
|
|
|
|
death_ref = p.get_death_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.db.get_event_from_handle(birth_ref.ref)
|
2005-02-20 00:35:48 +05:30
|
|
|
birth = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
birth = None
|
2006-05-10 01:15:18 +05:30
|
|
|
if death_ref:
|
|
|
|
death_event = self.db.get_event_from_handle(death_ref.ref)
|
2005-02-20 00:35:48 +05:30
|
|
|
death = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
death = None
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
if self.restrict:
|
2008-01-15 14:46:45 +05:30
|
|
|
alive = Utils.probably_alive(p, self.db)
|
2003-08-02 07:52:34 +05:30
|
|
|
else:
|
|
|
|
alive = 0
|
|
|
|
|
2005-02-20 00:35:48 +05:30
|
|
|
if birth and not alive:
|
|
|
|
if death and not alive :
|
2008-01-15 14:46:45 +05:30
|
|
|
dates = "%s-%s" % (fdate(birth), fdate(death))
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
|
|
|
dates = fdate(birth)
|
|
|
|
else:
|
2005-02-20 00:35:48 +05:30
|
|
|
if death and not alive:
|
2003-07-31 17:28:08 +05:30
|
|
|
dates = fdate(death)
|
|
|
|
else:
|
|
|
|
dates = ""
|
|
|
|
|
2008-01-15 14:46:45 +05:30
|
|
|
f.write('%s;%s;%s;%s;%s;%s\n' % (name, father, mother, email, web,
|
|
|
|
dates))
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
f.close()
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
def fdate(val):
|
2005-02-20 00:35:48 +05:30
|
|
|
if val.get_year_valid():
|
|
|
|
if val.get_month_valid():
|
|
|
|
if val.get_day_valid():
|
2008-01-15 14:46:45 +05:30
|
|
|
return "%d/%d/%d" % (val.get_day(), val.get_month(),
|
|
|
|
val.get_year())
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
2008-01-15 14:46:45 +05:30
|
|
|
return "%d/%d" % (val.get_month(), val.get_year())
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
2005-02-20 00:35:48 +05:30
|
|
|
return "%d" % val.get_year()
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2008-01-15 14:46:45 +05:30
|
|
|
def get_name(name, count):
|
2003-07-31 17:28:08 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
|
|
|
instance, in the form of Firstname Surname"""
|
2009-04-17 19:02:41 +05:30
|
|
|
|
2009-04-17 20:28:25 +05:30
|
|
|
return (name.first_name + ' ' +
|
2009-04-17 19:02:41 +05:30
|
|
|
(name.prefix + ' ' if name.prefix else '') +
|
|
|
|
name.surname +
|
|
|
|
(str(count) if count != -1 else '') +
|
|
|
|
(', ' +name.suffix if name.suffix else '')
|
|
|
|
)
|