gramps/gramps2/src/PlaceView.py

261 lines
9.3 KiB
Python
Raw Normal View History

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
#
# $Id$
2002-10-20 19:55:16 +05:30
"""
Handles the place view for GRAMPS.
"""
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.gdk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
import RelLib
2002-10-20 19:55:16 +05:30
import EditPlace
import DisplayModels
import const
2002-10-20 19:55:16 +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
column_names = [
_('Place Name'),
_('ID'),
_('Church Parish'),
_('ZIP/Postal Code'),
_('City'),
_('County'),
_('State'),
_('Country'),
_('Longitude'),
_('Latitude'),
_('Last Changed'),
]
_HANDLE_COL = len(column_names)
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# PlaceView class
#
#-------------------------------------------------------------------------
class PlaceView:
def __init__(self,parent,db,glade,update):
self.parent = parent
2002-10-21 06:48:07 +05:30
self.glade = glade
self.list = glade.get_widget("place_list")
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)
2002-10-20 19:55:16 +05:30
self.renderer = gtk.CellRendererText()
2003-03-26 08:02:58 +05:30
self.model = DisplayModels.PlaceModel(self.parent.db)
2002-10-20 19:55:16 +05:30
self.list.set_model(self.model)
self.topWindow = self.glade.get_widget("gramps")
2003-05-08 23:08:49 +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(True)
column.set_min_width(225)
self.list.append_column(column)
self.columns = [column]
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(True)
column.set_min_width(75)
self.columns.append(column)
self.list.append_column(column)
2002-10-20 19:55:16 +05:30
def change_db(self,db):
self.build_columns()
self.build_tree()
def build_tree(self):
self.model = DisplayModels.PlaceModel(self.parent.db)
self.list.set_model(self.model)
self.selection = self.list.get_selection()
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:
mlist = []
self.selection.selected_foreach(self.blist,mlist)
if mlist:
place = self.parent.db.get_place_from_handle(mlist[0])
EditPlace.EditPlace(self.parent,place,self.update_display,
self.topWindow)
2002-10-20 19:55:16 +05:30
return 1
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
self.build_context_menu(event)
return 1
return 0
2002-10-20 19:55:16 +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
def build_context_menu(self,event):
"""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)
menu.popup(None,None,None,event.button,event.time)
def on_add_place_clicked(self,obj):
EditPlace.EditPlace(self.parent,RelLib.Place(),self.new_place_after_edit)
2002-10-20 19:55:16 +05:30
def new_place_after_edit(self,place):
self.model.add_row_by_handle(place.get_handle())
2002-10-20 19:55:16 +05:30
def update_display(self,place):
self.model.update_row_by_handle(place.get_handle())
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)
self.model.delete_row_by_handle(place_handle)
2002-10-20 19:55:16 +05:30
def on_delete_clicked(self,obj):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
for place_handle in mlist:
used = 0
for key in self.parent.db.get_person_handles(sort_handles=False):
p = self.parent.db.get_person_from_handle(key)
event_list = []
for e in [p.get_birth_handle(),p.get_death_handle()] + p.get_event_list():
event = self.parent.db.get_event_from_handle(e)
if event:
event_list.append(event)
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())
for event in event_list:
if event:
if event.get_place_handle() == place_handle:
used = 1
for fid in self.parent.db.get_family_handles():
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
f = self.parent.db.get_family_from_handle(fid)
event_list = []
for event_id in f.get_event_list():
event = self.parent.db.get_event_from_handle(event_id)
if event:
event_list.append(event)
if f.get_lds_sealing():
event_list.append(f.get_lds_sealing())
for event in event_list:
if event.get_place_handle() == place_handle:
used = 1
place = self.parent.db.get_place_from_handle(place_handle)
if used == 1:
ans = EditPlace.DeletePlaceQuery(place,self.parent.db,
self.model.delete_row_by_handle)
QuestionDialog(_('Delete %s?') % place.get_title(),
_('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 '
'that reference it.'),
2003-03-23 09:20:59 +05:30
_('_Delete Place'),
ans.query_response)
else:
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"""
mlist = []
self.selection.selected_foreach(self.blist,mlist)
for place_handle in mlist:
place = self.parent.db.get_place_from_handle(place_handle)
EditPlace.EditPlace(self.parent, place, self.update_display)
2002-10-20 19:55:16 +05:30
def blist(self,store,path,iter,list):
handle = store.get_value(iter,_HANDLE_COL)
list.append(handle)
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
MergeData.MergePlaces(self.parent.db,mlist[0],mlist[1],self.build_tree)