From de04ab2ae329b64f4580c5d417ce3d378de727a9 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 16 Oct 2001 03:50:33 +0000 Subject: [PATCH] Cleaned up more code, broke LocationEditor into its own file svn: r475 --- gramps/src/Bookmarks.py | 106 +++------ gramps/src/EditPlace.py | 414 ++++++++++------------------------- gramps/src/EditSource.py | 65 +++--- gramps/src/Find.py | 20 +- gramps/src/GrampsParser.py | 1 + gramps/src/LocEdit.py | 126 +++++++++++ gramps/src/VersionControl.py | 35 +++ gramps/src/WriteXML.py | 2 +- gramps/src/gramps_main.py | 198 ++++++----------- 9 files changed, 408 insertions(+), 559 deletions(-) create mode 100644 gramps/src/LocEdit.py diff --git a/gramps/src/Bookmarks.py b/gramps/src/Bookmarks.py index 1bfe4b200..7c4df303c 100644 --- a/gramps/src/Bookmarks.py +++ b/gramps/src/Bookmarks.py @@ -41,9 +41,8 @@ import utils # Constants # #------------------------------------------------------------------------- -OBJECT = "o" -TOPINST = "top" -NAMEINST = "namelist" +_TOPINST = "top" +_NAMEINST = "namelist" #------------------------------------------------------------------------- # @@ -119,88 +118,51 @@ class Bookmarks : # #--------------------------------------------------------------------- def edit(self): - top = libglade.GladeXML(const.bookFile,TOPINST) - namelist = top.get_widget(NAMEINST) + top = libglade.GladeXML(const.bookFile,_TOPINST) + self.namelist = top.get_widget(_NAMEINST) index = 0 for person in self.bookmarks: - namelist.append([person.getPrimaryName().getName()]) - namelist.set_row_data(index,person) + self.namelist.append([person.getPrimaryName().getName()]) + self.namelist.set_row_data(index,person) index = index + 1 top.signal_autoconnect({ - "on_ok_clicked" : on_ok_clicked, - "on_down_clicked" : on_down_clicked, - "on_up_clicked" : on_up_clicked, - "on_delete_clicked" : on_delete_clicked, - "on_cancel_clicked" : on_cancel_clicked + "on_ok_clicked" : self.on_ok_clicked, + "on_down_clicked" : self.on_down_clicked, + "on_up_clicked" : self.on_up_clicked, + "on_delete_clicked" : self.on_delete_clicked, + "on_cancel_clicked" : self.on_cancel_clicked }) - topBox = top.get_widget(TOPINST) - topBox.set_data(OBJECT,self) - topBox.set_data(NAMEINST,namelist) - topBox.show() + def on_delete_clicked(self,obj): + if len(obj.selection) > 0: + index = obj.selection[0] + obj.remove(index) -#------------------------------------------------------------------------- -# -# on_delete_clicked - gets the selected row and number of rows that have -# been attached to the namelist. If the selected row is greater than 0, -# then the row is deleted from the list. The number of rows is then -# decremented. -# -#------------------------------------------------------------------------- -def on_delete_clicked(obj): - if len(obj.selection) > 0: - index = obj.selection[0] - obj.remove(index) + def on_up_clicked(self,obj): + if len(obj.selection) > 0: + index = obj.selection[0] + obj.swap_rows(index-1,index) -#------------------------------------------------------------------------- -# -# on_up_clicked - swap rows if the selected row is greater than 0 -# -#------------------------------------------------------------------------- -def on_up_clicked(obj): - if len(obj.selection) > 0: - index = obj.selection[0] - obj.swap_rows(index-1,index) + def on_down_clicked(self,obj): + if len(obj.selection) > 0: + index = obj.selection[0] + if index != obj.rows-1: + obj.swap_rows(index+1,index) -#------------------------------------------------------------------------- -# -# on_down_clicked - swap rows if the selected index is not the last index -# -#------------------------------------------------------------------------- -def on_down_clicked(obj): - if len(obj.selection) > 0: - index = obj.selection[0] - if index != obj.rows-1: - obj.swap_rows(index+1,index) - -#------------------------------------------------------------------------- -# -# on_ok_clicked - loop through the name list, extracting the attached -# person from list, and building up the new bookmark list. The menu is -# then redrawn. -# -#------------------------------------------------------------------------- -def on_ok_clicked(obj): - bkmarks = obj.get_data(OBJECT) - namelist = obj.get_data(NAMEINST) - del bkmarks.bookmarks[0:] + def on_ok_clicked(self,obj): + del self.bookmarks[0:] - for index in range(0,bkmarks.index): - person = namelist.get_row_data(index) - if person: - bkmarks.bookmarks.append(person) + for index in range(0,self.index): + person = self.namelist.get_row_data(index) + if person: + self.bookmarks.append(person) - bkmarks.redraw() - obj.destroy() + self.redraw() + obj.destroy() -#------------------------------------------------------------------------- -# -# on_cancel_clicked - destroy the bookmark editor -# -#------------------------------------------------------------------------- -def on_cancel_clicked(obj): - obj.destroy() + def on_cancel_clicked(self,obj): + obj.destroy() diff --git a/gramps/src/EditPlace.py b/gramps/src/EditPlace.py index 9083971f5..15759cd56 100644 --- a/gramps/src/EditPlace.py +++ b/gramps/src/EditPlace.py @@ -114,27 +114,26 @@ class EditPlace: self.top_window.signal_autoconnect({ "destroy_passed_object" : utils.destroy_passed_object, - "on_source_clicked" : on_source_clicked, + "on_source_clicked" : self.on_source_clicked, "on_photolist_select_icon" : self.gallery.on_photo_select_icon, "on_photolist_button_press_event" : self.gallery.on_photolist_button_press_event, - "on_switch_page" : on_switch_page, + "on_switch_page" : self.on_switch_page, "on_addphoto_clicked" : self.gallery.on_add_photo_clicked, "on_deletephoto_clicked" : self.gallery.on_delete_photo_clicked, "on_edit_properties_clicked": self.gallery.popup_change_description, - "on_add_url_clicked" : on_add_url_clicked, - "on_delete_url_clicked" : on_delete_url_clicked, - "on_update_url_clicked" : on_update_url_clicked, - "on_add_loc_clicked" : on_add_loc_clicked, - "on_delete_loc_clicked" : on_delete_loc_clicked, - "on_update_loc_clicked" : on_update_loc_clicked, - "on_web_list_select_row" : on_web_list_select_row, - "on_web_go_clicked": on_web_go_clicked, - "on_loc_list_select_row" : on_loc_list_select_row, - "on_apply_clicked" : on_place_apply_clicked + "on_add_url_clicked" : self.on_add_url_clicked, + "on_delete_url_clicked" : self.on_delete_url_clicked, + "on_update_url_clicked" : self.on_update_url_clicked, + "on_add_loc_clicked" : self.on_add_loc_clicked, + "on_delete_loc_clicked" : self.on_delete_loc_clicked, + "on_update_loc_clicked" : self.on_update_loc_clicked, + "on_web_list_select_row" : self.on_web_list_select_row, + "on_web_go_clicked": self.on_web_go_clicked, + "on_loc_list_select_row" : self.on_loc_list_select_row, + "on_apply_clicked" : self.on_place_apply_clicked }) self.top = self.top_window.get_widget("placeEditor") - self.top.set_data(_PLACE,self) # Typing CR selects OK button self.top.editable_enters(self.title); @@ -149,28 +148,15 @@ class EditPlace: self.top_window.get_widget("add_photo").set_sensitive(0) self.top_window.get_widget("delete_photo").set_sensitive(0) - self.web_list.set_data(_PLACE,self) self.redraw_url_list() - - self.loc_list.set_data(_PLACE,self) self.redraw_location_list() - #------------------------------------------------------------------------- - # - # - # - #------------------------------------------------------------------------- def update_lists(self): self.place.setUrlList(self.ulist) self.place.set_alternate_locations(self.llist) if self.lists_changed: utils.modified() - #--------------------------------------------------------------------- - # - # redraw_url_list - redraws the altername name list for the person - # - #--------------------------------------------------------------------- def redraw_url_list(self): length = utils.redraw_list(self.ulist,self.web_list,disp_url) if length > 0: @@ -180,307 +166,135 @@ class EditPlace: self.web_url.set_text("") self.web_description.set_text("") - #--------------------------------------------------------------------- - # - # redraw_location_list - # - #--------------------------------------------------------------------- def redraw_location_list(self): utils.redraw_list(self.llist,self.loc_list,disp_loc) -def on_web_go_clicked(obj): - import gnome.url + def on_web_go_clicked(self,obj): + import gnome.url - text = obj.get() - if text != "": - gnome.url.show(text) + text = obj.get() + if text != "": + gnome.url.show(text) -#----------------------------------------------------------------------------- -# -# -# -#----------------------------------------------------------------------------- -def on_place_apply_clicked(obj): + def on_place_apply_clicked(self,obj): - edit = obj.get_data(_PLACE) - title = edit.title.get_text() - city = edit.city.get_text() - county = edit.county.get_text() - state = edit.state.get_text() - country = edit.country.get_text() - longitude = edit.longitude.get_text() - latitude = edit.latitude.get_text() - note = edit.note.get_chars(0,-1) + title = self.title.get_text() + city = self.city.get_text() + county = self.county.get_text() + state = self.state.get_text() + country = self.country.get_text() + longitude = self.longitude.get_text() + latitude = self.latitude.get_text() + note = self.note.get_chars(0,-1) - mloc = edit.place.get_main_location() - if city != mloc.get_city(): - mloc.set_city(city) - utils.modified() + mloc = self.place.get_main_location() + if city != mloc.get_city(): + mloc.set_city(city) + utils.modified() - if edit.lists_changed: - edit.place.setSourceRefList(edit.srcreflist) - utils.modified() + if self.lists_changed: + self.place.setSourceRefList(self.srcreflist) + utils.modified() - if state != mloc.get_state(): - mloc.set_state(state) - utils.modified() + if state != mloc.get_state(): + mloc.set_state(state) + utils.modified() - if county != mloc.get_county(): - mloc.set_county(county) - utils.modified() + if county != mloc.get_county(): + mloc.set_county(county) + utils.modified() - if country != mloc.get_country(): - mloc.set_country(country) - utils.modified() + if country != mloc.get_country(): + mloc.set_country(country) + utils.modified() - if title != edit.place.get_title(): - edit.place.set_title(title) - utils.modified() + if title != self.place.get_title(): + self.place.set_title(title) + utils.modified() - if longitude != edit.place.get_longitude(): - edit.place.set_longitude(longitude) - utils.modified() + if longitude != self.place.get_longitude(): + self.place.set_longitude(longitude) + utils.modified() - if latitude != edit.place.get_latitude(): - edit.place.set_latitude(latitude) - utils.modified() + if latitude != self.place.get_latitude(): + self.place.set_latitude(latitude) + utils.modified() - if note != edit.place.getNote(): - edit.place.setNote(note) - utils.modified() + if note != self.place.getNote(): + self.place.setNote(note) + utils.modified() - edit.update_lists() + self.update_lists() - utils.destroy_passed_object(edit.top) - edit.callback(edit.place) + utils.destroy_passed_object(self.top) + self.callback(self.place) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_switch_page(obj,a,page): - src = obj.get_data(_PLACE) - if page == 3 and src.not_loaded: - src.not_loaded = 0 - src.gallery.load_images() + def on_switch_page(self,obj,a,page): + if page == 3 and self.not_loaded: + self.not_loaded = 0 + self.gallery.load_images() -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_update_url_clicked(obj): - import UrlEdit - if len(obj.selection) > 0: - row = obj.selection[0] - mobj = obj.get_data(_PLACE) - if mobj.place: - name = _("Internet Address Editor for %s") % mobj.place.get_title() + def on_update_url_clicked(self,obj): + import UrlEdit + if len(obj.selection) > 0: + row = obj.selection[0] + if self.place: + name = _("Internet Address Editor for %s") % self.place.get_title() + else: + name = _("Internet Address Editor") + UrlEdit.UrlEditor(self,name,obj.get_row_data(row)) + + def on_update_loc_clicked(self,obj): + import LocEdit + if len(obj.selection) > 0: + row = obj.selection[0] + LocEdit.LocationEditor(self,obj.get_row_data(row)) + + def on_delete_url_clicked(self,obj): + if utils.delete_selected(obj,self.ulist): + self.lists_changed = 1 + self.redraw_url_list() + + def on_delete_loc_clicked(self,obj): + if utils.delete_selected(obj,self.llist): + self.lists_changed = 1 + self.redraw_location_list() + + def on_add_url_clicked(self,obj): + import UrlEdit + if self.place: + name = _("Internet Address Editor for %s") % self.place.get_title() else: name = _("Internet Address Editor") - UrlEdit.UrlEditor(mobj,name,obj.get_row_data(row)) + UrlEdit.UrlEditor(self,name,None) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_update_loc_clicked(obj): - if len(obj.selection) > 0: - row = obj.selection[0] - LocationEditor(obj.get_data(_PLACE),obj.get_row_data(row)) + def on_add_loc_clicked(self,obj): + import LocEdit + LocEdit.LocationEditor(self,None) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_delete_url_clicked(obj): - epo = obj.get_data(_PLACE) - if utils.delete_selected(obj,epo.ulist): - epo.lists_changed = 1 - epo.redraw_url_list() + def on_source_clicked(self,obj): + Sources.SourceSelector(self.srcreflist,self,src_changed) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_delete_loc_clicked(obj): - epo = obj.get_data(_PLACE) - if utils.delete_selected(obj,epo.llist): - epo.lists_changed = 1 - epo.redraw_location_list() - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_add_url_clicked(obj): - import UrlEdit - mobj = obj.get_data(_PLACE) - if mobj.place: - name = _("Internet Address Editor for %s") % mobj.place.get_title() - else: - name = _("Internet Address Editor") - UrlEdit.UrlEditor(mobj,name,None) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_add_loc_clicked(obj): - LocationEditor(obj.get_data(_PLACE),None) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_source_clicked(obj): - epo = obj.get_data(_PLACE) - Sources.SourceSelector(epo.srcreflist,epo,src_changed) - -def src_changed(parent): - parent.lists_changed = 1 - -#------------------------------------------------------------------------- -# -# on_web_list_select_row - sets the row object attached to the passed -# object, and then updates the display with the data corresponding to -# the row. -# -#------------------------------------------------------------------------- -def on_web_list_select_row(obj,row,b,c): - - epo = obj.get_data(_PLACE) - url = obj.get_row_data(row) - - if url == None: - epo.web_url.set_text("") - epo.web_go.set_sensitive(0) - epo.web_description.set_text("") - else: - path = url.get_path() - epo.web_url.set_text(path) - epo.web_go.set_sensitive(1) - epo.web_description.set_text(url.get_description()) - -#------------------------------------------------------------------------- -# -# on_loclist_select_row - sets the row object attached to the passed -# object, and then updates the display with the data corresponding to -# the row. -# -#------------------------------------------------------------------------- -def on_loc_list_select_row(obj,row,b,c): - - epo = obj.get_data(_PLACE) - loc = obj.get_row_data(row) - - epo.loc_city.set_text(loc.get_city()) - epo.loc_county.set_text(loc.get_county()) - epo.loc_state.set_text(loc.get_state()) - epo.loc_country.set_text(loc.get_country()) - -#------------------------------------------------------------------------- -# -# update_location -# -# Updates the specified event with the specified date. Compares against -# the previous value, so the that modified flag is not set if nothing has -# actually changed. -# -#------------------------------------------------------------------------- -def update_location(loc,city,county,state,country): - changed = 0 - - if loc.get_city() != city: - loc.set_city(city) - changed = 1 - - if loc.get_county() != county: - loc.set_county(county) - changed = 1 - - if loc.get_state() != state: - loc.set_state(state) - changed = 1 - - if loc.get_country() != country: - loc.set_country(country) - changed = 1 - return changed - -#------------------------------------------------------------------------- -# -# LocationEditor class -# -#------------------------------------------------------------------------- -class LocationEditor: - - def __init__(self,parent,location): - self.parent = parent - self.location = location - self.top = libglade.GladeXML(const.dialogFile, "loc_edit") - self.window = self.top.get_widget("loc_edit") - self.city = self.top.get_widget("city") - self.state = self.top.get_widget("state") - self.county = self.top.get_widget("county") - self.country = self.top.get_widget("country") - - # Typing CR selects OK button - self.window.editable_enters(self.city); - self.window.editable_enters(self.county); - self.window.editable_enters(self.state); - self.window.editable_enters(self.country); - - if parent.place: - name = _("Location Editor for %s") % parent.place.get_title() + def on_web_list_select_row(self,obj,row,b,c): + url = obj.get_row_data(row) + if url == None: + self.web_url.set_text("") + self.web_go.set_sensitive(0) + self.web_description.set_text("") else: - name = _("Location Editor") - - self.top.get_widget("locationTitle").set_text(name) + path = url.get_path() + self.web_url.set_text(path) + self.web_go.set_sensitive(1) + self.web_description.set_text(url.get_description()) - if location != None: - self.city.set_text(location.get_city()) - self.county.set_text(location.get_county()) - self.country.set_text(location.get_country()) - self.state.set_text(location.get_state()) + def on_loc_list_select_row(self,obj,row,b,c): + loc = obj.get_row_data(row) - self.window.set_data("o",self) - self.top.signal_autoconnect({ - "destroy_passed_object" : utils.destroy_passed_object, - "on_loc_edit_ok_clicked" : on_location_edit_ok_clicked - }) - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_location_edit_ok_clicked(obj): - ee = obj.get_data("o") - loc = ee.location - - city = ee.city.get_text() - county = ee.county.get_text() - country = ee.country.get_text() - state = ee.state.get_text() - - if loc == None: - loc = Location() - ee.parent.llist.append(loc) - - if update_location(loc,city,county,state,country): - ee.parent.lists_changed = 1 - - ee.parent.redraw_location_list() - utils.destroy_passed_object(obj) + self.loc_city.set_text(loc.get_city()) + self.loc_county.set_text(loc.get_county()) + self.loc_state.set_text(loc.get_state()) + self.loc_country.set_text(loc.get_country()) #------------------------------------------------------------------------- # @@ -498,3 +312,5 @@ def disp_url(url): def disp_loc(loc): return [loc.get_city(),loc.get_county(),loc.get_state(),loc.get_country()] +def src_changed(parent): + parent.lists_changed = 1 diff --git a/gramps/src/EditSource.py b/gramps/src/EditSource.py index 59e741951..2cac27aba 100644 --- a/gramps/src/EditSource.py +++ b/gramps/src/EditSource.py @@ -53,7 +53,6 @@ _ = intl.gettext # Constants # #------------------------------------------------------------------------- -SOURCE = "s" class EditSource: @@ -85,14 +84,13 @@ class EditSource: "destroy_passed_object" : utils.destroy_passed_object, "on_photolist_select_icon" : self.gallery.on_photo_select_icon, "on_photolist_button_press_event" : self.gallery.on_photolist_button_press_event, - "on_switch_page" : on_switch_page, + "on_switch_page" : self.on_switch_page, "on_addphoto_clicked" : self.gallery.on_add_photo_clicked, "on_deletephoto_clicked" : self.gallery.on_delete_photo_clicked, - "on_sourceapply_clicked" : on_source_apply_clicked + "on_sourceapply_clicked" : self.on_source_apply_clicked }) self.top = self.top_window.get_widget("sourceEditor") - self.top.set_data(SOURCE,self) if self.source.getId() == "": self.top_window.get_widget("add_photo").set_sensitive(0) @@ -102,47 +100,34 @@ class EditSource: self.top.editable_enters(self.author); self.top.editable_enters(self.pubinfo); + def on_source_apply_clicked(self,obj): -#----------------------------------------------------------------------------- -# -# -# -#----------------------------------------------------------------------------- -def on_source_apply_clicked(obj): - - edit = obj.get_data(SOURCE) - title = edit.title.get_text() - author = edit.author.get_text() - pubinfo = edit.pubinfo.get_text() - note = edit.note.get_chars(0,-1) + title = self.title.get_text() + author = self.author.get_text() + pubinfo = self.pubinfo.get_text() + note = self.note.get_chars(0,-1) - if author != edit.source.getAuthor(): - edit.source.setAuthor(author) - utils.modified() + if author != self.source.getAuthor(): + self.source.setAuthor(author) + utils.modified() - if title != edit.source.getTitle(): - edit.source.setTitle(title) - utils.modified() + if title != self.source.getTitle(): + self.source.setTitle(title) + utils.modified() - if pubinfo != edit.source.getPubInfo(): - edit.source.setPubInfo(pubinfo) - utils.modified() + if pubinfo != self.source.getPubInfo(): + self.source.setPubInfo(pubinfo) + utils.modified() - if note != edit.source.getNote(): - edit.source.setNote(note) - utils.modified() + if note != self.source.getNote(): + self.source.setNote(note) + utils.modified() - utils.destroy_passed_object(edit.top) - edit.callback(edit.source) + utils.destroy_passed_object(self.top) + self.callback(self.source) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def on_switch_page(obj,a,page): - src = obj.get_data(SOURCE) - if page == 2 and src.not_loaded: - src.not_loaded = 0 - src.gallery.load_images() + def on_switch_page(self,obj,a,page): + if page == 2 and self.not_loaded: + self.not_loaded = 0 + self.gallery.load_images() diff --git a/gramps/src/Find.py b/gramps/src/Find.py index 0ea102219..c06986a8f 100644 --- a/gramps/src/Find.py +++ b/gramps/src/Find.py @@ -29,8 +29,6 @@ import utils import string import gtk -_OBJECT = "o" - class Find: """Opens find person dialog for gramps""" @@ -46,11 +44,10 @@ class Find: self.xml = libglade.GladeXML(const.gladeFile,"find") self.xml.signal_autoconnect({ "destroy_passed_object" : utils.destroy_passed_object, - "on_next_clicked" : on_next_clicked, - "on_prev_clicked" : on_prev_clicked, + "on_next_clicked" : self.on_next_clicked, + "on_prev_clicked" : self.on_prev_clicked, }) self.top = self.xml.get_widget("find") - self.top.set_data(_OBJECT,self) self.entry = self.xml.get_widget("entry1") self.top.editable_enters(self.entry) @@ -108,11 +105,10 @@ class Find: gtk.gdk_beep() + def on_next_clicked(self,obj): + """Callback for dialog box that causes the next person to be found""" + self.find_next() -def on_next_clicked(obj): - """Callback for dialog box that causes the next person to be found""" - obj.get_data(_OBJECT).find_next() - -def on_prev_clicked(obj): - """Callback for dialog box that causes the previous person to be found""" - obj.get_data(_OBJECT).find_prev() + def on_prev_clicked(self,obj): + """Callback for dialog box that causes the previous person to be found""" + self.find_prev() diff --git a/gramps/src/GrampsParser.py b/gramps/src/GrampsParser.py index dc53c3864..019f82e90 100644 --- a/gramps/src/GrampsParser.py +++ b/gramps/src/GrampsParser.py @@ -23,6 +23,7 @@ from RelLib import * import string import os import sys +import utils import gnome.mime #------------------------------------------------------------------------- diff --git a/gramps/src/LocEdit.py b/gramps/src/LocEdit.py new file mode 100644 index 000000000..d0b541fba --- /dev/null +++ b/gramps/src/LocEdit.py @@ -0,0 +1,126 @@ +# +# 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 +# + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import os +import string + +#------------------------------------------------------------------------- +# +# GTK/Gnome modules +# +#------------------------------------------------------------------------- +from gtk import * +from gnome.ui import * + +import libglade + +#------------------------------------------------------------------------- +# +# gramps modules +# +#------------------------------------------------------------------------- +import intl +import const +import utils +from RelLib import * + +_ = intl.gettext + +#------------------------------------------------------------------------- +# +# LocationEditor class +# +#------------------------------------------------------------------------- +class LocationEditor: + + def __init__(self,parent,location): + self.parent = parent + self.location = location + self.top = libglade.GladeXML(const.dialogFile, "loc_edit") + self.window = self.top.get_widget("loc_edit") + self.city = self.top.get_widget("city") + self.state = self.top.get_widget("state") + self.county = self.top.get_widget("county") + self.country = self.top.get_widget("country") + + # Typing CR selects OK button + self.window.editable_enters(self.city); + self.window.editable_enters(self.county); + self.window.editable_enters(self.state); + self.window.editable_enters(self.country); + + if parent.place: + name = _("Location Editor for %s") % parent.place.get_title() + else: + name = _("Location Editor") + + self.top.get_widget("locationTitle").set_text(name) + + if location != None: + self.city.set_text(location.get_city()) + self.county.set_text(location.get_county()) + self.country.set_text(location.get_country()) + self.state.set_text(location.get_state()) + + self.window.set_data("o",self) + self.top.signal_autoconnect({ + "destroy_passed_object" : utils.destroy_passed_object, + "on_loc_edit_ok_clicked" : self.on_location_edit_ok_clicked + }) + + def on_location_edit_ok_clicked(self,obj): + self.location = self.location + + city = self.city.get_text() + county = self.county.get_text() + country = self.country.get_text() + state = self.state.get_text() + + if self.location == None: + self.location = Location() + self.parent.llist.append(self.location) + + self.update_location(city,county,state,country) + + self.parent.redraw_location_list() + utils.destroy_passed_object(obj) + + def update_location(self,city,county,state,country): + if self.location.get_city() != city: + self.location.set_city(city) + self.parent.lists_changed = 1 + + if self.location.get_county() != county: + self.location.set_county(county) + self.parent.lists_changed = 1 + + if self.location.get_state() != state: + self.location.set_state(state) + self.parent.lists_changed = 1 + + if self.location.get_country() != country: + self.location.set_country(country) + self.parent.lists_changed = 1 + diff --git a/gramps/src/VersionControl.py b/gramps/src/VersionControl.py index 17a4b7b68..42d40c385 100644 --- a/gramps/src/VersionControl.py +++ b/gramps/src/VersionControl.py @@ -24,6 +24,10 @@ import os import string import shutil import intl +import libglade +import const +import utils + _ = intl.gettext try: @@ -38,6 +42,37 @@ _sep = '-' * 10 _end = "=" * 10 +class RevisionSelect: + + def __init__(self,db,filename,vc,load): + self.db = db + self.filename = filename + self.vc = vc + self.load = load + + dialog = libglade.GladeXML(const.gladeFile, "revselect") + revsel = dialog.get_widget("revselect") + dialog.signal_autoconnect({ + "destroy_passed_object" : utils.destroy_passed_object, + "on_loadrev_clicked" : self.on_loadrev_clicked, + }) + + self.revlist = dialog.get_widget("revlist") + l = self.vc.revision_list() + l.reverse() + index = 0 + for f in l: + self.revlist.append([f[0],f[1],f[2]]) + self.revlist.set_row_data(index,f[0]) + index = index + 1 + + def on_loadrev_clicked(self,obj): + if len(self.revlist.selection) > 0: + rev = self.revlist.get_row_data(self.revlist.selection[0]) + f = self.vc.get_version(rev) + self.load(f,self.filename,rev) + utils.destroy_passed_object(obj) + class VersionControl: """Base class for revision control systems""" def __init__(self,wd): diff --git a/gramps/src/WriteXML.py b/gramps/src/WriteXML.py index a141b817c..642f68723 100644 --- a/gramps/src/WriteXML.py +++ b/gramps/src/WriteXML.py @@ -56,7 +56,7 @@ def sortById(first,second): # #------------------------------------------------------------------------- def fix(line): - l = string.stripline) + l = string.stripline(line) l = string.replace(l,'&','&') l = string.replace(l,'>','>') l = string.replace(l,'<','<') diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index eea56dbcb..65be6c744 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -1119,49 +1119,12 @@ def on_ok_button1_clicked(obj): utils.destroy_passed_object(obj) if getoldrev.get_active(): - dialog = libglade.GladeXML(const.gladeFile, "revselect") - revsel = dialog.get_widget("revselect") - dialog.signal_autoconnect({ - "destroy_passed_object" : utils.destroy_passed_object, - "on_loadrev_clicked" : on_loadrev_clicked, - }) - revlist = dialog.get_widget("revlist") - revsel.set_data("o",revlist) vc = VersionControl.RcsVersionControl(filename) - l = vc.revision_list() - l.reverse() - index = 0 - for f in l: - revlist.append([f[0],f[1],f[2]]) - revlist.set_row_data(index,f[0]) - index = index + 1 - revlist.set_data("n",filename) + VersionControl.RevisionSelect(database,filename,vc,load_revision) else: if filename != "": read_file(filename) -def on_loadrev_clicked(obj): - clist = obj.get_data("o") - filename = clist.get_data("n") - if len(clist.selection) > 0: - rev = clist.get_row_data(clist.selection[0]) - vc = VersionControl.RcsVersionControl(filename) - f = vc.get_version(rev) - load_revision(f,filename,rev) - utils.destroy_passed_object(obj) - - active_person = None - for person in database.getPersonMap().values(): - if active_person == None: - active_person = person - lastname = person.getPrimaryName().getSurname() - if lastname and lastname not in const.surnames: - const.surnames.append(lastname) - - statusbar.set_progress(1.0) - full_update() - statusbar.set_progress(0.0) - #------------------------------------------------------------------------- # # @@ -3073,111 +3036,76 @@ def load_progress(value): # # #------------------------------------------------------------------------- -def load_database(name): +def post_load(name): global active_person - - filename = name + os.sep + const.indexFile + database.setSavePath(name) + res = database.getResearcher() + if res.getName() == "" and Config.owner.getName() != "": + database.setResearcher(Config.owner) + utils.modified() + + setup_bookmarks() + + mylist = database.getPersonEventTypes() + for type in mylist: + ntype = const.display_pevent(type) + if ntype not in const.personalEvents: + const.personalEvents.append(ntype) + + mylist = database.getFamilyEventTypes() + for type in mylist: + ntype = const.display_fevent(type) + if ntype not in const.marriageEvents: + const.marriageEvents.append(ntype) + + mylist = database.getPersonAttributeTypes() + for type in mylist: + ntype = const.display_pattr(type) + if ntype not in const.personalAttributes: + const.personalAttributes.append(ntype) + + mylist = database.getFamilyAttributeTypes() + for type in mylist: + if type not in const.familyAttributes: + const.familyAttributes.append(type) + + mylist = database.getFamilyRelationTypes() + for type in mylist: + if type not in const.familyRelations: + const.familyRelations.append(type) + + Config.save_last_file(name) + gtop.get_widget("filter").set_text("") + + person = database.getDefaultPerson() + if person: + active_person = person + return 1 + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def load_database(name): + + filename = "%s/%s" % (name,const.indexFile) if ReadXML.loadData(database,filename,load_progress) == 0: return 0 + return post_load(name) - database.setSavePath(name) - - res = database.getResearcher() - if res.getName() == "" and Config.owner.getName() != "": - database.setResearcher(Config.owner) - utils.modified() - - setup_bookmarks() - - mylist = database.getPersonEventTypes() - for type in mylist: - ntype = const.display_pevent(type) - if ntype not in const.personalEvents: - const.personalEvents.append(ntype) - - mylist = database.getFamilyEventTypes() - for type in mylist: - ntype = const.display_fevent(type) - if ntype not in const.marriageEvents: - const.marriageEvents.append(ntype) - - mylist = database.getPersonAttributeTypes() - for type in mylist: - ntype = const.display_pattr(type) - if ntype not in const.personalAttributes: - const.personalAttributes.append(ntype) - - mylist = database.getFamilyAttributeTypes() - for type in mylist: - if type not in const.familyAttributes: - const.familyAttributes.append(type) - - mylist = database.getFamilyRelationTypes() - for type in mylist: - if type not in const.familyRelations: - const.familyRelations.append(type) - - Config.save_last_file(name) - gtop.get_widget("filter").set_text("") - - person = database.getDefaultPerson() - if person: - active_person = person - return 1 - +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- def load_revision(f,name,revision): - global active_person - - filename = name + os.sep + const.indexFile - if ReadXML.loadRevision(database,f,filename, revision,load_progress) == 0: + filename = "%s/%s" % (name,const.indexFile) + if ReadXML.loadRevision(database,f,filename,revision,load_progress) == 0: return 0 - - database.setSavePath(name) - - res = database.getResearcher() - if res.getName() == "" and Config.owner.getName() != "": - database.setResearcher(Config.owner) - utils.modified() - - setup_bookmarks() - - mylist = database.getPersonEventTypes() - for type in mylist: - ntype = const.display_pevent(type) - if ntype not in const.personalEvents: - const.personalEvents.append(ntype) - - mylist = database.getFamilyEventTypes() - for type in mylist: - ntype = const.display_fevent(type) - if ntype not in const.marriageEvents: - const.marriageEvents.append(ntype) - - mylist = database.getPersonAttributeTypes() - for type in mylist: - ntype = const.display_pattr(type) - if ntype not in const.personalAttributes: - const.personalAttributes.append(ntype) - - mylist = database.getFamilyAttributeTypes() - for type in mylist: - if type not in const.familyAttributes: - const.familyAttributes.append(type) - - mylist = database.getFamilyRelationTypes() - for type in mylist: - if type not in const.familyRelations: - const.familyRelations.append(type) - - Config.save_last_file(name) - gtop.get_widget("filter").set_text("") - - person = database.getDefaultPerson() - if person: - active_person = person - return 1 + return post_load(name) #------------------------------------------------------------------------- #