* src/PedView.py: Fix remnants of gnome.canvas syntax.

* src/ReadGrdb.py: Add to CVS: native database importer.
* src/DbPrompter.py: Support for the native importer.
* src/Errors.py: Add HandleError exception for duplicate handles.


svn: r3984
This commit is contained in:
Alex Roitman 2005-01-29 05:13:29 +00:00
parent 5358395685
commit ffd374025f
5 changed files with 216 additions and 23 deletions

View File

@ -1,3 +1,9 @@
2005-01-28 Alex Roitman <shura@alex.neuro.umn.edu>
* src/PedView.py: Fix remnants of gnome.canvas syntax.
* src/ReadGrdb.py: Add to CVS: native database importer.
* src/DbPrompter.py: Support for the native importer.
* src/Errors.py: Add HandleError exception for duplicate handles.
2005-01-26 Don Allingham <dallingham@users.sourceforge.net> 2005-01-26 Don Allingham <dallingham@users.sourceforge.net>
* src/DbPrompter.py: gnome.vfs vs. gnomevfs, tolerence * src/DbPrompter.py: gnome.vfs vs. gnomevfs, tolerence
* src/GrampsMime.py: gnome.vfs vs. gnomevfs tolerence * src/GrampsMime.py: gnome.vfs vs. gnomevfs tolerence

View File

