* src/ChooseParents.py: Used EditPerson dialog instead of quick add,

select added parent in list
* src/gramps_main.py: eliminated importing of string, display
error if no person selected when trying to export
* src/ListModel.py : explicitly delete renderers and columns due
to memory leak in pygtk 1.99.16
* src/PlaceView.py: explictly delete model due to above memory leak
* src/plugins/pkgexport.glade: don't set height of window
* src/plugins/WriteFtree.py: export to Web Family Tree


svn: r1942
This commit is contained in:
Don Allingham 2003-07-31 11:58:08 +00:00
parent b0fe17bb89
commit d77e1909c6
6 changed files with 245 additions and 9 deletions

View File

@ -401,10 +401,19 @@ class ChooseParents:
self.change_family_type(self.family,mother_rel,father_rel)
self.family_update(None)
def add_new_parent(self,person):
def add_new_parent(self,epo,plist):
"""Adds a new person to either the father list or the mother list,
depending on the gender of the person."""
person = epo.person
id = person.getId()
if id == "":
id = self.db.addPerson(person)
else:
self.db.addPersonNoMap(person,id)
self.db.buildPersonDisplay(id)
self.type = const.save_frel(self.prel.get_text())
dinfo = self.db.getPersonDisplay(id)
rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]]
@ -423,8 +432,15 @@ class ChooseParents:
"""Called with the Add New Person button is pressed. Calls the QuickAdd
class to create a new person."""
import QuickAdd
QuickAdd.QuickAdd(self.db,"male",self.add_new_parent)
person = RelLib.Person()
person.setGender(RelLib.Person.male)
try:
import EditPerson
EditPerson.EditPerson(person,self.db,self.add_new_parent)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
def change_family_type(self,family,mother_rel,father_rel):
"""

View File

@ -41,6 +41,7 @@ class ListModel:
self.count = 0
self.cid = None
self.cids = []
self.objects = []
cnum = 0
for name in dlist:
@ -48,6 +49,10 @@ class ListModel:
renderer.set_fixed_height_from_font(1)
column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
column.set_min_width(name[2])
self.objects.append(renderer)
self.objects.append(column)
if name[0] == '':
column.set_visible(gtk.FALSE)
else:
@ -201,6 +206,7 @@ class ListModel:
self.model.set_value(iter,col,info)
if select:
self.sel_iter = iter
self.selection.select_iter(self.sel_iter)
return iter
def set(self,iter,data,info=None,select=0):
@ -234,3 +240,7 @@ class ListModel:
self.double_click(obj)
return 1
return 0
def cleanup(self):
for obj in self.objects:
del obj

View File

@ -113,6 +113,7 @@ class PlaceView:
on large databases, and should only be called when absolutely
necessary"""
del self.model
self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING, gobject.TYPE_STRING,

View File

@ -23,7 +23,6 @@
# Standard python modules
#
#-------------------------------------------------------------------------
import string
import os
import getopt
@ -168,9 +167,9 @@ class Gramps:
if format not in [ 'gedcom', 'gramps', 'gramps-pkg' ]:
print "Invalid format: %s" % format
os._exit(1)
elif string.upper(fname[-3:]) == "GED":
elif fname[-3:].upper()== "GED":
format = 'gedcom'
elif string.upper(fname[-3:]) == "TGZ":
elif fname[-3:].upper() == "TGZ":
format = 'gramps-pkg'
elif os.path.isdir(fname):
format = 'gramps'
@ -185,9 +184,9 @@ class Gramps:
if outformat not in [ 'gedcom', 'gramps', 'gramps-pkg', 'iso' ]:
print "Invalid format: %s" % outformat
os._exit(1)
elif string.upper(outfname[-3:]) == "GED":
elif outfname[-3:].upper() == "GED":
outformat = 'gedcom'
elif string.upper(outfname[-3:]) == "TGZ":
elif outfname[-3:].upper() == "TGZ":
outformat = 'gramps-pkg'
elif not os.path.isfile(outfname):
if not os.path.isdir(outfname):
@ -1968,6 +1967,10 @@ class Gramps:
"""Call the export plugin, with the active person and database"""
if self.active_person:
plugin_function(self.db,self.active_person)
else:
ErrorDialog(_('A person must be selected to export'),
_('Exporting requires that an active person be selected. '
'Please select a person and try again.'))
def import_callback(self,obj,plugin_function):
"""Call the import plugin"""

View File

@ -0,0 +1,207 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2003 Donald N. Allingham
#
# 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
#
"Export to Web Family Tree"
#-------------------------------------------------------------------------
#
# standard python modules
#
#-------------------------------------------------------------------------
import time
import os
from cStringIO import StringIO
#-------------------------------------------------------------------------
#
# GNOME/GTK modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import WriteXML
import TarFile
import Utils
from QuestionDialog import MissingMediaDialog
from intl import gettext as _
_title_string = _("Export to Web Family Tree")
#-------------------------------------------------------------------------
#
# writeData
#
#-------------------------------------------------------------------------
def writeData(database,person):
try:
FtreeWriter(database)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
#-------------------------------------------------------------------------
#
# FtreeWriter
#
#-------------------------------------------------------------------------
class FtreeWriter:
def __init__(self,database):
self.db = database
base = os.path.dirname(__file__)
glade_file = "%s/%s" % (base,"pkgexport.glade")
dic = {
"destroy_passed_object" : Utils.destroy_passed_object,
"on_ok_clicked" : self.on_ok_clicked
}
self.top = gtk.glade.XML(glade_file,"packageExport")
Utils.set_titles(self.top.get_widget('packageExport'),
self.top.get_widget('title'),
_title_string)
self.top.signal_autoconnect(dic)
self.top.get_widget("packageExport").show()
def on_ok_clicked(self,obj):
name = self.top.get_widget("filename").get_text()
Utils.destroy_passed_object(obj)
try:
self.export(name)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
def export(self, filename):
name_map = {}
id_map = {}
id_name = {}
for key in self.db.getPersonKeys():
pn = self.db.getPerson(key).getPrimaryName()
fn = ""
sn = pn.getSurname()
items = pn.getFirstName().split()
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;
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")
for key in self.db.getPersonKeys():
p = self.db.getPerson(key)
name = id_name[key]
father = ""
mother = ""
email = ""
web = ""
family = p.getMainParents()
if family:
if family.getFather():
father = id_map[family.getFather().getId()]
if family.getMother():
mother = id_map[family.getMother().getId()]
#
# Calculate Date
#
birth = p.getBirth().getDateObj()
death = p.getDeath().getDateObj()
if birth.isValid():
if death.isValid():
dates = "%s-%s" % (fdate(birth),fdate(death))
else:
dates = fdate(birth)
else:
if death.isValid():
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)

View File

@ -11,7 +11,6 @@
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
<property name="default_width">400</property>
<property name="default_height">350</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="has_separator">False</property>