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 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
|
2004-03-22 10:11:35 +05:30
|
|
|
import DisplayModels
|
2004-04-11 08:07:13 +05:30
|
|
|
import const
|
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'),
|
2005-01-12 19:11:54 +05:30
|
|
|
_('ZIP/Postal Code'),
|
2004-03-22 10:11:35 +05:30
|
|
|
_('City'),
|
|
|
|
_('County'),
|
|
|
|
_('State'),
|
|
|
|
_('Country'),
|
|
|
|
_('Longitude'),
|
|
|
|
_('Latitude'),
|
2004-08-24 09:18:15 +05:30
|
|
|
_('Last Changed'),
|
2004-03-22 10:11:35 +05:30
|
|
|
]
|
|
|
|
|
2004-08-11 09:12:38 +05:30
|
|
|
_HANDLE_COL = len(column_names)
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PlaceView class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PlaceView:
|
|
|
|
|
2005-04-01 11:03:22 +05:30
|
|
|
def __init__(self,parent,db,glade):
|
2004-02-26 09:04:19 +05:30
|
|
|
self.parent = parent
|
2005-04-04 06:41:50 +05:30
|
|
|
self.parent.connect('database-changed',self.change_db)
|
|
|
|
|
2002-10-21 06:48:07 +05:30
|
|
|
self.glade = glade
|
|
|
|
self.list = glade.get_widget("place_list")
|
2004-03-30 10:20:24 +05:30
|
|
|
self.list.connect('button-press-event',self.button_press)
|
|
|
|
self.list.connect('key-press-event',self.key_press)
|
|
|
|
self.selection = self.list.get_selection()
|
|
|
|
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.renderer = gtk.CellRendererText()
|
2004-08-19 08:07:35 +05:30
|
|
|
self.model = DisplayModels.PlaceModel(self.parent.db)
|
2004-04-11 08:07:13 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.list.set_model(self.model)
|
2003-11-19 23:30:58 +05:30
|
|
|
self.topWindow = self.glade.get_widget("gramps")
|
2005-05-16 04:29:25 +05:30
|
|
|
self.sort_col = 0
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns = []
|
2005-04-01 11:03:22 +05:30
|
|
|
self.change_db(db)
|
2004-03-22 10:11:35 +05:30
|
|
|
|
2005-05-16 04:29:25 +05:30
|
|
|
def column_clicked(self,obj,data):
|
|
|
|
if self.sort_col != data:
|
|
|
|
order = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING
|
|
|
|
or self.columns[data].get_sort_indicator() == False):
|
|
|
|
order = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
order = gtk.SORT_DESCENDING
|
|
|
|
self.sort_col = data
|
|
|
|
handle = self.first_selected()
|
|
|
|
self.model = DisplayModels.PlaceModel(self.parent.db,
|
|
|
|
self.sort_col,order)
|
|
|
|
self.list.set_model(self.model)
|
2005-05-17 09:28:18 +05:30
|
|
|
|
|
|
|
colmap = self.parent.db.get_place_column_order()
|
|
|
|
|
2005-05-16 04:29:25 +05:30
|
|
|
if handle:
|
|
|
|
path = self.model.on_get_path(handle)
|
|
|
|
self.selection.select_path(path)
|
|
|
|
self.list.scroll_to_cell(path,None,1,0.5,0)
|
|
|
|
for i in range(0,len(self.columns)):
|
2005-05-17 09:28:18 +05:30
|
|
|
self.columns[i].set_sort_indicator(i==colmap[data][1]-1)
|
|
|
|
self.columns[self.sort_col].set_sort_order(order)
|
2005-05-16 04:29:25 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def build_columns(self):
|
|
|
|
for column in self.columns:
|
|
|
|
self.list.remove_column(column)
|
|
|
|
|
|
|
|
column = gtk.TreeViewColumn(_('Place Name'), self.renderer,text=0)
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_resizable(True)
|
2004-03-22 10:11:35 +05:30
|
|
|
column.set_min_width(225)
|
2005-05-16 04:29:25 +05:30
|
|
|
column.connect('clicked',self.column_clicked,0)
|
|
|
|
column.set_clickable(True)
|
2004-03-22 10:11:35 +05:30
|
|
|
self.list.append_column(column)
|
|
|
|
self.columns = [column]
|
|
|
|
|
2005-05-17 09:28:18 +05:30
|
|
|
index = 1
|
2004-03-22 10:11:35 +05:30
|
|
|
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])
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_resizable(True)
|
2004-03-22 10:11:35 +05:30
|
|
|
column.set_min_width(75)
|
2005-05-16 04:29:25 +05:30
|
|
|
column.set_clickable(True)
|
2005-05-17 09:28:18 +05:30
|
|
|
column.connect('clicked',self.column_clicked,index)
|
|
|
|
index += 1
|
2004-03-22 10:11:35 +05:30
|
|
|
self.columns.append(column)
|
|
|
|
self.list.append_column(column)
|
|
|
|
|
2005-04-01 11:03:22 +05:30
|
|
|
def place_add(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.add_row_by_handle(handle)
|
|
|
|
|
|
|
|
def place_update(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.update_row_by_handle(handle)
|
|
|
|
|
|
|
|
def place_delete(self,handle_list):
|
|
|
|
for handle in handle_list:
|
|
|
|
self.model.delete_row_by_handle(handle)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def change_db(self,db):
|
2005-04-02 01:34:12 +05:30
|
|
|
db.connect('place-add', self.place_add)
|
|
|
|
db.connect('place-update', self.place_update)
|
|
|
|
db.connect('place-delete', self.place_delete)
|
|
|
|
db.connect('place-rebuild',self.build_tree)
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
self.build_columns()
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
def build_tree(self):
|
2004-08-19 08:07:35 +05:30
|
|
|
self.model = 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()
|
2004-08-19 08:07:35 +05:30
|
|
|
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
|
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-08-27 09:11:57 +05:30
|
|
|
place = self.parent.db.get_place_from_handle(mlist[0])
|
2005-04-01 11:03:22 +05:30
|
|
|
EditPlace.EditPlace(self.parent,place,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()
|
2005-03-28 09:52:09 +05:30
|
|
|
menu.set_title(_('Place Menu'))
|
2003-10-18 21:20:16 +05:30
|
|
|
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
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def on_add_place_clicked(self,obj):
|
2005-04-01 11:03:22 +05:30
|
|
|
EditPlace.EditPlace(self.parent,RelLib.Place())
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-08-30 09:20:33 +05:30
|
|
|
def delete_place(self,place):
|
|
|
|
trans = self.parent.db.transaction_begin()
|
|
|
|
place_handle = place.get_handle()
|
|
|
|
self.parent.db.remove_place(place_handle,trans)
|
|
|
|
title_msg = _("Delete Place (%s)") % place.get_title()
|
|
|
|
self.parent.db.transaction_commit(trans,title_msg)
|
2005-04-04 05:57:06 +05:30
|
|
|
|
|
|
|
def is_used(self,place_handle):
|
|
|
|
for handle in self.parent.db.get_person_handles(sort_handles=False):
|
|
|
|
person = self.parent.db.get_person_from_handle(handle)
|
|
|
|
if person.has_handle_reference('Place',place_handle):
|
|
|
|
return True
|
|
|
|
|
|
|
|
for handle in self.parent.db.get_family_handles():
|
|
|
|
family = self.parent.db.get_family_from_handle(handle)
|
|
|
|
if family.has_handle_reference('Place',place_handle):
|
|
|
|
return True
|
|
|
|
|
|
|
|
for handle in self.parent.db.get_event_handles():
|
|
|
|
event = self.parent.db.get_event_from_handle(handle)
|
|
|
|
if event.has_handle_reference('Place',place_handle):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
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)
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-08-30 09:20:33 +05:30
|
|
|
for place_handle in mlist:
|
|
|
|
place = self.parent.db.get_place_from_handle(place_handle)
|
2005-04-04 05:57:06 +05:30
|
|
|
if self.is_used(place_handle):
|
2005-04-01 11:03:22 +05:30
|
|
|
ans = EditPlace.DeletePlaceQuery(place,self.parent.db)
|
|
|
|
QuestionDialog(
|
|
|
|
_('Delete %s?') % place.get_title(),
|
|
|
|
_('This place is currently being used by at least one '
|
|
|
|
'record in the database. Deleting it will remove it '
|
|
|
|
'from the database and remove it from all records '
|
|
|
|
'that reference it.'),
|
|
|
|
_('_Delete Place'),
|
|
|
|
ans.query_response)
|
2002-12-17 10:42:28 +05:30
|
|
|
else:
|
2004-08-30 09:20:33 +05:30
|
|
|
self.delete_place(place)
|
|
|
|
|
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)
|
|
|
|
|
2004-08-30 09:20:33 +05:30
|
|
|
for place_handle in mlist:
|
|
|
|
place = self.parent.db.get_place_from_handle(place_handle)
|
2005-04-01 11:03:22 +05:30
|
|
|
EditPlace.EditPlace(self.parent, place,self.topWindow)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-16 04:29:25 +05:30
|
|
|
def first_selected(self):
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
if mlist:
|
|
|
|
return mlist[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2002-12-14 10:37:09 +05:30
|
|
|
def blist(self,store,path,iter,list):
|
2004-08-27 09:11:57 +05:30
|
|
|
handle = store.get_value(iter,_HANDLE_COL)
|
2004-08-20 17:41:56 +05:30
|
|
|
list.append(handle)
|
2004-03-30 10:20:24 +05:30
|
|
|
|
|
|
|
def merge(self):
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.blist,mlist)
|
|
|
|
|
|
|
|
if len(mlist) != 2:
|
|
|
|
msg = _("Cannot merge places.")
|
|
|
|
msg2 = _("Exactly two places must be selected to perform a merge. "
|
|
|
|
"A second place can be selected by holding down the "
|
|
|
|
"control key while clicking on the desired place.")
|
|
|
|
ErrorDialog(msg,msg2)
|
|
|
|
else:
|
|
|
|
import MergeData
|
2004-08-11 09:12:38 +05:30
|
|
|
MergeData.MergePlaces(self.parent.db,mlist[0],mlist[1],self.build_tree)
|