2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-11 09:47:53 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-11-13 00:15:07 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-04-01 19:09:34 +05:30
|
|
|
import cPickle as pickle
|
2005-12-07 01:24:16 +05:30
|
|
|
import gc
|
2005-01-11 09:47:53 +05:30
|
|
|
from gettext import gettext as _
|
2005-12-22 17:32:06 +05:30
|
|
|
import sys
|
|
|
|
|
2006-01-09 16:58:44 +05:30
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import Sources
|
|
|
|
import ImageSelect
|
2005-01-01 09:57:15 +05:30
|
|
|
import NameDisplay
|
2005-09-16 09:37:53 +05:30
|
|
|
import DisplayState
|
2005-08-18 11:28:28 +05:30
|
|
|
import Spell
|
2005-12-07 01:24:16 +05:30
|
|
|
import GrampsDisplay
|
|
|
|
import RelLib
|
|
|
|
import ListModel
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-26 02:35:09 +05:30
|
|
|
from DdTargets import DdTargets
|
2005-12-07 01:24:16 +05:30
|
|
|
from WindowUtils import GladeIf
|
2006-02-06 00:30:25 +05:30
|
|
|
from DisplayTabs import *
|
2005-03-26 02:35:09 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# EditPlace
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-09-16 09:37:53 +05:30
|
|
|
class EditPlace(DisplayState.ManagedWindow):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-26 10:22:21 +05:30
|
|
|
def __init__(self,dbstate,uistate,track,place):
|
2005-08-12 08:05:27 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
2005-09-16 09:37:53 +05:30
|
|
|
|
|
|
|
self.ref_not_loaded = place and place.get_handle()
|
2005-12-07 01:24:16 +05:30
|
|
|
self.idle = None
|
2005-01-01 09:57:15 +05:30
|
|
|
self.name_display = NameDisplay.displayer.display
|
2002-10-20 19:55:16 +05:30
|
|
|
self.place = place
|
2005-09-16 09:37:53 +05:30
|
|
|
self.db = dbstate.db
|
|
|
|
self.path = dbstate.db.get_save_path()
|
|
|
|
self.not_loaded = True
|
2005-12-22 17:32:06 +05:30
|
|
|
self.model = None # becomes the model for back references.
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lists_changed = 0
|
|
|
|
|
2006-01-17 10:33:30 +05:30
|
|
|
self.top = gtk.glade.XML(const.gladeFile,"placeEditor","gramps")
|
2005-12-26 10:22:21 +05:30
|
|
|
self.gladeif = GladeIf(self.top)
|
2005-12-07 01:24:16 +05:30
|
|
|
|
2005-12-26 10:22:21 +05:30
|
|
|
self.window = self.top.get_widget("placeEditor")
|
|
|
|
title_label = self.top.get_widget('title')
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2005-12-26 10:22:21 +05:30
|
|
|
Utils.set_titles(self.window,title_label,_('Place Editor'))
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2005-08-12 08:05:27 +05:30
|
|
|
mode = not self.dbstate.db.readonly
|
2005-12-26 10:22:21 +05:30
|
|
|
self.title = self.top.get_widget("place_title")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.title.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.city = self.top.get_widget("city")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.city.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.parish = self.top.get_widget("parish")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.parish.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.county = self.top.get_widget("county")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.county.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.state = self.top.get_widget("state")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.state.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.phone = self.top.get_widget("phone")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.phone.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.postal = self.top.get_widget("postal")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.postal.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.country = self.top.get_widget("country")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.country.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.longitude = self.top.get_widget("longitude")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.longitude.set_editable(mode)
|
2005-12-26 10:22:21 +05:30
|
|
|
self.latitude = self.top.get_widget("latitude")
|
2005-02-20 06:32:15 +05:30
|
|
|
self.latitude.set_editable(mode)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-26 10:22:21 +05:30
|
|
|
self.top.get_widget('changed').set_text(place.get_change_display())
|
2004-08-24 09:18:15 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.title.set_text(place.get_title())
|
|
|
|
mloc = place.get_main_location()
|
|
|
|
self.city.set_text(mloc.get_city())
|
|
|
|
self.county.set_text(mloc.get_county())
|
|
|
|
self.state.set_text(mloc.get_state())
|
2003-12-09 11:30:51 +05:30
|
|
|
self.phone.set_text(mloc.get_phone())
|
|
|
|
self.postal.set_text(mloc.get_postal_code())
|
2002-10-20 19:55:16 +05:30
|
|
|
self.parish.set_text(mloc.get_parish())
|
|
|
|
self.country.set_text(mloc.get_country())
|
|
|
|
self.longitude.set_text(place.get_longitude())
|
|
|
|
self.latitude.set_text(place.get_latitude())
|
2005-12-26 10:22:21 +05:30
|
|
|
self.plist = self.top.get_widget("refinfo")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-02-06 00:30:25 +05:30
|
|
|
self.notebook = self.top.get_widget('notebook3')
|
2003-12-12 11:06:38 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
self.gladeif.connect('placeEditor', 'delete_event', self.on_delete_event)
|
|
|
|
self.gladeif.connect('button127', 'clicked', self.close)
|
|
|
|
self.gladeif.connect('ok', 'clicked', self.on_place_apply_clicked)
|
|
|
|
self.gladeif.connect('button135', 'clicked', self.on_help_clicked)
|
2005-12-26 10:22:21 +05:30
|
|
|
|
|
|
|
DisplayState.ManagedWindow.__init__(self, uistate, track, place)
|
2005-12-07 01:24:16 +05:30
|
|
|
|
2005-08-12 08:05:27 +05:30
|
|
|
if self.place.get_handle() == None or self.dbstate.db.readonly:
|
2005-12-26 10:22:21 +05:30
|
|
|
self.top.get_widget("add_photo").set_sensitive(0)
|
|
|
|
self.top.get_widget("delete_photo").set_sensitive(0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-26 10:22:21 +05:30
|
|
|
self.top.get_widget('ok').set_sensitive(not self.db.readonly)
|
2005-09-16 09:37:53 +05:30
|
|
|
|
2006-02-06 00:30:25 +05:30
|
|
|
self._create_tabbed_pages()
|
|
|
|
self.show()
|
2005-09-16 09:37:53 +05:30
|
|
|
|
2005-07-09 01:54:54 +05:30
|
|
|
self.pdmap = {}
|
|
|
|
self.build_pdmap()
|
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
|
2005-12-23 05:13:32 +05:30
|
|
|
def build_window_key(self,place):
|
|
|
|
if place:
|
|
|
|
return place.get_handle()
|
|
|
|
else:
|
2005-12-24 01:39:02 +05:30
|
|
|
return id(self)
|
2005-12-23 05:13:32 +05:30
|
|
|
|
|
|
|
def build_menu_names(self,place):
|
|
|
|
win_menu_label = place.get_title()
|
|
|
|
if not win_menu_label.strip():
|
|
|
|
win_menu_label = _("New Place")
|
|
|
|
return (win_menu_label, _('Edit Place'))
|
|
|
|
|
2005-07-09 01:54:54 +05:30
|
|
|
def build_pdmap(self):
|
|
|
|
self.pdmap.clear()
|
|
|
|
cursor = self.db.get_place_cursor()
|
|
|
|
data = cursor.next()
|
|
|
|
while data:
|
|
|
|
if data[1][2]:
|
|
|
|
self.pdmap[data[1][2]] = data[0]
|
|
|
|
data = cursor.next()
|
|
|
|
cursor.close()
|
|
|
|
|
2006-02-06 00:30:25 +05:30
|
|
|
def _add_page(self,page):
|
|
|
|
self.notebook.insert_page(page)
|
|
|
|
self.notebook.set_tab_label(page,page.get_tab_widget())
|
|
|
|
return page
|
|
|
|
|
|
|
|
def _create_tabbed_pages(self):
|
|
|
|
"""
|
|
|
|
Creates the notebook tabs and inserts them into the main
|
|
|
|
window.
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.loc_list = self._add_page(LocationEmbedList(
|
|
|
|
self.dbstate,self.uistate, self.track,
|
|
|
|
self.place.alt_loc))
|
|
|
|
self.srcref_list = self._add_page(SourceEmbedList(
|
|
|
|
self.dbstate,self.uistate, self.track,
|
|
|
|
self.place.source_list))
|
|
|
|
self.note_tab = self._add_page(NoteTab(
|
|
|
|
self.dbstate, self.uistate, self.track,
|
|
|
|
self.place.get_note_object()))
|
|
|
|
self.gallery_tab = self._add_page(GalleryTab(
|
|
|
|
self.dbstate, self.uistate, self.track,
|
|
|
|
self.place.get_media_list()))
|
|
|
|
self.web_list = self._add_page(WebEmbedList(
|
|
|
|
self.dbstate,self.uistate,self.track,
|
|
|
|
self.place.get_url_list()))
|
|
|
|
self.backref_list = self._add_page(SourceBackRefList(
|
|
|
|
self.dbstate,self.uistate,self.track,
|
|
|
|
self.db.find_backlink_handles(self.place.handle)))
|
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
def on_delete_event(self,obj,b):
|
2005-12-07 01:24:16 +05:30
|
|
|
self.gladeif.close()
|
2006-02-06 00:30:25 +05:30
|
|
|
self.close()
|
2004-02-26 09:04:19 +05:30
|
|
|
|
2006-02-06 00:30:25 +05:30
|
|
|
def close_window(self,obj):
|
2005-12-07 01:24:16 +05:30
|
|
|
self.gladeif.close()
|
2006-02-06 00:30:25 +05:30
|
|
|
self.close()
|
2005-12-26 10:22:21 +05:30
|
|
|
self.window.destroy()
|
2005-12-07 01:24:16 +05:30
|
|
|
if self.idle != None:
|
|
|
|
gobject.source_remove(self.idle)
|
2003-11-19 23:30:58 +05:30
|
|
|
|
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2005-12-07 01:24:16 +05:30
|
|
|
GrampsDisplay.help('adv-plc')
|
2003-11-19 23:30:58 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def build_columns(self,tree,list):
|
|
|
|
cnum = 0
|
|
|
|
for name in list:
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
|
|
|
|
column.set_min_width(name[1])
|
|
|
|
cnum = cnum + 1
|
|
|
|
tree.append_column(column)
|
|
|
|
|
|
|
|
def set(self,field,getf,setf):
|
2003-12-17 10:53:16 +05:30
|
|
|
text = unicode(field.get_text())
|
2002-10-20 19:55:16 +05:30
|
|
|
if text != getf():
|
|
|
|
setf(text)
|
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
def on_place_apply_clicked(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
mloc = self.place.get_main_location()
|
2005-07-09 01:54:54 +05:30
|
|
|
title = self.title.get_text()
|
|
|
|
if self.pdmap.has_key(title) and self.pdmap[title] != self.place.handle:
|
|
|
|
import QuestionDialog
|
2006-02-06 00:30:25 +05:30
|
|
|
QuestionDialog.ErrorDialog(
|
|
|
|
_("Place title is already in use"),
|
|
|
|
_("Each place must have a unique title, and "
|
|
|
|
"title you have selected is already used by "
|
|
|
|
"another place"))
|
2005-07-09 01:54:54 +05:30
|
|
|
return
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.set(self.city,mloc.get_city,mloc.set_city)
|
|
|
|
self.set(self.parish,mloc.get_parish,mloc.set_parish)
|
|
|
|
self.set(self.state,mloc.get_state,mloc.set_state)
|
2003-12-09 11:30:51 +05:30
|
|
|
self.set(self.phone,mloc.get_phone,mloc.set_phone)
|
|
|
|
self.set(self.postal,mloc.get_postal_code,mloc.set_postal_code)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.set(self.county,mloc.get_county,mloc.set_county)
|
|
|
|
self.set(self.country,mloc.get_country,mloc.set_country)
|
|
|
|
self.set(self.title,self.place.get_title,self.place.set_title)
|
|
|
|
self.set(self.longitude,self.place.get_longitude,
|
|
|
|
self.place.set_longitude)
|
|
|
|
self.set(self.latitude,self.place.get_latitude,
|
|
|
|
self.place.set_latitude)
|
|
|
|
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2004-08-30 09:20:33 +05:30
|
|
|
if self.place.get_handle():
|
|
|
|
self.db.commit_place(self.place,trans)
|
|
|
|
else:
|
|
|
|
self.db.add_place(self.place,trans)
|
2005-04-01 11:03:22 +05:30
|
|
|
self.db.transaction_commit(trans,
|
|
|
|
_("Edit Place (%s)") % self.place.get_title())
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
self.close(obj)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DeletePlaceQuery
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DeletePlaceQuery:
|
|
|
|
|
2005-04-01 11:03:22 +05:30
|
|
|
def __init__(self,place,db):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
|
|
|
self.place = place
|
|
|
|
|
|
|
|
def query_response(self):
|
2004-08-13 10:04:07 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2005-06-05 09:31:56 +05:30
|
|
|
self.db.disable_signals()
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2005-04-04 05:57:06 +05:30
|
|
|
place_handle = self.place.get_handle()
|
|
|
|
|
|
|
|
for handle in self.db.get_person_handles(sort_handles=False):
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
|
|
|
if person.has_handle_reference('Place',place_handle):
|
|
|
|
person.remove_handle_references('Place',place_handle)
|
|
|
|
self.db.commit_person(person,trans)
|
|
|
|
|
|
|
|
for handle in self.db.get_family_handles():
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
|
|
|
if family.has_handle_reference('Place',place_handle):
|
|
|
|
family.remove_handle_references('Place',place_handle)
|
|
|
|
self.db.commit_family(family,trans)
|
|
|
|
|
|
|
|
for handle in self.db.get_event_handles():
|
|
|
|
event = self.db.get_event_from_handle(handle)
|
|
|
|
if event.has_handle_reference('Place',place_handle):
|
|
|
|
event.remove_handle_references('Place',place_handle)
|
|
|
|
self.db.commit_event(event,trans)
|
2002-10-21 06:48:07 +05:30
|
|
|
|
2005-06-05 09:31:56 +05:30
|
|
|
self.db.enable_signals()
|
|
|
|
self.db.remove_place(place_handle,trans)
|
2005-04-01 11:03:22 +05:30
|
|
|
self.db.transaction_commit(trans,
|
|
|
|
_("Delete Place (%s)") % self.place.get_title())
|