@ -249,12 +249,11 @@ class ImportDbPrompter:
mime_filter.add_pattern('*') mime_filter.add_pattern('*')
choose.add_filter(mime_filter) choose.add_filter(mime_filter)
# FIXME: Uncomment when we have grdb importer # Always add native format filter
# # Always add native format filter mime_filter = gtk.FileFilter()
# mime_filter = gtk.FileFilter() mime_filter.set_name(_('GRAMPS databases'))
# mime_filter.set_name(_('GRAMPS databases')) mime_filter.add_mime_type(const.app_gramps)
# mime_filter.add_mime_type(const.app_gramps) choose.add_filter(mime_filter)
# choose.add_filter(mime_filter)
# Add more data type selections if opening existing db # Add more data type selections if opening existing db
for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list: for (importData,mime_filter,mime_type,native_format) in PluginMgr.import_list:
@ -275,12 +274,13 @@ class ImportDbPrompter:
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
filename = choose.get_filename() filename = choose.get_filename()
filetype = get_mime_type(filename) filetype = get_mime_type(filename)
# FIXME: Uncomment when we have grdb importer
# if filetype == 'application/x-gramps':
# if filetype == 'application/x-gramps': choose.destroy()
# choose.destroy() import ReadGrdb
# self.parent.read_file(filename) ReadGrdb.importData(self.parent.db,filename)
# return True self.parent.import_tool_callback()
return True
(the_path,the_file) = os.path.split(filename) (the_path,the_file) = os.path.split(filename)
GrampsKeys.save_last_import_dir(the_path) GrampsKeys.save_last_import_dir(the_path)

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2003 Donald N. Allingham # Copyright (C) 2003-2005 Donald N. Allingham
# #
# 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
@ -18,6 +18,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id$
class FilterError(Exception): class FilterError(Exception):
"""Error used to report Filter errors""" """Error used to report Filter errors"""
def __init__(self,value,value2=""): def __init__(self,value,value2=""):
@ -70,3 +72,12 @@ class PluginError(Exception):
def __str__(self): def __str__(self):
return self.value return self.value
class HandleError(Exception):
"""Error used to report wrong database handle errors"""
def __init__(self,value):
Exception.__init__(self)
self.value = value
def __str__(self):
return self.value

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2001-2004 Donald N. Allingham # Copyright (C) 2001-2005 Donald N. Allingham
# #
# 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
@ -98,8 +98,8 @@ class DispBox:
self.exp = "%s" % self.name self.exp = "%s" % self.name
self.group = self.root.add(gnome.canvas.CanvasGroup,x=x,y=y) self.group = self.root.add(CanvasGroup,x=x,y=y)
self.shadow = self.group.add(gnome.canvas.CanvasRect, self.shadow = self.group.add(CanvasRect,
x1=shadow, x1=shadow,
y1=shadow, y1=shadow,
x2=w+shadow, x2=w+shadow,
@ -108,7 +108,7 @@ class DispBox:
fill_color_gdk=style.dark[gtk.STATE_NORMAL]) fill_color_gdk=style.dark[gtk.STATE_NORMAL])
# draw the real box # draw the real box
self.bkgnd = self.group.add(gnome.canvas.CanvasRect, self.bkgnd = self.group.add(CanvasRect,
x1=0, x1=0,
y1=0, y1=0,
x2=w, x2=w,
@ -117,7 +117,7 @@ class DispBox:
fill_color_gdk=style.base[gtk.STATE_NORMAL]) fill_color_gdk=style.base[gtk.STATE_NORMAL])
font = gtk.gdk.font_from_description(style.font_desc) font = gtk.gdk.font_from_description(style.font_desc)
self.textbox = self.group.add(gnome.canvas.CanvasText, self.textbox = self.group.add(CanvasText,
x=xpad, x=xpad,
y=h/2.0, y=h/2.0,
text=self.name, text=self.name,
@ -265,7 +265,7 @@ class PedigreeView:
xpts = self.build_x_coords(cw/xdiv,_CANVASPAD+h) xpts = self.build_x_coords(cw/xdiv,_CANVASPAD+h)
ypts = self.build_y_coords((ch-h)/32.0, h) ypts = self.build_y_coords((ch-h)/32.0, h)
self.anchor_txt = self.root.add(gnome.canvas.CanvasText, self.anchor_txt = self.root.add(CanvasText,
x=0, x=0,
y=y2-12, y=y2-12,
font=font, font=font,
@ -279,7 +279,7 @@ class PedigreeView:
if len(family.get_child_handle_list()) > 0: if len(family.get_child_handle_list()) > 0:
button,arrow = self.make_arrow_button(gtk.ARROW_LEFT, button,arrow = self.make_arrow_button(gtk.ARROW_LEFT,
self.on_show_child_menu) self.on_show_child_menu)
item = self.root.add(gnome.canvas.CanvasWidget, widget=button, item = self.root.add(CanvasWidget, widget=button,
x=_CANVASPAD, y=ypts[0]+(h/2.0), x=_CANVASPAD, y=ypts[0]+(h/2.0),
height=h, width=h, height=h, width=h,
size_pixels=1, anchor=gtk.ANCHOR_WEST) size_pixels=1, anchor=gtk.ANCHOR_WEST)
@ -305,7 +305,7 @@ class PedigreeView:
gen_no = len(firstRel)-len(secondRel) gen_no = len(firstRel)-len(secondRel)
for i in range(int(xdiv)): for i in range(int(xdiv)):
item = self.root.add(gnome.canvas.CanvasText, x=(cw*i/xdiv + cpad), y=h, item = self.root.add(CanvasText, x=(cw*i/xdiv + cpad), y=h,
text=str(gen_no), text=str(gen_no),
font=font, font=font,
anchor=gtk.ANCHOR_WEST) anchor=gtk.ANCHOR_WEST)
@ -422,7 +422,7 @@ class PedigreeView:
button,arrow = self.make_arrow_button(gtk.ARROW_RIGHT,self.change_to_parent) button,arrow = self.make_arrow_button(gtk.ARROW_RIGHT,self.change_to_parent)
button.set_data(_PERSON,parent.get_handle()) button.set_data(_PERSON,parent.get_handle())
item = self.root.add(gnome.canvas.CanvasWidget, widget=button, x=x, y=y+(h/2), item = self.root.add(CanvasWidget, widget=button, x=x, y=y+(h/2),
height=h, width=h, size_pixels=1, height=h, width=h, size_pixels=1,
anchor=gtk.ANCHOR_EAST) anchor=gtk.ANCHOR_EAST)
self.canvas_items.append(arrow) self.canvas_items.append(arrow)
@ -445,7 +445,7 @@ class PedigreeView:
startx = x1+(w/2.0) startx = x1+(w/2.0)
pts = [startx,y1, startx,y2+(h/2.0), x2,y2+(h/2.0)] pts = [startx,y1, startx,y2+(h/2.0), x2,y2+(h/2.0)]
item = self.root.add(gnome.canvas.CanvasLine, width_pixels=2, item = self.root.add(CanvasLine, width_pixels=2,
points=pts, line_style=ls, points=pts, line_style=ls,
fill_color_gdk=style.fg[gtk.STATE_NORMAL]) fill_color_gdk=style.fg[gtk.STATE_NORMAL])
item.set_data(_PERSON,data.get_handle()) item.set_data(_PERSON,data.get_handle())

176
gramps2/src/ReadGrdb.py Normal file
View File

@ -0,0 +1,176 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2005 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
#
# $Id$
# Written by Alex Roitman,
# largely based on ReadXML by Don Allingham
#-------------------------------------------------------------------------
#
# Standard Python Modules
#
#-------------------------------------------------------------------------
import os
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# Gramps Modules
#
#-------------------------------------------------------------------------
import GrampsBSDDB
from QuestionDialog import ErrorDialog
import Errors
#-------------------------------------------------------------------------
#
# Importing data into the currently open database.
#
#-------------------------------------------------------------------------
def importData(database, filename, callback=None,cl=0,use_trans=True):
filename = os.path.normpath(filename)
basefile = os.path.dirname(filename)
change = os.path.getmtime(filename)
other_database = GrampsBSDDB.GrampsBSDDB()
try:
other_database.load(filename,callback)
except:
if cl:
print "Error: %s could not be opened. Exiting." % filename
else:
ErrorDialog(_("%s could not be opened") % filename)
return
trans = database.transaction_begin()
# copy all data from new_database to database,
# rename gramps IDs of first-class objects when conflicts are found
# People table
for person_handle in other_database.person_map.keys():
person = other_database.get_person_from_handle(person_handle)
# First, check whether this handle is a duplicate, and do something
if person_handle in database.person_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.\n'
'Name: %s' % (person_handle,person.get_primary_name().get_regular_name())
)
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(person.get_gramps_id())
if database.id_trans.has_key(gramps_id):
gramps_id = database.find_next_person_gramps_id()
person.set_gramps_id(gramps_id)
database.add_person(person,trans)
# Family table
for family_handle in other_database.family_map.keys():
family = other_database.get_family_from_handle(family_handle)
# First, check whether this handle is a duplicate, and do something
if family_handle in database.family_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.' % family_handle
)
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(family.get_gramps_id())
if database.fid_trans.has_key(gramps_id):
gramps_id = database.find_next_family_gramps_id()
family.set_gramps_id(gramps_id)
database.add_family(family,trans)
# Place table
for place_handle in other_database.place_map.keys():
place = other_database.get_place_from_handle(place_handle)
# First, check whether this handle is a duplicate, and do something
if place_handle in database.place_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.' % place_handle
)
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(place.get_gramps_id())
if database.pid_trans.has_key(gramps_id):
gramps_id = database.find_next_place_gramps_id()
place.set_gramps_id(gramps_id)
database.add_place(place,trans)
# Source table
for source_handle in other_database.source_map.keys():
source = other_database.get_source_from_handle(source_handle)
# First, check whether this handle is a duplicate, and do something
if source_handle in database.source_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.' % source_handle
)
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(source.get_gramps_id())
if database.sid_trans.has_key(gramps_id):
gramps_id = database.find_next_source_gramps_id()
source.set_gramps_id(gramps_id)
database.add_source(source,trans)
# Media table
for media_handle in other_database.media_map.keys():
media = other_database.get_object_from_handle(media_handle)
# First, check whether this handle is a duplicate, and do something
if media_handle in database.media_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.' % media_handle
)
# Then we check gramps_id for conflicts and change it if needed
gramps_id = str(media.get_gramps_id())
if database.oid_trans.has_key(gramps_id):
gramps_id = database.find_next_object_gramps_id()
media.set_gramps_id(gramps_id)
database.add_object(media,trans)
# Event table
for event_handle in other_database.event_map.keys():
event = other_database.get_event_from_handle(event_handle)
# First, check whether this handle is a duplicate, and do something
if event_handle in database.event_map.keys():
raise Errors.HandleError(
'Handle %s is already present in the opened database.' % event_handle
)
# Events don't have gramps IDs, so we don't need to check here
database.add_event(event,trans)
database.transaction_commit(trans,_("Import database"))