2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-01-13 00:26:24 +05:30
|
|
|
# Copyright (C) 2001-2004 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-10-18 21:20:16 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Handles the place view for GRAMPS.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import gtk.gdk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-01-10 10:51:32 +05:30
|
|
|
import RelLib
|
2002-10-20 19:55:16 +05:30
|
|
|
import EditPlace
|
|
|
|
import Utils
|
2004-03-22 10:11:35 +05:30
|
|
|
import DisplayModels
|
|
|
|
import ColumnOrder
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
from QuestionDialog import QuestionDialog, ErrorDialog
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
column_names = [
|
|
|
|
_('Place Name'),
|
|
|
|
_('ID'),
|
|
|
|
_('Church Parish'),
|
|
|
|
_('City'),
|
|
|
|
_('County'),
|
|
|
|
_('State'),
|
|
|
|
_('Country'),
|
|
|
|
_('Longitude'),
|
|
|
|
_('Latitude'),
|
|
|
|
]
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PlaceView class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PlaceView:
|
|
|
|
|
2004-02-26 09:04:19 +05:30
|
|
|
def __init__(self,parent,db,glade,update):
|
|
|
|
self.parent = parent
|
2002-10-21 06:48:07 +05:30
|
|
|
self.db = db
|
|
|
|
self.glade = glade
|
|
|
|
self.list = glade.get_widget("place_list")
|
|
|
|
self.update = update
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
self.renderer = gtk.CellRendererText()
|
2003-03-26 08:02:58 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.active = None
|
|
|
|
|
2004-03-23 10:31:19 +05:30
|
|
|
self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.db))
|
2002-10-20 19:55:16 +05:30
|
|
|
self.list.set_model(self.model)
|
2003-04-04 11:18:25 +05:30
|
|
|
self.selection = self.list.get_selection()
|
2004-03-22 10:11:35 +05:30
|
|
|
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
2003-05-08 23:08:49 +05:30
|
|
|
self.list.connect('button-press-event',self.button_press)
|
2004-02-15 08:54:12 +05:30
|
|
|
self.list.connect('key-press-event',self.key_press)
|
2003-11-19 23:30:58 +05:30
|
|
|
self.topWindow = self.glade.get_widget("gramps")
|
2003-05-08 23:08:49 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns = []
|
|
|
|
self.build_columns()
|
|
|
|
|
|
|
|
def build_columns(self):
|
|
|
|
for column in self.columns:
|
|
|
|
self.list.remove_column(column)
|
|
|
|
|
|
|
|
column = gtk.TreeViewColumn(_('Place Name'), self.renderer,text=0)
|
|
|
|
column.set_resizable(gtk.TRUE)
|
2004-03-23 10:31:19 +05:30
|
|
|
column.set_clickable(gtk.TRUE)
|
2004-03-22 10:11:35 +05:30
|
|
|
column.set_min_width(225)
|
2004-03-23 10:31:19 +05:30
|
|
|
column.set_sort_column_id(0)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.list.append_column(column)
|
|
|
|
self.columns = [column]
|
|
|
|
|
|
|
|
index = 1
|
|
|
|
for pair in self.parent.db.get_place_column_order():
|
|
|
|
if not pair[0]:
|
|
|
|
continue
|
|
|
|
name = column_names[pair[1]]
|
|
|
|
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
|
|
|
|
column.set_resizable(gtk.TRUE)
|
|
|
|
column.set_clickable(gtk.TRUE)
|
|
|
|
column.set_min_width(75)
|
2004-03-23 10:31:19 +05:30
|
|
|
column.set_sort_column_id(index)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns.append(column)
|
|
|
|
self.list.append_column(column)
|
|
|
|
index += 1
|
|
|
|
|
2004-02-01 10:19:49 +05:30
|
|
|
def on_click(self,column):
|
|
|
|
self.click_col = column
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def change_db(self,db):
|
2004-03-22 10:11:35 +05:30
|
|
|
self.build_columns()
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
def build_tree(self):
|
|
|
|
self.list.set_model(None)
|
2004-03-23 10:31:19 +05:30
|
|
|
self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.parent.db))
|
2004-03-22 10:11:35 +05:30
|
|
|
self.list.set_model(self.model)
|
|
|
|
self.selection = self.list.get_selection()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def load_places(self,id=None):
|
|
|
|
"""Rebuilds the entire place view. This can be very time consuming
|
|
|
|
on large databases, and should only be called when absolutely
|
|
|
|
necessary"""
|
2004-03-22 10:11:35 +05:30
|
|
|
pass
|
|
|
|
#self.build_tree()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-04-04 11:18:25 +05:30
|
|
|
def goto(self,id):
|
|
|
|
self.selection.unselect_all()
|
2003-11-06 00:27:47 +05:30
|
|
|
iter = self.id2col[id]
|
|
|
|
self.selection.select_iter(iter)
|
|
|
|
itpath = self.model.get_path (iter)
|
|
|
|
col = self.list.get_column (0)
|
|
|
|
self.list.scroll_to_cell (itpath, col, gtk.TRUE, 0.5, 0)
|
2002-12-14 10:37:09 +05:30
|
|
|
|
2003-04-04 11:18:25 +05:30
|
|
|
def merge(self):
|
2002-12-14 10:37:09 +05:30
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
|
|
|
|
if len(mlist) != 2:
|
2003-08-25 19:30:26 +05:30
|
|
|
msg = _("Cannot merge places.")
|
2003-08-26 00:03:52 +05:30
|
|
|
msg2 = _("Exactly two places must be selected to perform a merge. "
|
|
|
|
"A second place can be selected by holding down the "
|
2003-09-30 09:49:35 +05:30
|
|
|
"control key while clicking on the desired place.")
|
2003-02-24 10:21:57 +05:30
|
|
|
ErrorDialog(msg,msg2)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
import MergeData
|
2002-12-14 10:37:09 +05:30
|
|
|
MergeData.MergePlaces(self.db,mlist[0],mlist[1],self.load_places)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def button_press(self,obj,event):
|
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
2002-12-17 10:42:28 +05:30
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
if mlist:
|
2004-02-26 09:04:19 +05:30
|
|
|
EditPlace.EditPlace(self.parent,mlist[0],self.update_display,self.topWindow)
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
2003-10-18 21:20:16 +05:30
|
|
|
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
2003-10-20 08:17:03 +05:30
|
|
|
self.build_context_menu(event)
|
2003-10-18 21:20:16 +05:30
|
|
|
return 1
|
2003-01-10 10:51:32 +05:30
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-15 08:54:12 +05:30
|
|
|
def key_press(self,obj,event):
|
|
|
|
if event.keyval == gtk.gdk.keyval_from_name("Return") \
|
|
|
|
and not event.state:
|
|
|
|
self.on_edit_clicked(obj)
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2003-10-20 08:17:03 +05:30
|
|
|
def build_context_menu(self,event):
|
2003-10-18 21:20:16 +05:30
|
|
|
"""Builds the menu with editing operations on the place's list"""
|
|
|
|
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
if mlist:
|
|
|
|
sel_sensitivity = 1
|
|
|
|
else:
|
|
|
|
sel_sensitivity = 0
|
|
|
|
entries = [
|
|
|
|
(gtk.STOCK_ADD, self.on_add_place_clicked,1),
|
|
|
|
(gtk.STOCK_REMOVE, self.on_delete_clicked,sel_sensitivity),
|
|
|
|
(_("Edit"), self.on_edit_clicked,sel_sensitivity),
|
|
|
|
]
|
|
|
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.set_title(_('Source Menu'))
|
|
|
|
for stock_id,callback,sensitivity in entries:
|
|
|
|
item = gtk.ImageMenuItem(stock_id)
|
|
|
|
if callback:
|
|
|
|
item.connect("activate",callback)
|
|
|
|
item.set_sensitive(sensitivity)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
2003-10-20 08:17:03 +05:30
|
|
|
menu.popup(None,None,None,event.button,event.time)
|
2003-10-18 21:20:16 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def new_place_after_edit(self,place):
|
2004-02-14 11:10:30 +05:30
|
|
|
self.db.add_place(place)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.update(0)
|
|
|
|
|
|
|
|
def update_display(self,place):
|
2002-10-21 06:48:07 +05:30
|
|
|
if place:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.db.build_place_display(place.get_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
self.update(0)
|
|
|
|
|
|
|
|
def on_add_place_clicked(self,obj):
|
2004-02-26 09:04:19 +05:30
|
|
|
EditPlace.EditPlace(self.parent,RelLib.Place(),self.new_place_after_edit)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_delete_clicked(self,obj):
|
2002-12-17 10:42:28 +05:30
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
|
|
|
|
for place in mlist:
|
2003-06-28 03:31:59 +05:30
|
|
|
used = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
for key in self.db.get_person_keys():
|
|
|
|
p = self.db.get_person(key)
|
2004-02-27 09:37:23 +05:30
|
|
|
event_list = []
|
|
|
|
for e in [p.get_birth_id(),p.get_death_id()] + p.get_event_list():
|
|
|
|
event = self.db.find_event_from_id(e)
|
|
|
|
if event:
|
|
|
|
event_list.append(event)
|
2004-02-14 11:10:30 +05:30
|
|
|
if p.get_lds_baptism():
|
|
|
|
event_list.append(p.get_lds_baptism())
|
|
|
|
if p.get_lds_endowment():
|
|
|
|
event_list.append(p.get_lds_endowment())
|
|
|
|
if p.get_lds_sealing():
|
|
|
|
event_list.append(p.get_lds_sealing())
|
2002-12-17 10:42:28 +05:30
|
|
|
for event in event_list:
|
2004-02-14 11:10:30 +05:30
|
|
|
if event.get_place_id() == place:
|
2002-12-17 10:42:28 +05:30
|
|
|
used = 1
|
|
|
|
|
2004-02-27 09:37:23 +05:30
|
|
|
for fid in self.db.get_family_keys():
|
|
|
|
f = self.db.find_family_from_id(fid)
|
|
|
|
event_list = []
|
|
|
|
for e in f.get_event_list():
|
|
|
|
event = self.db.find_event_from_id(e)
|
|
|
|
if event:
|
|
|
|
event_list.append(event)
|
2004-02-14 11:10:30 +05:30
|
|
|
if f.get_lds_sealing():
|
|
|
|
event_list.append(f.get_lds_sealing())
|
2002-12-17 10:42:28 +05:30
|
|
|
for event in event_list:
|
2004-02-14 11:10:30 +05:30
|
|
|
if event.get_place_id() == place:
|
2002-12-17 10:42:28 +05:30
|
|
|
used = 1
|
|
|
|
|
|
|
|
if used == 1:
|
|
|
|
ans = EditPlace.DeletePlaceQuery(place,self.db,self.update_display)
|
2003-07-17 08:07:28 +05:30
|
|
|
QuestionDialog(_('Delete %s?') % place.get_title(),
|
2003-04-10 01:19:11 +05:30
|
|
|
_('This place is currently being used by at least one '
|
2003-02-24 10:21:57 +05:30
|
|
|
'record in the database. Deleting it will remove it '
|
|
|
|
'from the database and remove it from all records '
|
2003-03-14 00:28:52 +05:30
|
|
|
'that reference it.'),
|
2003-03-23 09:20:59 +05:30
|
|
|
_('_Delete Place'),
|
2002-12-17 10:42:28 +05:30
|
|
|
ans.query_response)
|
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.db.remove_place(place.get_id())
|
2002-12-17 10:42:28 +05:30
|
|
|
self.update(0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_edit_clicked(self,obj):
|
|
|
|
"""Display the selected places in the EditPlace display"""
|
2002-12-17 10:42:28 +05:30
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
|
|
|
|
for place in mlist:
|
2004-02-26 09:04:19 +05:30
|
|
|
EditPlace.EditPlace(self.parent, place, self.update_display)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-12-14 10:37:09 +05:30
|
|
|
def blist(self,store,path,iter,list):
|
2004-02-14 11:10:30 +05:30
|
|
|
id = self.db.get_place_id(store.get_value(iter,1))
|
2002-12-14 10:37:09 +05:30
|
|
|
list.append(id)
|