2003-07-31 17:28:08 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-01-18 07:29:30 +05:30
|
|
|
# Copyright (C) 2003-2004 Donald N. Allingham
|
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
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2003-12-07 04:35:52 +05:30
|
|
|
import gnome
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
2003-08-02 07:52:34 +05:30
|
|
|
import GenericFilter
|
|
|
|
import Errors
|
|
|
|
|
2004-01-18 07:29:30 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
_title_string = _("Export to Web Family Tree")
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# writeData
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def writeData(database,person):
|
|
|
|
try:
|
2003-08-02 07:52:34 +05:30
|
|
|
FtreeWriter(database,person)
|
2003-07-31 17:28:08 +05:30
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FtreeWriter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class FtreeWriter:
|
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
def __init__(self,database,person,cl=0,name=""):
|
2003-07-31 17:28:08 +05:30
|
|
|
self.db = database
|
2003-09-16 07:05:09 +05:30
|
|
|
self.person = person
|
|
|
|
self.plist = {}
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
if cl:
|
|
|
|
if name:
|
|
|
|
self.export(name,None,0)
|
|
|
|
else:
|
|
|
|
base = os.path.dirname(__file__)
|
|
|
|
glade_file = "%s/%s" % (base,"writeftree.glade")
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
dic = {
|
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_ok_clicked" : self.on_ok_clicked,
|
2003-12-07 04:35:52 +05:30
|
|
|
"on_help_clicked" : self.on_help_clicked,
|
2003-09-16 07:05:09 +05:30
|
|
|
}
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
self.top = gtk.glade.XML(glade_file,"top","gramps")
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
Utils.set_titles(self.top.get_widget('top'),
|
2003-07-31 17:28:08 +05:30
|
|
|
self.top.get_widget('title'),
|
|
|
|
_title_string)
|
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
self.top.signal_autoconnect(dic)
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
self.topwin = self.top.get_widget("top")
|
|
|
|
self.restrict = self.top.get_widget("restrict")
|
|
|
|
self.filter = self.top.get_widget("filter")
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
all = GenericFilter.GenericFilter()
|
|
|
|
all.set_name(_("Entire Database"))
|
|
|
|
all.add_rule(GenericFilter.Everyone([]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
des = GenericFilter.GenericFilter()
|
2004-02-14 11:10:30 +05:30
|
|
|
des.set_name(_("Descendants of %s") % person.get_primary_name().get_name())
|
|
|
|
des.add_rule(GenericFilter.IsDescendantOf([person.get_id()]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
ans = GenericFilter.GenericFilter()
|
2004-02-14 11:10:30 +05:30
|
|
|
ans.set_name(_("Ancestors of %s") % person.get_primary_name().get_name())
|
|
|
|
ans.add_rule(GenericFilter.IsAncestorOf([person.get_id()]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
com = GenericFilter.GenericFilter()
|
|
|
|
com.set_name(_("People with common ancestor with %s") %
|
2004-02-14 11:10:30 +05:30
|
|
|
person.get_primary_name().get_name())
|
|
|
|
com.add_rule(GenericFilter.HasCommonAncestorWith([person.get_id()]))
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com])
|
|
|
|
self.filter.set_menu(self.filter_menu)
|
2003-08-02 07:52:34 +05:30
|
|
|
|
2003-09-16 07:05:09 +05:30
|
|
|
self.topwin.show()
|
2003-08-02 07:52:34 +05:30
|
|
|
|
|
|
|
def close(self,obj):
|
|
|
|
self.topwin.destroy()
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
def on_ok_clicked(self,obj):
|
|
|
|
name = self.top.get_widget("filename").get_text()
|
2003-08-02 07:52:34 +05:30
|
|
|
restrict = self.top.get_widget('restrict').get_active()
|
|
|
|
pfilter = self.filter_menu.get_active().get_data("filter")
|
|
|
|
|
|
|
|
Utils.destroy_passed_object(self.topwin)
|
2003-07-31 17:28:08 +05:30
|
|
|
try:
|
2003-08-02 07:52:34 +05:30
|
|
|
self.export(name, pfilter, restrict)
|
2003-11-11 04:01:07 +05:30
|
|
|
except (IOError,OSError),msg:
|
|
|
|
ErrorDialog(_("Could not create %s") % name, msg)
|
2003-07-31 17:28:08 +05:30
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
|
|
|
|
2003-12-07 04:35:52 +05:30
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','export-data')
|
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
def export(self, filename, cfilter, restrict ):
|
|
|
|
|
|
|
|
if cfilter == None:
|
2004-02-14 11:10:30 +05:30
|
|
|
for p in self.db.get_person_keys():
|
2003-08-02 07:52:34 +05:30
|
|
|
self.plist[p] = 1
|
|
|
|
else:
|
|
|
|
try:
|
2004-02-14 11:10:30 +05:30
|
|
|
for p in cfilter.apply(self.db, self.db.get_person_id_map().values()):
|
|
|
|
self.plist[p.get_id()] = 1
|
2003-08-02 07:52:34 +05:30
|
|
|
except Errors.FilterError, msg:
|
|
|
|
(m1,m2) = msg.messages()
|
|
|
|
ErrorDialog(m1,m2)
|
|
|
|
return
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
name_map = {}
|
|
|
|
id_map = {}
|
|
|
|
id_name = {}
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2004-02-14 11:10:30 +05:30
|
|
|
pn = self.db.get_person(key).get_primary_name()
|
2003-07-31 17:28:08 +05:30
|
|
|
fn = ""
|
2004-02-14 11:10:30 +05:30
|
|
|
sn = pn.get_surname()
|
|
|
|
items = pn.get_first_name().split()
|
2003-07-31 17:28:08 +05:30
|
|
|
if len(items) > 0:
|
|
|
|
n = "%s %s" % (items[0],sn)
|
|
|
|
else:
|
|
|
|
n = sn
|
|
|
|
|
|
|
|
count = -1
|
|
|
|
if name_map.has_key(n):
|
|
|
|
count = 0
|
|
|
|
while 1:
|
|
|
|
nn = "%s%d" % (n,count)
|
|
|
|
if not name_map.has_key(nn):
|
|
|
|
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
|
|
|
|
id_name[key] = get_name(pn,count)
|
|
|
|
|
|
|
|
f = open(filename,"w")
|
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
for key in self.plist:
|
2004-02-14 11:10:30 +05:30
|
|
|
p = self.db.get_person(key)
|
2003-07-31 17:28:08 +05:30
|
|
|
name = id_name[key]
|
|
|
|
father = ""
|
|
|
|
mother = ""
|
|
|
|
email = ""
|
|
|
|
web = ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
family = p.get_main_parents_family_id()
|
2003-07-31 17:28:08 +05:30
|
|
|
if family:
|
2004-02-14 11:10:30 +05:30
|
|
|
if family.get_father_id() and id_map.has_key(family.get_father_id().get_id()):
|
|
|
|
father = id_map[family.get_father_id().get_id()]
|
|
|
|
if family.get_mother_id() and id_map.has_key(family.get_mother_id().get_id()):
|
|
|
|
mother = id_map[family.get_mother_id().get_id()]
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
#
|
|
|
|
# Calculate Date
|
|
|
|
#
|
2004-02-14 11:10:30 +05:30
|
|
|
birth = p.get_birth().get_date_object()
|
|
|
|
death = p.get_death().get_date_object()
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-08-02 07:52:34 +05:30
|
|
|
if restrict:
|
2004-03-11 09:58:17 +05:30
|
|
|
alive = p.probably_alive(db)
|
2003-08-02 07:52:34 +05:30
|
|
|
else:
|
|
|
|
alive = 0
|
|
|
|
|
|
|
|
if birth.isValid() and not alive:
|
|
|
|
if death.isValid() and not alive :
|
2003-07-31 17:28:08 +05:30
|
|
|
dates = "%s-%s" % (fdate(birth),fdate(death))
|
|
|
|
else:
|
|
|
|
dates = fdate(birth)
|
|
|
|
else:
|
2003-08-02 07:52:34 +05:30
|
|
|
if death.isValid() and not alive:
|
2003-07-31 17:28:08 +05:30
|
|
|
dates = fdate(death)
|
|
|
|
else:
|
|
|
|
dates = ""
|
|
|
|
|
|
|
|
f.write('%s;%s;%s;%s;%s;%s\n' % (name,father,mother,email,web,dates))
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def fdate(val):
|
|
|
|
if val.getYearValid():
|
|
|
|
if val.getMonthValid():
|
|
|
|
if val.getDayValid():
|
|
|
|
return "%d/%d/%d" % (val.getDay(),val.getMonth(),val.getYear())
|
|
|
|
else:
|
|
|
|
return "%d/%d" % (val.getMonth(),val.getYear())
|
|
|
|
else:
|
|
|
|
return "%d" % val.getYear()
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def get_name(name,count):
|
|
|
|
"""returns a name string built from the components of the Name
|
|
|
|
instance, in the form of Firstname Surname"""
|
|
|
|
if count == -1:
|
|
|
|
val = ""
|
|
|
|
else:
|
|
|
|
val = str(count)
|
|
|
|
|
|
|
|
if (name.Suffix == ""):
|
|
|
|
if name.Prefix:
|
|
|
|
return "%s %s %s%s" % (name.FirstName, name.Prefix, name.Surname, val)
|
|
|
|
else:
|
|
|
|
return "%s %s%s" % (name.FirstName, name.Surname, val)
|
|
|
|
else:
|
|
|
|
if name.Prefix:
|
|
|
|
return "%s %s %s%s, %s" % (name.FirstName, name.Prefix, name.Surname, val, name.Suffix)
|
|
|
|
else:
|
|
|
|
return "%s %s%s, %s" % (name.FirstName, name.Surname, val, name.Suffix)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from Plugins import register_export
|
|
|
|
|
|
|
|
register_export(writeData,_title_string)
|