From 245fa23f640024f41b733a359a1d51314362f639 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 11 Apr 2004 02:37:13 +0000 Subject: [PATCH] * src/Bookmarks.py: use IDs instead of person references * src/ChooseParents.py: allow for NOSORT option * src/GrampsParser.py: removed * src/GrampsXML.py: removed * src/MediaView.py: allow for NOSORT option * src/PedView.py: double click to edit * src/PeopleView.py: allow for NOSORT option * src/PlaceView.py: allow for NOSORT option * src/RelLib.py: handle bookmarks in metadata * src/ReadXML.py: merge GrampsParser * src/SourceView.py: allow for NOSORT option * src/const.py.in: fix paths for xml files * src/gramps_main.py: bookmark fixes * src/papersize.xml : move to data subdirectory * src/plugins/ReadGedcom.py: fix menu string * src/plugins/ReadNative.py: fix menu string * src/plugins/ReadPkg.py: fix menu string svn: r3085 --- gramps2/ChangeLog | 19 + gramps2/Makefile.am | 2 +- gramps2/src/Bookmarks.py | 2 +- gramps2/src/ChooseParents.py | 13 +- gramps2/src/GrampsParser.py | 1066 -------------------------- gramps2/src/GrampsXML.py | 42 - gramps2/src/Makefile.am | 6 +- gramps2/src/Makefile.in | 4 - gramps2/src/MediaView.py | 25 +- gramps2/src/PedView.py | 10 +- gramps2/src/PeopleView.py | 9 +- gramps2/src/PlaceView.py | 25 +- gramps2/src/ReadXML.py | 1000 +++++++++++++++++++++--- gramps2/src/RelLib.py | 5 +- gramps2/src/SourceView.py | 23 +- gramps2/src/const.py.in | 12 +- gramps2/src/data/Makefile.am | 2 +- gramps2/src/{ => data}/papersize.xml | 0 gramps2/src/gramps_main.py | 11 +- gramps2/src/plugins/Makefile.in | 1 - gramps2/src/plugins/ReadGedcom.py | 2 +- gramps2/src/plugins/ReadNative.py | 2 +- gramps2/src/plugins/ReadPkg.py | 2 +- 23 files changed, 998 insertions(+), 1285 deletions(-) delete mode 100644 gramps2/src/GrampsParser.py delete mode 100644 gramps2/src/GrampsXML.py rename gramps2/src/{ => data}/papersize.xml (100%) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 57098ddfd..a5838478f 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,22 @@ +2004-04-10 Don Allingham + * src/Bookmarks.py: use IDs instead of person references + * src/ChooseParents.py: allow for NOSORT option + * src/GrampsParser.py: removed + * src/GrampsXML.py: removed + * src/MediaView.py: allow for NOSORT option + * src/PedView.py: double click to edit + * src/PeopleView.py: allow for NOSORT option + * src/PlaceView.py: allow for NOSORT option + * src/RelLib.py: handle bookmarks in metadata + * src/ReadXML.py: merge GrampsParser + * src/SourceView.py: allow for NOSORT option + * src/const.py.in: fix paths for xml files + * src/gramps_main.py: bookmark fixes + * src/papersize.xml : move to data subdirectory + * src/plugins/ReadGedcom.py: fix menu string + * src/plugins/ReadNative.py: fix menu string + * src/plugins/ReadPkg.py: fix menu string + 2004-04-07 Don Allingham * src/choose.glade: merged into gramps.glade * src/styles.glade: merged into gramps.glade diff --git a/gramps2/Makefile.am b/gramps2/Makefile.am index 5c7a541be..f28bd5533 100644 --- a/gramps2/Makefile.am +++ b/gramps2/Makefile.am @@ -10,7 +10,7 @@ gramps: gramps.sh cp gramps.sh gramps .PHONY: pycheck trans - + pycheck: (cd src; make pycheck) trans: diff --git a/gramps2/src/Bookmarks.py b/gramps2/src/Bookmarks.py index 256e9b605..4e6733641 100644 --- a/gramps2/src/Bookmarks.py +++ b/gramps2/src/Bookmarks.py @@ -143,7 +143,7 @@ class Bookmarks : """ self.draw_window() index = 0 - for person in self.bookmarks: + for person_id in self.bookmarks: data = self.db.person_map.get(str(person_id)) name = data[2].get_name() self.namelist.append([name]) diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index bd020dde7..c11d4aae8 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -34,6 +34,7 @@ __version__ = "$Revision$" # #------------------------------------------------------------------------- from gettext import gettext as _ +import os #------------------------------------------------------------------------- # @@ -75,6 +76,7 @@ class ChooseParents: family_update - task that updates the family display full_update - task that updates the main display """ + self.nosort = os.environ.has_key('NOSORT') self.parent = parent self.db = db self.child_windows = {} @@ -294,7 +296,10 @@ class ChooseParents: def redrawf(self): """Redraws the potential father list""" self.father_nsort = PeopleModel.PeopleModel(self.db, self.father_filter) - self.father_model = gtk.TreeModelSort(self.father_nsort) + if self.nosort: + self.father_model = self.father_nsort + else: + self.father_model = gtk.TreeModelSort(self.father_nsort) self.father_list.set_model(self.father_model) if self.type == "Partners": self.flabel.set_label("%s" % _("Par_ent")) @@ -304,7 +309,11 @@ class ChooseParents: def redrawm(self): """Redraws the potential mother list""" self.mother_nsort = PeopleModel.PeopleModel(self.db, self.mother_filter) - self.mother_model = gtk.TreeModelSort(self.mother_nsort) + if self.nosort: + self.mother_model = self.mother_nsort + else: + self.mother_model = gtk.TreeModelSort(self.mother_nsort) + self.mother_list.set_model(self.mother_model) if self.type == "Partners": self.mlabel.set_label("%s" % _("Pa_rent")) diff --git a/gramps2/src/GrampsParser.py b/gramps2/src/GrampsParser.py deleted file mode 100644 index dcb7aef54..000000000 --- a/gramps2/src/GrampsParser.py +++ /dev/null @@ -1,1066 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2004 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$ - -import const -import RelLib -import Date - -import string -import Calendar -import Utils -import GrampsMime -import xml.parsers.expat - -#------------------------------------------------------------------------- -# -# Remove extraneous spaces -# -#------------------------------------------------------------------------- - -def rs(text): - return string.join(string.split(text)) - -def fix_spaces(text_list): - return string.join(map(rs,text_list),'\n') - -#------------------------------------------------------------------------- -# -# Gramps database parsing class. Derived from SAX XML parser -# -#------------------------------------------------------------------------- -class GrampsParser: - - def __init__(self,database,callback,base): - self.stext_list = [] - self.scomments_list = [] - self.note_list = [] - self.tlist = [] - self.conf = 2 - - self.ord = None - self.objref = None - self.object = None - self.pref = None - self.use_p = 0 - self.in_note = 0 - self.in_stext = 0 - self.in_scomments = 0 - self.in_witness = 0 - self.db = database - self.base = base - self.photo = None - self.person = None - self.family = None - self.address = None - self.source = None - self.source_ref = None - self.attribute = None - self.placeobj = None - self.locations = 0 - self.place_map = {} - - self.resname = "" - self.resaddr = "" - self.rescity = "" - self.resstate = "" - self.rescon = "" - self.respos = "" - self.resphone = "" - self.resemail = "" - - self.pmap = {} - self.fmap = {} - self.smap = {} - self.lmap = {} - self.media_file_map = {} - - self.callback = callback - self.entries = 0 - self.count = 0 - self.increment = 100 - self.event = None - self.name = None - self.tempDefault = None - self.owner = RelLib.Researcher() - self.func_list = [None]*50 - self.func_index = 0 - self.func = None - self.witness_comment = "" - - self.func_map = { - "address" : (self.start_address, self.stop_address), - "addresses" : (None,None), - "childlist" : (None,None), - "aka" : (self.start_name, self.stop_aka), - "attribute" : (self.start_attribute, self.stop_attribute), - "attr_type" : (None,self.stop_attr_type), - "attr_value" : (None,self.stop_attr_value), - "bookmark" : (self.start_bmark, None), - "witness" : (self.start_witness,self.stop_witness), - "bookmarks" : (None, None), - "child" : (self.start_child,None), - "childof" : (self.start_childof,None), - "city" : (None, self.stop_city), - "country" : (None, self.stop_country), - "comment" : (None, self.stop_comment), - "created" : (self.start_created, None), - "ref" : (None, self.stop_ref), - "database" : (None, None), - "phone" : (None, self.stop_phone), - "date" : (None, self.stop_date), - "cause" : (None, self.stop_cause), - "description": (None, self.stop_description), - "event" : (self.start_event, self.stop_event), - "families" : (None, self.stop_families), - "family" : (self.start_family, self.stop_family), - "father" : (self.start_father, None), - "first" : (None, self.stop_first), - "gender" : (None, self.stop_gender), - "header" : (None, None), - "last" : (self.start_last, self.stop_last), - "mother" : (self.start_mother,None), - "name" : (self.start_name, self.stop_name), - "nick" : (None, self.stop_nick), - "note" : (self.start_note, self.stop_note), - "p" : (None, self.stop_ptag), - "parentin" : (self.start_parentin,None), - "people" : (self.start_people, self.stop_people), - "person" : (self.start_person, self.stop_person), - "img" : (self.start_photo, self.stop_photo), - "objref" : (self.start_objref, self.stop_objref), - "object" : (self.start_object, self.stop_object), - "place" : (self.start_place, self.stop_place), - "dateval" : (self.start_dateval, None), - "daterange" : (self.start_daterange, None), - "datestr" : (self.start_datestr, None), - "places" : (None, self.stop_places), - "placeobj" : (self.start_placeobj,self.stop_placeobj), - "location" : (self.start_location,None), - "lds_ord" : (self.start_lds_ord, self.stop_lds_ord), - "temple" : (self.start_temple, None), - "status" : (self.start_status, None), - "sealed_to" : (self.start_sealed_to, None), - "coord" : (self.start_coord,None), - "pos" : (self.start_pos, None), - "postal" : (None, self.stop_postal), - "researcher" : (None, self.stop_research), - "resname" : (None, self.stop_resname ), - "resaddr" : (None, self.stop_resaddr ), - "rescity" : (None, self.stop_rescity ), - "resstate" : (None, self.stop_resstate ), - "rescountry" : (None, self.stop_rescountry), - "respostal" : (None, self.stop_respostal), - "resphone" : (None, self.stop_resphone), - "resemail" : (None, self.stop_resemail), - "sauthor" : (None, self.stop_sauthor), - "sabbrev" : (None, self.stop_sabbrev), - "scomments" : (None, self.stop_scomments), - "sdate" : (None,self.stop_sdate), - "source" : (self.start_source, self.stop_source), - "sourceref" : (self.start_sourceref, self.stop_sourceref), - "sources" : (None, None), - "spage" : (None, self.stop_spage), - "spubinfo" : (None, self.stop_spubinfo), - "state" : (None, self.stop_state), - "stext" : (None, self.stop_stext), - "stitle" : (None, self.stop_stitle), - "street" : (None, self.stop_street), - "suffix" : (None, self.stop_suffix), - "title" : (None, self.stop_title), - "url" : (self.start_url, None) - } - - - def parse(self,file): - p = xml.parsers.expat.ParserCreate() - p.StartElementHandler = self.startElement - p.EndElementHandler = self.endElement - p.CharacterDataHandler = self.characters - p.ParseFile(file) - - self.db.set_researcher(self.owner) - if self.tempDefault != None: - id = self.tempDefault - if self.db.has_person_id(id) and self.db.get_default_person() == None: - self.db.set_default_person_id(id) - - for key in self.func_map.keys(): - del self.func_map[key] - del self.func_map - del self.func_list - del p - - def start_lds_ord(self,attrs): - type = attrs['type'] - self.ord = RelLib.LdsOrd() - if self.person: - if type == "baptism": - self.person.set_lds_baptism(self.ord) - elif type == "endowment": - self.person.set_lds_endowment(self.ord) - elif type == "sealed_to_parents": - self.person.set_lds_sealing(self.ord) - elif self.family: - if type == "sealed_to_spouse": - self.family.set_lds_sealing(self.ord) - - def start_temple(self,attrs): - self.ord.set_temple(attrs['val']) - - def start_status(self,attrs): - self.ord.set_status(int(attrs['val'])) - - def start_sealed_to(self,attrs): - id = attrs['ref'] - self.ord.set_family_id(self.db.find_family_no_map(id)) - - def start_place(self,attrs): - if attrs.has_key('ref'): - self.placeobj = self.db.find_place_from_id(attrs['ref']) - else: - self.placeobj = None - - def start_placeobj(self,attrs): - self.placeobj = self.db.find_place_from_id(attrs['id']) - title = attrs['title'] - if title == "": - title = attrs['id'] - self.placeobj.set_title(title) - self.locations = 0 - if self.num_places > 0: - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - - def start_location(self,attrs): - """Bypass the function calls for this one, since it appears to - take up quite a bit of time""" - - loc = RelLib.Location() - if attrs.has_key('phone'): - loc.phone = attrs['phone'] - if attrs.has_key('postal'): - loc.postal = attrs['postal'] - if attrs.has_key('city'): - loc.city = attrs['city'] - if attrs.has_key('parish'): - loc.parish = attrs['parish'] - if attrs.has_key('state'): - loc.state = attrs['state'] - if attrs.has_key('county'): - loc.county =attrs['county'] - if attrs.has_key('country'): - loc.country = attrs['country'] - if self.locations > 0: - self.placeobj.add_alternate_locations(loc) - else: - self.placeobj.set_main_location(loc) - self.locations = self.locations + 1 - - def start_witness(self,attrs): - self.in_witness = 1 - if attrs.has_key('ref'): - self.witness = RelLib.Witness(RelLib.Event.ID,attrs['ref']) - if attrs.has_key('name'): - self.witness = RelLib.Witness(RelLib.Event.NAME,attrs['name']) - - def start_coord(self,attrs): - if attrs.has_key('lat'): - self.placeobj.set_latitude(attrs['lat']) - if attrs.has_key('long'): - self.placeobj.set_longitude(attrs['long']) - - def start_event(self,attrs): - self.event = RelLib.Event() - self.db.add_event(self.event) - self.event_type = const.save_event(attrs["type"]) - if attrs.has_key("conf"): - self.event.conf = int(attrs["conf"]) - else: - self.event.conf = 2 - if attrs.has_key("priv"): - self.event.private = int(attrs["priv"]) - - def start_attribute(self,attrs): - self.attribute = RelLib.Attribute() - if attrs.has_key("conf"): - self.attribute.conf = int(attrs["conf"]) - else: - self.attribute.conf = 2 - if attrs.has_key("priv"): - self.attribute.private = int(attrs["priv"]) - if attrs.has_key('type'): - self.attribute.set_type(const.save_attr(attrs["type"])) - if attrs.has_key('value'): - self.attribute.set_value(attrs["value"]) - if self.photo: - self.photo.add_attribute(self.attribute) - elif self.object: - self.object.add_attribute(self.attribute) - elif self.objref: - self.objref.add_attribute(self.attribute) - elif self.person: - self.person.add_attribute(self.attribute) - elif self.family: - self.family.add_attribute(self.attribute) - - def start_address(self,attrs): - self.address = RelLib.Address() - self.person.add_address(self.address) - if attrs.has_key("conf"): - self.address.conf = int(attrs["conf"]) - else: - self.address.conf = 2 - if attrs.has_key("priv"): - self.address.private = int(attrs["priv"]) - - def start_bmark(self,attrs): - self.db.bookmarks.append(attrs["ref"]) - - def start_person(self,attrs): - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - self.person = self.db.find_person_from_id(attrs["id"]) - if attrs.has_key("complete"): - self.person.set_complete(int(attrs['complete'])) - else: - self.person.set_complete(0) - - def start_people(self,attrs): - if attrs.has_key("default"): - self.tempDefault = attrs["default"] - - def start_father(self,attrs): - self.family.set_father_id(attrs["ref"]) - - def start_mother(self,attrs): - self.family.set_mother_id(attrs["ref"]) - - def start_child(self,attrs): - self.family.add_child_id(attrs["ref"]) - - def start_url(self,attrs): - - if not attrs.has_key("href"): - return - try: - desc = attrs["description"] - except KeyError: - desc = "" - - try: - url = RelLib.Url() - url.set_path(attrs["href"]) - url.set_description(desc) - if attrs.has_key("priv"): - url.set_privacy(int(attrs['priv'])) - if self.person: - self.person.add_url(url) - elif self.placeobj: - self.placeobj.add_url(url) - except KeyError: - return - - def start_family(self,attrs): - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - self.family = self.db.find_family_no_map(attrs["id"]) - if attrs.has_key("type"): - self.family.set_relationship(const.save_frel(attrs["type"])) - else: - self.family.set_relationship("") - if attrs.has_key("complete"): - self.family.set_complete(int(attrs['complete'])) - else: - self.family.set_complete(0) - - def start_childof(self,attrs): - family = self.db.find_family_no_map(attrs["ref"]) - if attrs.has_key("mrel"): - mrel = attrs["mrel"] - else: - mrel = "Birth" - if attrs.has_key("frel"): - frel = attrs["frel"] - else: - frel = "Birth" - self.person.add_parent_family_id(family.get_id(),mrel,frel) - - def start_parentin(self,attrs): - self.person.add_family_id(attrs["ref"]) - - def start_name(self,attrs): - if not self.in_witness: - self.name = RelLib.Name() - if attrs.has_key("type"): - self.name.set_type(attrs["type"]) - if attrs.has_key("conf"): - self.name.set_confidence(int(attrs["conf"])) - else: - self.name.conf = 2 - if attrs.has_key("priv"): - self.name.set_privacy(int(attrs["priv"])) - - def start_last(self,attrs): - if attrs.has_key('prefix'): - self.name.set_surname_prefix(attrs['prefix']) - - def start_note(self,attrs): - self.in_note = 1 - self.note = RelLib.Note() - if attrs.has_key("format"): - self.note.set_format(int(attrs['format'])) - - def start_sourceref(self,attrs): - self.source_ref = RelLib.SourceRef() - source = self.db.find_source_from_id(attrs["ref"]) - if attrs.has_key("conf"): - self.source_ref.confidence = int(attrs["conf"]) - else: - self.source_ref.confidence = self.conf - self.source_ref.set_base_id(source.get_id()) - if self.photo: - self.photo.add_source_reference(self.source_ref) - elif self.ord: - self.ord.add_source_reference(self.source_ref) - elif self.object: - self.object.add_source_reference(self.source_ref) - elif self.event: - self.event.add_source_reference(self.source_ref) - elif self.address: - self.address.add_source_reference(self.source_ref) - elif self.name: - self.name.add_source_reference(self.source_ref) - elif self.attribute: - self.attribute.add_source_reference(self.source_ref) - elif self.placeobj: - self.placeobj.add_source_reference(self.source_ref) - elif self.family: - self.family.add_source_reference(self.source_ref) - elif self.person: - self.person.add_source_reference(self.source_ref) - - def start_source(self,attrs): - if self.num_srcs > 0: - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - self.source = self.db.find_source_from_id(attrs["id"]) - - def start_objref(self,attrs): - self.objref = RelLib.MediaRef() - self.objref.set_reference_id(attrs['ref']) - if attrs.has_key('priv'): - self.objref.set_privacy(int(attrs['priv'])) - if self.family: - self.family.add_media_reference(self.objref) - elif self.source: - self.source.add_media_reference(self.objref) - elif self.person: - self.person.add_media_reference(self.objref) - elif self.placeobj: - self.placeobj.add_media_reference(self.objref) - - def start_object(self,attrs): - self.object = self.db.find_object_from_id(attrs['id']) - self.object.set_mime_type(attrs['mime']) - self.object.set_description(attrs['description']) - src = attrs["src"] - if src: - if src[0] != '/': - self.object.set_path("%s/%s" % (self.base,src)) - else: - self.object.set_path(src) - - def stop_people(self,tag): - pass - - def stop_object(self,tag): - self.db.commit_media_object(self.object) - self.object = None - - def stop_objref(self,tag): - self.objref = None - - def start_photo(self,attrs): - self.photo = RelLib.MediaObject() - self.pref = RelLib.MediaRef() - self.pref.set_reference_id(self.photo.get_id()) - - for key in attrs.keys(): - if key == "descrip" or key == "description": - self.photo.set_description(attrs[key]) - elif key == "priv": - self.pref.set_privacy(int(attrs[key])) - elif key == "src": - src = attrs["src"] - if src[0] != '/': - self.photo.set_path("%s/%s" % (self.base,src)) - else: - self.photo.set_path(src) - else: - a = RelLib.Attribute() - a.set_type(key) - a.set_value(attrs[key]) - self.photo.add_attribute(a) - self.photo.set_mime_type(GrampsMime.get_type(self.photo.get_path())) - self.db.add_object(self.photo) - if self.family: - self.family.add_media_reference(self.pref) - elif self.source: - self.source.add_media_reference(self.pref) - elif self.person: - self.person.add_media_reference(self.pref) - elif self.placeobj: - self.placeobj.add_media_reference(self.pref) - - def start_daterange(self,attrs): - if self.source_ref: - d = self.source_ref.get_date() - elif self.ord: - d = self.ord.get_date_object() - elif self.address: - d = self.address.get_date_object() - else: - d = self.event.get_date_object() - - if attrs.has_key("calendar"): - d.set_calendar_val(int(attrs['calendar'])) - - if attrs.has_key("cformat"): - d.set_calendar(Calendar.find_calendar(attrs['calendar'])) - - d.get_start_date().set_iso_date(attrs['start']) - d.get_stop_date().set_iso_date(attrs['stop']) - d.range = 1 - - def start_dateval(self,attrs): - if self.source_ref: - d = self.source_ref.get_date() - elif self.ord: - d = self.ord.get_date_object() - elif self.address: - d = self.address.get_date_object() - else: - d = self.event.get_date_object() - - if attrs.has_key("calendar"): - d.set_calendar_val(int(attrs['calendar'])) - - if attrs.has_key("cformat"): - d.set_calendar(Calendar.find_calendar(attrs['cformat'])) - - d.get_start_date().set_iso_date(attrs['val']) - - if attrs.has_key("type"): - d.get_start_date().set_mode(attrs['type']) - else: - d.get_start_date().set_mode(None) - - def start_datestr(self,attrs): - if self.source_ref: - d = self.source_ref.get_date() - elif self.ord: - d = self.ord.get_date_object() - elif self.address: - d = self.address.get_date_object() - else: - d = self.event.get_date_object() - - d.set(attrs['val']) - - def start_created(self,attrs): - if attrs.has_key('sources'): - self.num_srcs = int(attrs['sources']) - else: - self.num_srcs = 0 - if attrs.has_key('places'): - self.num_places = int(attrs['places']) - else: - self.num_places = 0 - self.entries = int(attrs["people"]) + int(attrs["families"]) + \ - self.num_places + self.num_srcs - - def start_pos(self,attrs): - self.person.position = (int(attrs["x"]), int(attrs["y"])) - - def stop_attribute(self,tag): - self.attribute = None - - def stop_comment(self,tag): - if tag.strip(): - self.witness_comment = tag - else: - self.witness_comment = "" - - def stop_witness(self,tag): - if self.witness_comment: - self.witness.set_comment(self.witness_comment) - elif tag.strip(): - self.witness.set_comment(tag) - else: - self.witness.set_comment("") - self.event.add_witness(self.witness) - self.in_witness = 0 - - def stop_attr_type(self,tag): - self.attribute.set_type(tag) - - def stop_attr_value(self,tag): - self.attribute.set_value(tag) - - def stop_address(self,tag): - self.address = None - - def stop_places(self,tag): - self.placeobj = None - - def stop_photo(self,tag): - self.photo = None - - def stop_placeobj(self,tag): - if self.placeobj.get_title() == "": - loc = self.placeobj.get_main_location() - self.placeobj.set_title(build_place_title(loc)) - self.db.commit_place(self.placeobj) - self.placeobj = None - - def stop_family(self,tag): - self.db.commit_family(self.family) - self.family = None - - def stop_event(self,tag): - self.event.name = self.event_type - - if self.family: - self.family.add_event_id(self.event.get_id()) - else: - if self.event_type == "Birth": - self.person.set_birth_id(self.event.get_id()) - elif self.event_type == "Death": - self.person.set_death_id(self.event.get_id()) - else: - self.person.add_event_id(self.event.get_id()) - self.db.commit_event(self.event) - self.event = None - - def stop_name(self,tag): - if self.in_witness: - self.witness = RelLib.Witness(RelLib.Event.NAME,tag) - else: - if self.name.get_type() == "": - self.name.set_type("Birth Name") - self.person.set_primary_name (self.name) - self.person.get_primary_name().build_sort_name() - self.name = None - - def stop_ref(self,tag): - self.witness = RelLib.Witness(RelLib.Event.ID,tag) - - def stop_place(self,tag): - if self.placeobj == None: - if self.place_map.has_key(tag): - self.placeobj = self.place_map[tag] - else: - self.placeobj = RelLib.Place() - self.placeobj.set_title(tag) - if self.ord: - self.ord.set_place_id(self.placeobj.get_id()) - else: - self.event.set_place_id(self.placeobj.get_id()) - self.db.commit_place(self.placeobj) - self.placeobj = None - - def stop_date(self,tag): - if tag: - if self.address: - self.address.set_date(tag) - else: - self.event.set_date(tag) - - def stop_first(self,tag): - self.name.set_first_name(tag) - - def stop_families(self,tag): - self.family = None - - def stop_person(self,tag): - self.db.commit_person(self.person) - self.person = None - - def stop_description(self,tag): - self.event.set_description(tag) - - def stop_cause(self,tag): - self.event.set_cause(tag) - - def stop_gender(self,tag): - t = tag - if t == "M": - self.person.set_gender (RelLib.Person.male) - elif t == "F": - self.person.set_gender (RelLib.Person.female) - else: - self.person.set_gender (RelLib.Person.unknown) - - def stop_stitle(self,tag): - self.source.set_title(tag) - - def stop_sourceref(self,tag): - self.source_ref = None - - def stop_source(self,tag): - self.db.commit_source(self.source) - self.source = None - - def stop_sauthor(self,tag): - self.source.set_author(tag) - - def stop_sdate(self,tag): - date = Date.Date() - date.set(tag) - self.source_ref.set_date(date) - - def stop_phone(self,tag): - self.address.set_phone(tag) - - def stop_street(self,tag): - self.address.set_street(tag) - - def stop_city(self,tag): - self.address.set_city(tag) - - def stop_state(self,tag): - self.address.set_state(tag) - - def stop_country(self,tag): - self.address.setCountry(tag) - - def stop_postal(self,tag): - self.address.set_postal_code(tag) - - def stop_spage(self,tag): - self.source_ref.set_page(tag) - - def stop_lds_ord(self,tag): - self.ord = None - - def stop_spubinfo(self,tag): - self.source.set_publication_info(tag) - - def stop_sabbrev(self,tag): - self.source.set_abbreviation(tag) - - def stop_stext(self,tag): - if self.use_p: - self.use_p = 0 - note = fix_spaces(self.stext_list) - else: - note = tag - self.source_ref.set_text(note) - - def stop_scomments(self,tag): - if self.use_p: - self.use_p = 0 - note = fix_spaces(self.scomments_list) - else: - note = tag - self.source_ref.set_comments(note) - - def stop_last(self,tag): - if self.name: - self.name.set_surname(tag) - - def stop_suffix(self,tag): - if self.name: - self.name.set_suffix(tag) - - def stop_title(self,tag): - if self.name: - self.name.set_title(tag) - - def stop_nick(self,tag): - if self.person: - self.person.set_nick_name(tag) - - def stop_note(self,tag): - self.in_note = 0 - if self.use_p: - self.use_p = 0 - text = fix_spaces(self.note_list) - else: - text = tag - self.note.set(text) - - if self.address: - self.address.set_note_object(self.note) - elif self.ord: - self.ord.set_note_object(self.note) - elif self.attribute: - self.attribute.set_note_object(self.note) - elif self.object: - self.object.set_note_object(self.note) - elif self.objref: - self.objref.set_note_object(self.note) - elif self.photo: - self.photo.set_note_object(self.note) - elif self.name: - self.name.set_note_object(self.note) - elif self.source: - self.source.set_note_object(self.note) - elif self.event: - self.event.set_note_object(self.note) - elif self.person: - self.person.set_note_object(self.note) - elif self.family: - self.family.set_note_object(self.note) - elif self.placeobj: - self.placeobj.set_note_object(self.note) - - def stop_research(self,tag): - self.owner.set(self.resname, self.resaddr, self.rescity, self.resstate, - self.rescon, self.respos, self.resphone, self.resemail) - - def stop_resname(self,tag): - self.resname = tag - - def stop_resaddr(self,tag): - self.resaddr = tag - - def stop_rescity(self,tag): - self.rescity = tag - - def stop_resstate(self,tag): - self.resstate = tag - - def stop_rescountry(self,tag): - self.rescon = tag - - def stop_respostal(self,tag): - self.respos = tag - - def stop_resphone(self,tag): - self.resphone = tag - - def stop_resemail(self,tag): - self.resemail = tag - - def stop_ptag(self,tag): - self.use_p = 1 - if self.in_note: - self.note_list.append(tag) - elif self.in_stext: - self.stext_list.append(tag) - elif self.in_scomments: - self.scomments_list.append(tag) - - def stop_aka(self,tag): - self.person.add_alternate_name(self.name) - if self.name.get_type() == "": - self.name.set_type("Also Known As") - self.name = None - - def startElement(self,tag,attrs): - - self.func_list[self.func_index] = (self.func,self.tlist) - self.func_index = self.func_index + 1 - self.tlist = [] - - try: - f,self.func = self.func_map[tag] - if f: - f(attrs) - except KeyError: - self.func_map[tag] = (None,None) - self.func = None - - def endElement(self,tag): - - if self.func: - self.func(string.join(self.tlist,'')) - self.func_index = self.func_index - 1 - self.func,self.tlist = self.func_list[self.func_index] - - def characters(self, data): - if self.func: - self.tlist.append(data) - -#------------------------------------------------------------------------- -# -# Gramps database parsing class. Derived from SAX XML parser -# -#------------------------------------------------------------------------- -class GrampsImportParser(GrampsParser): - - def __init__(self,database,callback,base): - GrampsParser.__init__(self,database,callback,base) - - def start_childof(self,attrs): - family = self.db.find_family_no_conflicts(attrs["ref"],self.fmap) - if attrs.has_key("mrel"): - mrel = attrs["mrel"] - else: - mrel = "Birth" - if attrs.has_key("frel"): - frel = attrs["frel"] - else: - frel = "Birth" - self.person.add_parent_family_id(family.get_id(),mrel,frel) - - def start_parentin(self,attrs): - self.person.add_family_id(attrs["ref"]) - - def start_bmark(self,attrs): - person = self.db.find_person_no_conflicts(attrs["ref"],self.pmap) - self.db.bookmarks.append(person) - - def start_person(self,attrs): - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - self.person = self.db.find_person_no_conflicts(attrs["id"],self.pmap) - if attrs.has_key("complete"): - self.person.set_complete(int(attrs['complete'])) - else: - self.person.set_complete(0) - - def start_father(self,attrs): - self.family.set_father_id(attrs["ref"]) - - def start_mother(self,attrs): - self.family.set_mother_id(attrs["ref"]) - - def start_child(self,attrs): - self.family.add_child_id(attrs["ref"]) - - def start_family(self,attrs): - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - self.family = self.db.find_family_no_conflicts(attrs["id"],self.fmap) - if attrs.has_key("type"): - self.family.set_relationship(const.save_frel(attrs["type"])) - if attrs.has_key("complete"): - self.family.set_complete(int(attrs['complete'])) - else: - self.family.set_complete(0) - - def start_source(self,attrs): - self.source = self.db.find_source_no_conflicts(attrs["id"],self.smap) - - def start_sourceref(self,attrs): - self.source_ref = RelLib.SourceRef() - source = self.db.find_source_no_conflicts(attrs["ref"],self.smap) - if attrs.has_key("conf"): - self.source_ref.confidence = int(attrs["conf"]) - else: - self.source_ref.confidence = self.conf - self.source_ref.set_base_id(source.get_id()) - if self.photo: - self.photo.add_source_reference(self.source_ref) - elif self.ord: - self.ord.add_source_reference(self.source_ref) - elif self.object: - self.object.add_source_reference(self.source_ref) - elif self.event: - self.event.add_source_reference(self.source_ref) - elif self.address: - self.address.add_source_reference(self.source_ref) - elif self.name: - self.name.add_source_reference(self.source_ref) - elif self.attribute: - self.attribute.add_source_reference(self.source_ref) - elif self.placeobj: - self.placeobj.add_source_reference(self.source_ref) - elif self.family: - self.family.add_source_reference(self.source_ref) - - def start_place(self,attrs): - self.placeobj = self.db.find_place_no_conflicts(attrs['ref'],self.lmap) - - def start_placeobj(self,attrs): - self.placeobj = self.db.find_place_no_conflicts(attrs['id'],self.lmap) - title = attrs['title'] - if title == "": - title = attrs['id'] - self.placeobj.set_title(title) - self.locations = 0 - if self.num_places > 0: - if self.callback != None and self.count % self.increment == 0: - self.callback(float(self.count)/float(self.entries)) - self.count = self.count + 1 - - def start_objref(self,attrs): - self.objref = RelLib.MediaRef() - id = self.db.find_object_no_conflicts(attrs['ref'],self.media_file_map).get_id() - self.objref.set_reference_id(id) - if attrs.has_key('priv'): - self.objref.set_privacy(int(attrs['priv'])) - if self.family: - self.family.add_media_reference(self.objref) - elif self.source: - self.source.add_media_reference(self.objref) - elif self.person: - self.person.add_media_reference(self.objref) - elif self.placeobj: - self.placeobj.add_media_reference(self.objref) - - def start_object(self,attrs): - self.object = self.db.find_object_no_conflicts(attrs['id'],self.media_file_map) - self.object.set_mime_type(attrs['mime']) - self.object.set_description(attrs['description']) - src = attrs["src"] - if src: - if src[0] != '/': - self.object.set_path("%s/%s" % (self.db.get_save_path(),src)) - else: - self.object.set_path(src) - -def append_value(orig,val): - if orig: - return "%s, %s" % (orig,val) - else: - return val - -def build_place_title(loc): - "Builds a title from a location" - city = loc.get_city() - state = loc.get_state() - country = loc.get_country() - county = loc.get_county() - parish = loc.get_parish() - - value = "" - - if parish: - value = parish - if city: - value = append_value(value,city) - if county: - value = append_value(value,county) - if state: - value = append_value(value,state) - if country: - value = append_value(value,country) - return value diff --git a/gramps2/src/GrampsXML.py b/gramps2/src/GrampsXML.py deleted file mode 100644 index 4bec79000..000000000 --- a/gramps2/src/GrampsXML.py +++ /dev/null @@ -1,42 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000 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 -# - -import RelLib -import WriteXML -import ReadXML -import const - -class GrampsXML(RelLib.GrampsDB): - - def get_base(self): - return const.xmlFile - - def get_type(self): - return 'GrampsXML' - - def new(self): - RelLib.GrampsDB.new(self) - - def save(self,name,callback): - WriteXML.exportData(self,name,callback) - - def load(self,name,callback): - ReadXML.loadData(self,name,callback) - return 1 diff --git a/gramps2/src/Makefile.am b/gramps2/src/Makefile.am index bec5d403c..2e9c047fd 100644 --- a/gramps2/src/Makefile.am +++ b/gramps2/src/Makefile.am @@ -2,8 +2,6 @@ SUBDIRS = docgen filters plugins data po calendars # For intl. support, how do we compile? -CFLAGS = -fPIC -shared -O @GNOMEINC@ @CFLAGS@ @CPPFLAGS@ -I@includedir@ -LDFLAGS = @GNOMELIB@ @LDFLAGS@ -L@libdir@ @LIBS@ MOSTLYCLEANFILES = # What are the PYTHON scripts for this package that need to be handled? @@ -42,9 +40,7 @@ pkgpython_PYTHON = \ GenericFilter.py\ GrampsCfg.py\ gramps_main.py\ - GrampsParser.py\ gramps.py\ - GrampsXML.py\ GraphLayout.py\ Gregorian.py\ Hebrew.py\ @@ -117,7 +113,7 @@ GRAPHICS = \ tools.png # Other stuff that we need to install -dist_pkgdata_DATA = $(GLADEFILES) $(GRAPHICS) gramps.desktop papersize.xml +dist_pkgdata_DATA = $(GLADEFILES) $(GRAPHICS) gramps.desktop # In principle the following rule slightly violates the automake/autoconf # spirit of keeping each subdirectory as a separate entity unto itself. diff --git a/gramps2/src/Makefile.in b/gramps2/src/Makefile.in index b24776d84..d3dab7d72 100644 --- a/gramps2/src/Makefile.in +++ b/gramps2/src/Makefile.in @@ -113,8 +113,6 @@ target_alias = @target_alias@ SUBDIRS = docgen filters plugins data po calendars # For intl. support, how do we compile? -CFLAGS = -fPIC -shared -O @GNOMEINC@ @CFLAGS@ @CPPFLAGS@ -I@includedir@ -LDFLAGS = @GNOMELIB@ @LDFLAGS@ -L@libdir@ @LIBS@ MOSTLYCLEANFILES = @@ -153,9 +151,7 @@ pkgpython_PYTHON = \ GenericFilter.py\ GrampsCfg.py\ gramps_main.py\ - GrampsParser.py\ gramps.py\ - GrampsXML.py\ GraphLayout.py\ Gregorian.py\ Hebrew.py\ diff --git a/gramps2/src/MediaView.py b/gramps2/src/MediaView.py index 50a061430..48d28ad40 100644 --- a/gramps2/src/MediaView.py +++ b/gramps2/src/MediaView.py @@ -86,7 +86,11 @@ class MediaView: self.preview = glade.get_widget("preview") self.renderer = gtk.CellRendererText() - self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.db)) + if const.nosort_tree: + self.model = DisplayModels.MediaModel(self.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.db)) + self.selection = self.list.get_selection() self.list.set_model(self.model) @@ -125,10 +129,12 @@ class MediaView: self.list.remove_column(column) column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0) - column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + column.set_resizable(gtk.TRUE) + + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(0) column.set_min_width(225) - column.set_sort_column_id(0) self.list.append_column(column) self.columns = [column] @@ -139,9 +145,10 @@ class MediaView: name = column_names[pair[1]] column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(index) column.set_min_width(75) - column.set_sort_column_id(index) self.columns.append(column) self.list.append_column(column) index += 1 @@ -153,7 +160,11 @@ class MediaView: def build_tree(self): self.list.set_model(None) - self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.parent.db)) + if const.nosort_tree: + self.model = DisplayModels.MediaModel(self.parent.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.parent.db)) + self.list.set_model(self.model) self.selection = self.list.get_selection() diff --git a/gramps2/src/PedView.py b/gramps2/src/PedView.py index a0542c4ee..168070150 100644 --- a/gramps2/src/PedView.py +++ b/gramps2/src/PedView.py @@ -46,11 +46,12 @@ _DIED = _('d.') class DispBox: - def __init__(self,root,style,x,y,w,h,person,db,change): + def __init__(self,root,style,x,y,w,h,person,db,change,edit): shadow = _PAD xpad = _PAD self.change = change + self.edit = edit self.x = x self.y = y self.w = w @@ -121,9 +122,9 @@ class DispBox: shift doubleclick would change the active person, entering the box expands it to display more information, leaving a box returns it to the original size and information""" - if event.type == gtk.gdk._2BUTTON_PRESS: - return 1 + self.edit(self.person) + return 0 elif event.type == gtk.gdk.ENTER_NOTIFY: self.expand() return 0 @@ -305,11 +306,10 @@ class PedigreeView: ypts[mindex], h, w, p[0], style, p[1]) p = list[i] box = DispBox(self.root,style,xpts[i],ypts[i],w,h,p[0],self.parent.db, - self.change_active_person) + self.change_active_person, self.load_person) self.boxes.append(box) self.change_active_person(person) - def make_arrow_button(self,direction,function): """Make a button containing an arrow with the attached callback""" diff --git a/gramps2/src/PeopleView.py b/gramps2/src/PeopleView.py index a7313a785..a2f24a4c8 100644 --- a/gramps2/src/PeopleView.py +++ b/gramps2/src/PeopleView.py @@ -48,6 +48,7 @@ _sel_mode = gtk.SELECTION_SINGLE #------------------------------------------------------------------------- import PeopleModel import Filter +import const column_names = [ _('Name'), @@ -69,8 +70,6 @@ class PeopleView: def __init__(self,parent): self.parent = parent - self.nosort = os.environ.has_key('NOSORT') - self.DataFilter = Filter.Filter("") self.pscroll = self.parent.gtop.get_widget("pscroll") self.person_tree = self.parent.gtop.get_widget("person_tree") @@ -88,7 +87,7 @@ class PeopleView: column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0) column.set_resizable(gtk.TRUE) column.set_min_width(225) - if not self.nosort: + if not const.nosort_tree: column.set_clickable(gtk.TRUE) column.set_sort_column_id(PeopleModel.COLUMN_NAME_SORT) self.person_tree.append_column(column) @@ -112,7 +111,7 @@ class PeopleView: self.person_tree.set_model(None) self.person_model = PeopleModel.PeopleModel(self.parent.db) - if self.nosort: + if const.nosort_tree: self.sort_model = self.person_model else: self.sort_model = gtk.TreeModelSort(self.person_model) @@ -254,7 +253,7 @@ class PeopleView: def redisplay_person_list(self,person): self.person_model = PeopleModel.PeopleModel(self.parent.db) - if self.nosort: + if const.nosort_tree: self.sort_model = self.person_model else: self.sort_model = gtk.TreeModelSort(self.person_model) diff --git a/gramps2/src/PlaceView.py b/gramps2/src/PlaceView.py index f452ff5d1..29fcaad23 100644 --- a/gramps2/src/PlaceView.py +++ b/gramps2/src/PlaceView.py @@ -43,6 +43,7 @@ import EditPlace import Utils import DisplayModels import ColumnOrder +import const from QuestionDialog import QuestionDialog, ErrorDialog from gettext import gettext as _ @@ -78,7 +79,11 @@ class PlaceView: self.renderer = gtk.CellRendererText() - self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.db)) + if const.nosort_tree: + self.model = DisplayModels.PlaceModel(self.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.db)) + self.list.set_model(self.model) self.topWindow = self.glade.get_widget("gramps") @@ -90,10 +95,12 @@ class PlaceView: self.list.remove_column(column) column = gtk.TreeViewColumn(_('Place Name'), self.renderer,text=0) - column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + column.set_resizable(gtk.TRUE) + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(0) + column.set_min_width(225) - column.set_sort_column_id(0) self.list.append_column(column) self.columns = [column] @@ -104,9 +111,10 @@ class PlaceView: name = column_names[pair[1]] column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(index) column.set_min_width(75) - column.set_sort_column_id(index) self.columns.append(column) self.list.append_column(column) index += 1 @@ -120,7 +128,10 @@ class PlaceView: def build_tree(self): self.list.set_model(None) - self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.parent.db)) + if const.nosort_tree: + self.model = DisplayModels.PlaceModel(self.parent.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.parent.db)) self.list.set_model(self.model) self.selection = self.list.get_selection() diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index e8bc31977..55c25413c 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -29,18 +29,21 @@ import string import os import gtk import shutil -from xml.parsers.expat import ExpatError +import xml.parsers.expat #------------------------------------------------------------------------- # # Gramps Modules # #------------------------------------------------------------------------- -import RelLib -from GrampsParser import GrampsParser, GrampsImportParser from QuestionDialog import ErrorDialog, WarningDialog, MissingMediaDialog from gettext import gettext as _ +import Calendar +import Date +import GrampsMime +import RelLib import Utils +import const #------------------------------------------------------------------------- # @@ -68,7 +71,7 @@ def importData(database, filename, callback,cl=0): database.fmap = {} missmedia_action = 0 - parser = GrampsImportParser(database,callback,basefile) + parser = GrampsParser(database,callback,basefile) if gzip_ok: use_gzip = 1 @@ -180,7 +183,6 @@ def importData(database, filename, callback,cl=0): # File is lost => do nothing, leave as is pass - def select_clicked(): # File is lost => select a file to replace the lost one def fs_close_window(obj): @@ -202,135 +204,901 @@ def importData(database, filename, callback,cl=0): fs_top.run() fs_top.destroy() -# # Rename media files if they were conflicting with existing ones -# newpath = database.get_save_path() -# for old_media_id in parser.media_file_map.keys(): -# new_media_id = parser.MediaFileMap[old_media_id] -# new_media = database.find_object_from_id(new_media_id) -# oldfile = new_media.get_path() -# (junk,oldext) = os.path.splitext(os.path.basename(oldfile)) -# oldfile = os.path.join(basefile,OldMediaID+oldext) -# newfile = os.path.join(newpath,NewMediaID+oldext) -# ObjectMap[NewMediaID].set_path(newfile) -# ObjectMap[NewMediaID].setLocal(1) -# try: -# shutil.copyfile(oldfile,newfile) -# try: -# shutil.copystat(oldfile,newfile) -# except: -# pass -# except: -# if cl: -# print "Warning: media file %s was not found," \ -# % os.path.basename(oldfile), "so it was ignored." -# else: -# # File is lost => ask what to do (if we were not told yet) -# if missmedia_action == 0: -# mmd = MissingMediaDialog(_("Media object could not be found"), -# _("%(file_name)s is referenced in the database, but no longer exists. " -# "The file may have been deleted or moved to a different location. " -# "You may choose to either remove the reference from the database, " -# "keep the reference to the missing file, or select a new file." -# ) % { 'file_name' : oldfile }, -# remove_clicked, leave_clicked, select_clicked) -# missmedia_action = mmd.default_action -# elif missmedia_action == 1: -# remove_clicked() -# elif missmedia_action == 2: -# leave_clicked() -# elif missmedia_action == 3: -# select_clicked() - del parser return 1 - #------------------------------------------------------------------------- # -# Initialization function for the module. Called to start the reading -# of data. +# Remove extraneous spaces # #------------------------------------------------------------------------- -def loadData(database, filename, callback=None): - basefile = os.path.dirname(filename) - database.smap = {} - database.pmap = {} - database.fmap = {} +def rs(text): + return string.join(string.split(text)) - filename = os.path.normpath(filename) +def fix_spaces(text_list): + return string.join(map(rs,text_list),'\n') - parser = GrampsParser(database,callback,basefile) +#------------------------------------------------------------------------- +# +# Gramps database parsing class. Derived from SAX XML parser +# +#------------------------------------------------------------------------- +class GrampsParser: - if gzip_ok: - use_gzip = 1 - try: - f = gzip.open(filename,"r") - f.read(1) - f.close() - except IOError,msg: - use_gzip = 0 - else: - use_gzip = 0 + def __init__(self,database,callback,base): + self.stext_list = [] + self.scomments_list = [] + self.note_list = [] + self.tlist = [] + self.conf = 2 + + self.ord = None + self.objref = None + self.object = None + self.pref = None + self.use_p = 0 + self.in_note = 0 + self.in_stext = 0 + self.in_scomments = 0 + self.in_witness = 0 + self.db = database + self.base = base + self.photo = None + self.person = None + self.family = None + self.address = None + self.source = None + self.source_ref = None + self.attribute = None + self.placeobj = None + self.locations = 0 + self.place_map = {} - try: - if use_gzip: - xml_file = gzip.open(filename,"rb") + self.resname = "" + self.resaddr = "" + self.rescity = "" + self.resstate = "" + self.rescon = "" + self.respos = "" + self.resphone = "" + self.resemail = "" + + self.pmap = {} + self.fmap = {} + self.smap = {} + self.lmap = {} + self.media_file_map = {} + + self.callback = callback + self.entries = 0 + self.count = 0 + self.increment = 100 + self.event = None + self.name = None + self.tempDefault = None + self.owner = RelLib.Researcher() + self.func_list = [None]*50 + self.func_index = 0 + self.func = None + self.witness_comment = "" + + self.func_map = { + "address" : (self.start_address, self.stop_address), + "addresses" : (None,None), + "childlist" : (None,None), + "aka" : (self.start_name, self.stop_aka), + "attribute" : (self.start_attribute, self.stop_attribute), + "attr_type" : (None,self.stop_attr_type), + "attr_value" : (None,self.stop_attr_value), + "bookmark" : (self.start_bmark, None), + "witness" : (self.start_witness,self.stop_witness), + "bookmarks" : (None, None), + "child" : (self.start_child,None), + "childof" : (self.start_childof,None), + "city" : (None, self.stop_city), + "country" : (None, self.stop_country), + "comment" : (None, self.stop_comment), + "created" : (self.start_created, None), + "ref" : (None, self.stop_ref), + "database" : (None, None), + "phone" : (None, self.stop_phone), + "date" : (None, self.stop_date), + "cause" : (None, self.stop_cause), + "description": (None, self.stop_description), + "event" : (self.start_event, self.stop_event), + "families" : (None, self.stop_families), + "family" : (self.start_family, self.stop_family), + "father" : (self.start_father, None), + "first" : (None, self.stop_first), + "gender" : (None, self.stop_gender), + "header" : (None, None), + "last" : (self.start_last, self.stop_last), + "mother" : (self.start_mother,None), + "name" : (self.start_name, self.stop_name), + "nick" : (None, self.stop_nick), + "note" : (self.start_note, self.stop_note), + "p" : (None, self.stop_ptag), + "parentin" : (self.start_parentin,None), + "people" : (self.start_people, self.stop_people), + "person" : (self.start_person, self.stop_person), + "img" : (self.start_photo, self.stop_photo), + "objref" : (self.start_objref, self.stop_objref), + "object" : (self.start_object, self.stop_object), + "place" : (self.start_place, self.stop_place), + "dateval" : (self.start_dateval, None), + "daterange" : (self.start_daterange, None), + "datestr" : (self.start_datestr, None), + "places" : (None, self.stop_places), + "placeobj" : (self.start_placeobj,self.stop_placeobj), + "location" : (self.start_location,None), + "lds_ord" : (self.start_lds_ord, self.stop_lds_ord), + "temple" : (self.start_temple, None), + "status" : (self.start_status, None), + "sealed_to" : (self.start_sealed_to, None), + "coord" : (self.start_coord,None), + "pos" : (self.start_pos, None), + "postal" : (None, self.stop_postal), + "researcher" : (None, self.stop_research), + "resname" : (None, self.stop_resname ), + "resaddr" : (None, self.stop_resaddr ), + "rescity" : (None, self.stop_rescity ), + "resstate" : (None, self.stop_resstate ), + "rescountry" : (None, self.stop_rescountry), + "respostal" : (None, self.stop_respostal), + "resphone" : (None, self.stop_resphone), + "resemail" : (None, self.stop_resemail), + "sauthor" : (None, self.stop_sauthor), + "sabbrev" : (None, self.stop_sabbrev), + "scomments" : (None, self.stop_scomments), + "sdate" : (None,self.stop_sdate), + "source" : (self.start_source, self.stop_source), + "sourceref" : (self.start_sourceref, self.stop_sourceref), + "sources" : (None, None), + "spage" : (None, self.stop_spage), + "spubinfo" : (None, self.stop_spubinfo), + "state" : (None, self.stop_state), + "stext" : (None, self.stop_stext), + "stitle" : (None, self.stop_stitle), + "street" : (None, self.stop_street), + "suffix" : (None, self.stop_suffix), + "title" : (None, self.stop_title), + "url" : (self.start_url, None) + } + + + def parse(self,file): + p = xml.parsers.expat.ParserCreate() + p.StartElementHandler = self.startElement + p.EndElementHandler = self.endElement + p.CharacterDataHandler = self.characters + p.ParseFile(file) + + self.db.set_researcher(self.owner) + if self.tempDefault != None: + id = self.tempDefault + if self.db.has_person_id(id) and self.db.get_default_person() == None: + self.db.set_default_person_id(id) + + for key in self.func_map.keys(): + del self.func_map[key] + del self.func_map + del self.func_list + del p + + def start_lds_ord(self,attrs): + type = attrs['type'] + self.ord = RelLib.LdsOrd() + if self.person: + if type == "baptism": + self.person.set_lds_baptism(self.ord) + elif type == "endowment": + self.person.set_lds_endowment(self.ord) + elif type == "sealed_to_parents": + self.person.set_lds_sealing(self.ord) + elif self.family: + if type == "sealed_to_spouse": + self.family.set_lds_sealing(self.ord) + + def start_temple(self,attrs): + self.ord.set_temple(attrs['val']) + + def start_status(self,attrs): + self.ord.set_status(int(attrs['val'])) + + def start_sealed_to(self,attrs): + id = attrs['ref'] + self.ord.set_family_id(self.db.find_family_no_map(id)) + + def start_place(self,attrs): + self.placeobj = self.db.find_place_no_conflicts(attrs['ref'],self.lmap) + + def start_placeobj(self,attrs): + self.placeobj = self.db.find_place_no_conflicts(attrs['id'],self.lmap) + title = attrs['title'] + if title == "": + title = attrs['id'] + self.placeobj.set_title(title) + self.locations = 0 + if self.num_places > 0: + if self.callback != None and self.count % self.increment == 0: + self.callback(float(self.count)/float(self.entries)) + self.count = self.count + 1 + + def start_location(self,attrs): + """Bypass the function calls for this one, since it appears to + take up quite a bit of time""" + + loc = RelLib.Location() + if attrs.has_key('phone'): + loc.phone = attrs['phone'] + if attrs.has_key('postal'): + loc.postal = attrs['postal'] + if attrs.has_key('city'): + loc.city = attrs['city'] + if attrs.has_key('parish'): + loc.parish = attrs['parish'] + if attrs.has_key('state'): + loc.state = attrs['state'] + if attrs.has_key('county'): + loc.county =attrs['county'] + if attrs.has_key('country'): + loc.country = attrs['country'] + if self.locations > 0: + self.placeobj.add_alternate_locations(loc) else: - xml_file = open(filename,"r") - except IOError,msg: - filemsg = _("%s could not be opened.") % filename - ErrorDialog(filemsg,str(msg)) - return 0 - except: - ErrorDialog(_("%s could not be opened.") % filename) - return 0 + self.placeobj.set_main_location(loc) + self.locations = self.locations + 1 - try: - parser.parse(xml_file) - except IOError,msg: - ErrorDialog(_("Error reading %s") % filename, str(msg)) - import traceback - traceback.print_exc() - return 0 -# except: -# ErrorDialog(_("Error reading %s") % filename) -# import traceback -# traceback.print_exc() -# return 0 + def start_witness(self,attrs): + self.in_witness = 1 + if attrs.has_key('ref'): + self.witness = RelLib.Witness(RelLib.Event.ID,attrs['ref']) + if attrs.has_key('name'): + self.witness = RelLib.Witness(RelLib.Event.NAME,attrs['name']) + + def start_coord(self,attrs): + if attrs.has_key('lat'): + self.placeobj.set_latitude(attrs['lat']) + if attrs.has_key('long'): + self.placeobj.set_longitude(attrs['long']) - xml_file.close() - del parser - return 1 + def start_event(self,attrs): + self.event = RelLib.Event() + self.db.add_event(self.event) + self.event_type = const.save_event(attrs["type"]) + if attrs.has_key("conf"): + self.event.conf = int(attrs["conf"]) + else: + self.event.conf = 2 + if attrs.has_key("priv"): + self.event.private = int(attrs["priv"]) + + def start_attribute(self,attrs): + self.attribute = RelLib.Attribute() + if attrs.has_key("conf"): + self.attribute.conf = int(attrs["conf"]) + else: + self.attribute.conf = 2 + if attrs.has_key("priv"): + self.attribute.private = int(attrs["priv"]) + if attrs.has_key('type'): + self.attribute.set_type(const.save_attr(attrs["type"])) + if attrs.has_key('value'): + self.attribute.set_value(attrs["value"]) + if self.photo: + self.photo.add_attribute(self.attribute) + elif self.object: + self.object.add_attribute(self.attribute) + elif self.objref: + self.objref.add_attribute(self.attribute) + elif self.person: + self.person.add_attribute(self.attribute) + elif self.family: + self.family.add_attribute(self.attribute) -#------------------------------------------------------------------------- -# -# Initialization function for the module. Called to start the reading -# of data. -# -#------------------------------------------------------------------------- -def loadRevision(database, file, filename, revision, callback=None): + def start_address(self,attrs): + self.address = RelLib.Address() + self.person.add_address(self.address) + if attrs.has_key("conf"): + self.address.conf = int(attrs["conf"]) + else: + self.address.conf = 2 + if attrs.has_key("priv"): + self.address.private = int(attrs["priv"]) - basefile = os.path.dirname(filename) - database.smap = {} - database.pmap = {} - database.fmap = {} + def start_bmark(self,attrs): + person = self.db.find_person_no_conflicts(attrs["ref"],self.pmap) + self.db.bookmarks.append(person.get_id()) - parser = GrampsParser(database,callback,basefile) + def start_person(self,attrs): + if self.callback != None and self.count % self.increment == 0: + self.callback(float(self.count)/float(self.entries)) + self.count = self.count + 1 + self.person = self.db.find_person_no_conflicts(attrs["id"],self.pmap) + if attrs.has_key("complete"): + self.person.set_complete(int(attrs['complete'])) + else: + self.person.set_complete(0) - filename = _("%s (revision %s)") % (filename,revision) + def start_people(self,attrs): + if attrs.has_key("default"): + self.tempDefault = attrs["default"] + + def start_father(self,attrs): + self.family.set_father_id(attrs["ref"]) + + def start_mother(self,attrs): + self.family.set_mother_id(attrs["ref"]) - try: - parser.parse(file) - except IOError,msg: - ErrorDialog(_("Error reading %s") % filename,str(msg)) - import traceback - traceback.print_exc() - return 0 - except: - import DisplayTrace - DisplayTrace.DisplayTrace() - return 0 + def start_child(self,attrs): + self.family.add_child_id(attrs["ref"]) - file.close() - return 1 + def start_url(self,attrs): + + if not attrs.has_key("href"): + return + try: + desc = attrs["description"] + except KeyError: + desc = "" + + try: + url = RelLib.Url() + url.set_path(attrs["href"]) + url.set_description(desc) + if attrs.has_key("priv"): + url.set_privacy(int(attrs['priv'])) + if self.person: + self.person.add_url(url) + elif self.placeobj: + self.placeobj.add_url(url) + except KeyError: + return + + def start_family(self,attrs): + if self.callback != None and self.count % self.increment == 0: + self.callback(float(self.count)/float(self.entries)) + self.count = self.count + 1 + self.family = self.db.find_family_no_conflicts(attrs["id"],self.fmap) + if attrs.has_key("type"): + self.family.set_relationship(const.save_frel(attrs["type"])) + if attrs.has_key("complete"): + self.family.set_complete(int(attrs['complete'])) + else: + self.family.set_complete(0) + + def start_childof(self,attrs): + family = self.db.find_family_no_conflicts(attrs["ref"],self.fmap) + if attrs.has_key("mrel"): + mrel = attrs["mrel"] + else: + mrel = "Birth" + if attrs.has_key("frel"): + frel = attrs["frel"] + else: + frel = "Birth" + self.person.add_parent_family_id(family.get_id(),mrel,frel) + + def start_parentin(self,attrs): + self.person.add_family_id(attrs["ref"]) + + def start_name(self,attrs): + if not self.in_witness: + self.name = RelLib.Name() + if attrs.has_key("type"): + self.name.set_type(attrs["type"]) + if attrs.has_key("conf"): + self.name.set_confidence(int(attrs["conf"])) + else: + self.name.conf = 2 + if attrs.has_key("priv"): + self.name.set_privacy(int(attrs["priv"])) + + def start_last(self,attrs): + if attrs.has_key('prefix'): + self.name.set_surname_prefix(attrs['prefix']) + + def start_note(self,attrs): + self.in_note = 1 + self.note = RelLib.Note() + if attrs.has_key("format"): + self.note.set_format(int(attrs['format'])) + + def start_sourceref(self,attrs): + self.source_ref = RelLib.SourceRef() + source = self.db.find_source_no_conflicts(attrs["ref"],self.smap) + if attrs.has_key("conf"): + self.source_ref.confidence = int(attrs["conf"]) + else: + self.source_ref.confidence = self.conf + self.source_ref.set_base_id(source.get_id()) + if self.photo: + self.photo.add_source_reference(self.source_ref) + elif self.ord: + self.ord.add_source_reference(self.source_ref) + elif self.object: + self.object.add_source_reference(self.source_ref) + elif self.event: + self.event.add_source_reference(self.source_ref) + elif self.address: + self.address.add_source_reference(self.source_ref) + elif self.name: + self.name.add_source_reference(self.source_ref) + elif self.attribute: + self.attribute.add_source_reference(self.source_ref) + elif self.placeobj: + self.placeobj.add_source_reference(self.source_ref) + elif self.family: + self.family.add_source_reference(self.source_ref) + + def start_source(self,attrs): + self.source = self.db.find_source_no_conflicts(attrs["id"],self.smap) + + def start_objref(self,attrs): + self.objref = RelLib.MediaRef() + id = self.db.find_object_no_conflicts(attrs['ref'],self.media_file_map).get_id() + self.objref.set_reference_id(id) + if attrs.has_key('priv'): + self.objref.set_privacy(int(attrs['priv'])) + if self.family: + self.family.add_media_reference(self.objref) + elif self.source: + self.source.add_media_reference(self.objref) + elif self.person: + self.person.add_media_reference(self.objref) + elif self.placeobj: + self.placeobj.add_media_reference(self.objref) + + def start_object(self,attrs): + self.object = self.db.find_object_no_conflicts(attrs['id'],self.media_file_map) + self.object.set_mime_type(attrs['mime']) + self.object.set_description(attrs['description']) + src = attrs["src"] + if src: + if src[0] != '/': + self.object.set_path("%s/%s" % (self.base,src)) + else: + self.object.set_path(src) + + def stop_people(self,tag): + pass + + def stop_object(self,tag): + self.db.commit_media_object(self.object) + self.object = None + + def stop_objref(self,tag): + self.objref = None + + def start_photo(self,attrs): + self.photo = RelLib.MediaObject() + self.pref = RelLib.MediaRef() + self.pref.set_reference_id(self.photo.get_id()) + + for key in attrs.keys(): + if key == "descrip" or key == "description": + self.photo.set_description(attrs[key]) + elif key == "priv": + self.pref.set_privacy(int(attrs[key])) + elif key == "src": + src = attrs["src"] + if src[0] != '/': + self.photo.set_path("%s/%s" % (self.base,src)) + else: + self.photo.set_path(src) + else: + a = RelLib.Attribute() + a.set_type(key) + a.set_value(attrs[key]) + self.photo.add_attribute(a) + self.photo.set_mime_type(GrampsMime.get_type(self.photo.get_path())) + self.db.add_object(self.photo) + if self.family: + self.family.add_media_reference(self.pref) + elif self.source: + self.source.add_media_reference(self.pref) + elif self.person: + self.person.add_media_reference(self.pref) + elif self.placeobj: + self.placeobj.add_media_reference(self.pref) + + def start_daterange(self,attrs): + if self.source_ref: + d = self.source_ref.get_date() + elif self.ord: + d = self.ord.get_date_object() + elif self.address: + d = self.address.get_date_object() + else: + d = self.event.get_date_object() + + if attrs.has_key("calendar"): + d.set_calendar_val(int(attrs['calendar'])) + + if attrs.has_key("cformat"): + d.set_calendar(Calendar.find_calendar(attrs['calendar'])) + + d.get_start_date().set_iso_date(attrs['start']) + d.get_stop_date().set_iso_date(attrs['stop']) + d.range = 1 + + def start_dateval(self,attrs): + if self.source_ref: + d = self.source_ref.get_date() + elif self.ord: + d = self.ord.get_date_object() + elif self.address: + d = self.address.get_date_object() + else: + d = self.event.get_date_object() + + if attrs.has_key("calendar"): + d.set_calendar_val(int(attrs['calendar'])) + + if attrs.has_key("cformat"): + d.set_calendar(Calendar.find_calendar(attrs['cformat'])) + + d.get_start_date().set_iso_date(attrs['val']) + + if attrs.has_key("type"): + d.get_start_date().set_mode(attrs['type']) + else: + d.get_start_date().set_mode(None) + + def start_datestr(self,attrs): + if self.source_ref: + d = self.source_ref.get_date() + elif self.ord: + d = self.ord.get_date_object() + elif self.address: + d = self.address.get_date_object() + else: + d = self.event.get_date_object() + + d.set(attrs['val']) + + def start_created(self,attrs): + if attrs.has_key('sources'): + self.num_srcs = int(attrs['sources']) + else: + self.num_srcs = 0 + if attrs.has_key('places'): + self.num_places = int(attrs['places']) + else: + self.num_places = 0 + self.entries = int(attrs["people"]) + int(attrs["families"]) + \ + self.num_places + self.num_srcs + + def start_pos(self,attrs): + self.person.position = (int(attrs["x"]), int(attrs["y"])) + + def stop_attribute(self,tag): + self.attribute = None + + def stop_comment(self,tag): + if tag.strip(): + self.witness_comment = tag + else: + self.witness_comment = "" + + def stop_witness(self,tag): + if self.witness_comment: + self.witness.set_comment(self.witness_comment) + elif tag.strip(): + self.witness.set_comment(tag) + else: + self.witness.set_comment("") + self.event.add_witness(self.witness) + self.in_witness = 0 + + def stop_attr_type(self,tag): + self.attribute.set_type(tag) + + def stop_attr_value(self,tag): + self.attribute.set_value(tag) + + def stop_address(self,tag): + self.address = None + + def stop_places(self,tag): + self.placeobj = None + + def stop_photo(self,tag): + self.photo = None + + def stop_placeobj(self,tag): + if self.placeobj.get_title() == "": + loc = self.placeobj.get_main_location() + self.placeobj.set_title(build_place_title(loc)) + self.db.commit_place(self.placeobj) + self.placeobj = None + + def stop_family(self,tag): + self.db.commit_family(self.family) + self.family = None + + def stop_event(self,tag): + self.event.name = self.event_type + + if self.family: + self.family.add_event_id(self.event.get_id()) + else: + if self.event_type == "Birth": + self.person.set_birth_id(self.event.get_id()) + elif self.event_type == "Death": + self.person.set_death_id(self.event.get_id()) + else: + self.person.add_event_id(self.event.get_id()) + self.db.commit_event(self.event) + self.event = None + + def stop_name(self,tag): + if self.in_witness: + self.witness = RelLib.Witness(RelLib.Event.NAME,tag) + else: + if self.name.get_type() == "": + self.name.set_type("Birth Name") + self.person.set_primary_name (self.name) + self.person.get_primary_name().build_sort_name() + self.name = None + + def stop_ref(self,tag): + self.witness = RelLib.Witness(RelLib.Event.ID,tag) + + def stop_place(self,tag): + if self.placeobj == None: + if self.place_map.has_key(tag): + self.placeobj = self.place_map[tag] + else: + self.placeobj = RelLib.Place() + self.placeobj.set_title(tag) + if self.ord: + self.ord.set_place_id(self.placeobj.get_id()) + else: + self.event.set_place_id(self.placeobj.get_id()) + self.db.commit_place(self.placeobj) + self.placeobj = None + + def stop_date(self,tag): + if tag: + if self.address: + self.address.set_date(tag) + else: + self.event.set_date(tag) + + def stop_first(self,tag): + self.name.set_first_name(tag) + + def stop_families(self,tag): + self.family = None + + def stop_person(self,tag): + self.db.commit_person(self.person) + self.person = None + + def stop_description(self,tag): + self.event.set_description(tag) + + def stop_cause(self,tag): + self.event.set_cause(tag) + + def stop_gender(self,tag): + t = tag + if t == "M": + self.person.set_gender (RelLib.Person.male) + elif t == "F": + self.person.set_gender (RelLib.Person.female) + else: + self.person.set_gender (RelLib.Person.unknown) + + def stop_stitle(self,tag): + self.source.set_title(tag) + + def stop_sourceref(self,tag): + self.source_ref = None + + def stop_source(self,tag): + self.db.commit_source(self.source) + self.source = None + + def stop_sauthor(self,tag): + self.source.set_author(tag) + + def stop_sdate(self,tag): + date = Date.Date() + date.set(tag) + self.source_ref.set_date(date) + + def stop_phone(self,tag): + self.address.set_phone(tag) + + def stop_street(self,tag): + self.address.set_street(tag) + + def stop_city(self,tag): + self.address.set_city(tag) + + def stop_state(self,tag): + self.address.set_state(tag) + + def stop_country(self,tag): + self.address.setCountry(tag) + + def stop_postal(self,tag): + self.address.set_postal_code(tag) + + def stop_spage(self,tag): + self.source_ref.set_page(tag) + + def stop_lds_ord(self,tag): + self.ord = None + + def stop_spubinfo(self,tag): + self.source.set_publication_info(tag) + + def stop_sabbrev(self,tag): + self.source.set_abbreviation(tag) + + def stop_stext(self,tag): + if self.use_p: + self.use_p = 0 + note = fix_spaces(self.stext_list) + else: + note = tag + self.source_ref.set_text(note) + + def stop_scomments(self,tag): + if self.use_p: + self.use_p = 0 + note = fix_spaces(self.scomments_list) + else: + note = tag + self.source_ref.set_comments(note) + + def stop_last(self,tag): + if self.name: + self.name.set_surname(tag) + + def stop_suffix(self,tag): + if self.name: + self.name.set_suffix(tag) + + def stop_title(self,tag): + if self.name: + self.name.set_title(tag) + + def stop_nick(self,tag): + if self.person: + self.person.set_nick_name(tag) + + def stop_note(self,tag): + self.in_note = 0 + if self.use_p: + self.use_p = 0 + text = fix_spaces(self.note_list) + else: + text = tag + self.note.set(text) + + if self.address: + self.address.set_note_object(self.note) + elif self.ord: + self.ord.set_note_object(self.note) + elif self.attribute: + self.attribute.set_note_object(self.note) + elif self.object: + self.object.set_note_object(self.note) + elif self.objref: + self.objref.set_note_object(self.note) + elif self.photo: + self.photo.set_note_object(self.note) + elif self.name: + self.name.set_note_object(self.note) + elif self.source: + self.source.set_note_object(self.note) + elif self.event: + self.event.set_note_object(self.note) + elif self.person: + self.person.set_note_object(self.note) + elif self.family: + self.family.set_note_object(self.note) + elif self.placeobj: + self.placeobj.set_note_object(self.note) + + def stop_research(self,tag): + self.owner.set(self.resname, self.resaddr, self.rescity, self.resstate, + self.rescon, self.respos, self.resphone, self.resemail) + + def stop_resname(self,tag): + self.resname = tag + + def stop_resaddr(self,tag): + self.resaddr = tag + + def stop_rescity(self,tag): + self.rescity = tag + + def stop_resstate(self,tag): + self.resstate = tag + + def stop_rescountry(self,tag): + self.rescon = tag + + def stop_respostal(self,tag): + self.respos = tag + + def stop_resphone(self,tag): + self.resphone = tag + + def stop_resemail(self,tag): + self.resemail = tag + + def stop_ptag(self,tag): + self.use_p = 1 + if self.in_note: + self.note_list.append(tag) + elif self.in_stext: + self.stext_list.append(tag) + elif self.in_scomments: + self.scomments_list.append(tag) + + def stop_aka(self,tag): + self.person.add_alternate_name(self.name) + if self.name.get_type() == "": + self.name.set_type("Also Known As") + self.name = None + + def startElement(self,tag,attrs): + + self.func_list[self.func_index] = (self.func,self.tlist) + self.func_index = self.func_index + 1 + self.tlist = [] + + try: + f,self.func = self.func_map[tag] + if f: + f(attrs) + except KeyError: + self.func_map[tag] = (None,None) + self.func = None + + def endElement(self,tag): + + if self.func: + self.func(string.join(self.tlist,'')) + self.func_index = self.func_index - 1 + self.func,self.tlist = self.func_list[self.func_index] + + def characters(self, data): + if self.func: + self.tlist.append(data) + +def append_value(orig,val): + if orig: + return "%s, %s" % (orig,val) + else: + return val + +def build_place_title(loc): + "Builds a title from a location" + city = loc.get_city() + state = loc.get_state() + country = loc.get_country() + county = loc.get_county() + parish = loc.get_parish() + + value = "" + + if parish: + value = parish + if city: + value = append_value(value,city) + if county: + value = append_value(value,county) + if state: + value = append_value(value,state) + if country: + value = append_value(value,country) + return value + diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index c19b0eb17..35eac08ba 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -71,7 +71,6 @@ PLACE_KEY = 5 #------------------------------------------------------------------------- _id_reg = compile("%\d+d") - #------------------------------------------------------------------------- # # SourceNote @@ -2426,6 +2425,9 @@ class GrampsDB: self.surnames.open(name, "surnames", db.DB_HASH, flags=db.DB_CREATE) self.person_map.associate(self.surnames, find_surname, db.DB_CREATE) + self.bookmarks = self.metadata.get('bookmarks') + if self.bookmarks == None: + self.bookmarks = [] return 1 def close(self): @@ -2435,6 +2437,7 @@ class GrampsDB: self.source_map.close() self.media_map.close() self.event_map.close() + self.metadata['bookmarks'] = self.bookmarks self.metadata.close() self.surnames.close() self.env.close() diff --git a/gramps2/src/SourceView.py b/gramps2/src/SourceView.py index 65c538e99..826d5e562 100644 --- a/gramps2/src/SourceView.py +++ b/gramps2/src/SourceView.py @@ -38,6 +38,7 @@ import RelLib import EditSource import Utils import DisplayModels +import const from QuestionDialog import QuestionDialog @@ -73,7 +74,10 @@ class SourceView: self.renderer = gtk.CellRendererText() - self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.db)) + if const.nosort_tree: + self.model = DisplayModels.SourceModel(self.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.db)) self.list.set_model(self.model) self.topWindow = self.glade.get_widget("gramps") @@ -85,10 +89,11 @@ class SourceView: self.list.remove_column(column) column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0) - column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + column.set_resizable(gtk.TRUE) + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(0) column.set_min_width(225) - column.set_sort_column_id(0) self.list.append_column(column) self.columns = [column] @@ -99,9 +104,10 @@ class SourceView: name = column_names[pair[1]] column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(gtk.TRUE) - column.set_clickable(gtk.TRUE) + if not const.nosort_tree: + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(index) column.set_min_width(75) - column.set_sort_column_id(index) self.columns.append(column) self.list.append_column(column) index += 1 @@ -115,7 +121,10 @@ class SourceView: def build_tree(self): self.list.set_model(None) - self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) + if const.nosort_tree: + self.model = DisplayModels.SourceModel(self.parent.db) + else: + self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) self.list.set_model(self.model) self.selection = self.list.get_selection() diff --git a/gramps2/src/const.py.in b/gramps2/src/const.py.in index 054aaf487..fc3b52bb5 100644 --- a/gramps2/src/const.py.in +++ b/gramps2/src/const.py.in @@ -62,7 +62,6 @@ if os.environ.has_key('GRAMPSDIR'): else: rootDir = "." -papersize = "file:%s/papersize.xml" % rootDir good_xpm = "%s/good.png" % rootDir bad_xpm = "%s/bad.png" % rootDir caution_xpm = "%s/caution.png" % rootDir @@ -93,11 +92,20 @@ filtersDir = "%s/filters" % rootDir dataDir = "%s/data" % rootDir gtkrcFile = "%s/gtkrc" % rootDir template_dir = "%s/templates" % dataDir +papersize = "file:%s/papersize.xml" % dataDir fdl = "%s/fdl.txt" % dataDir startup = 1 dnd_images = 1 +#------------------------------------------------------------------------- +# +# Paths to external programs +# +#------------------------------------------------------------------------- + +nosort_tree = os.environ.has_key('NOSORT') and os.environ['NOSORT'] == "1" + #------------------------------------------------------------------------- # # About box information @@ -877,3 +885,5 @@ notes_formats = [ _("Flowed"), _("Preformatted"), ] + + diff --git a/gramps2/src/data/Makefile.am b/gramps2/src/data/Makefile.am index 22fe33411..4d9f70aa3 100644 --- a/gramps2/src/data/Makefile.am +++ b/gramps2/src/data/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS = templates pkgdatadir = $(datadir)/@PACKAGE@/data -pkgdata_DATA = gedcom.xml +pkgdata_DATA = gedcom.xml papersize.xml EXTRA_DIST = $(pkgdata_DATA) diff --git a/gramps2/src/papersize.xml b/gramps2/src/data/papersize.xml similarity index 100% rename from gramps2/src/papersize.xml rename to gramps2/src/data/papersize.xml diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 5ef370a2d..6ff2fd18e 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -70,7 +70,6 @@ import Bookmarks import GrampsCfg import EditPerson import Find -import ReadXML import DbPrompter try: # First try python2.3 and later: this is the future @@ -1626,14 +1625,6 @@ class Gramps: self.db.clear_added_media_objects() return self.post_load(name) - def load_revision(self,f,name,revision): - filename = "%s/%s" % (name,self.db.get_base()) - self.status_text(_('Loading %s...' % name)) - if ReadXML.loadRevision(self.db,f,filename,revision,self.load_progress) == 0: - return 0 - self.db.clear_added_media_objects() - return self.post_load(name) - def setup_bookmarks(self): self.bookmarks = Bookmarks.Bookmarks(self.db,self.db.get_bookmarks(), self.gtop.get_widget("jump_to"), @@ -1659,7 +1650,7 @@ class Gramps: def on_add_bookmark_activate(self,obj): if self.active_person: - self.bookmarks.add(self.active_person) + self.bookmarks.add(self.active_person.get_id()) name = GrampsCfg.nameof(self.active_person) self.status_text(_("%s has been bookmarked") % name) gtk.timeout_add(5000,self.modify_statusbar) diff --git a/gramps2/src/plugins/Makefile.in b/gramps2/src/plugins/Makefile.in index d0a532b7c..a0aaf2a41 100644 --- a/gramps2/src/plugins/Makefile.in +++ b/gramps2/src/plugins/Makefile.in @@ -172,7 +172,6 @@ GLADEFILES = \ gedcomexport.glade\ gedcomimport.glade\ merge.glade\ - pafexport.glade\ patchnames.glade\ pkgexport.glade\ relcalc.glade\ diff --git a/gramps2/src/plugins/ReadGedcom.py b/gramps2/src/plugins/ReadGedcom.py index 2df9e54ec..44a4a545b 100644 --- a/gramps2/src/plugins/ReadGedcom.py +++ b/gramps2/src/plugins/ReadGedcom.py @@ -71,7 +71,7 @@ UPDATE = 25 db = None callback = None -_title_string = _("Import from GEDCOM") +_title_string = _("GEDCOM") def nocnv(s): return unicode(s) diff --git a/gramps2/src/plugins/ReadNative.py b/gramps2/src/plugins/ReadNative.py index cb1fbb8e9..21872d29a 100644 --- a/gramps2/src/plugins/ReadNative.py +++ b/gramps2/src/plugins/ReadNative.py @@ -31,7 +31,7 @@ import gtk import const import os -_title_string = _("Import from GRAMPS database") +_title_string = _("GRAMPS XML database") #------------------------------------------------------------------------- # diff --git a/gramps2/src/plugins/ReadPkg.py b/gramps2/src/plugins/ReadPkg.py index 110782942..8a72b08ca 100644 --- a/gramps2/src/plugins/ReadPkg.py +++ b/gramps2/src/plugins/ReadPkg.py @@ -33,7 +33,7 @@ import os from QuestionDialog import ErrorDialog, WarningDialog import TarFile -_title_string = _("Import from GRAMPS package") +_title_string = _("GRAMPS package") #------------------------------------------------------------------------- # #