2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-09-14 02:12:57 +05:30
|
|
|
# Copyright (C) 2000-2003 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
|
|
|
|
#
|
|
|
|
"""
|
|
|
|
The AddrEdit module provides the AddressEditor class. This provides a
|
|
|
|
mechanism for the user to edit address information.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import Date
|
|
|
|
import RelLib
|
|
|
|
import Sources
|
|
|
|
|
|
|
|
from DateEdit import DateEdit
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# AddressEditor class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class AddressEditor:
|
|
|
|
"""
|
|
|
|
Displays a dialog that allows the user to edit an address.
|
|
|
|
"""
|
2003-06-11 08:56:02 +05:30
|
|
|
def __init__(self,parent,addr,callback):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Displays the dialog box.
|
|
|
|
|
|
|
|
parent - The class that called the Address editor.
|
|
|
|
addr - The address that is to be edited
|
|
|
|
"""
|
|
|
|
# Get the important widgets from the glade description
|
2003-08-17 07:44:33 +05:30
|
|
|
self.top = gtk.glade.XML(const.dialogFile, "addr_edit","gramps")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.window = self.top.get_widget("addr_edit")
|
|
|
|
self.addr_start = self.top.get_widget("address_start")
|
|
|
|
self.street = self.top.get_widget("street")
|
|
|
|
self.city = self.top.get_widget("city")
|
|
|
|
self.state = self.top.get_widget("state")
|
|
|
|
self.country = self.top.get_widget("country")
|
|
|
|
self.postal = self.top.get_widget("postal")
|
|
|
|
self.note_field = self.top.get_widget("addr_note")
|
|
|
|
self.priv = self.top.get_widget("priv")
|
|
|
|
self.slist = self.top.get_widget("slist")
|
|
|
|
|
|
|
|
self.parent = parent
|
|
|
|
self.addr = addr
|
2003-06-11 08:56:02 +05:30
|
|
|
self.callback = callback
|
2002-10-20 19:55:16 +05:30
|
|
|
name = parent.person.getPrimaryName().getName()
|
2003-06-03 08:24:56 +05:30
|
|
|
if name == ", ":
|
|
|
|
text = _("Address Editor")
|
|
|
|
else:
|
|
|
|
text = _("Address Editor for %s") % name
|
2003-03-05 11:31:31 +05:30
|
|
|
|
|
|
|
title_label = self.top.get_widget("title")
|
2003-03-06 11:42:51 +05:30
|
|
|
|
|
|
|
Utils.set_titles(self.window,title_label,
|
|
|
|
text,_('Address Editor'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if self.addr:
|
|
|
|
self.srcreflist = self.addr.getSourceRefList()
|
|
|
|
self.addr_start.set_text(self.addr.getDate())
|
|
|
|
self.street.set_text(self.addr.getStreet())
|
|
|
|
self.city.set_text(self.addr.getCity())
|
|
|
|
self.state.set_text(self.addr.getState())
|
|
|
|
self.country.set_text(self.addr.getCountry())
|
|
|
|
self.postal.set_text(self.addr.getPostal())
|
|
|
|
self.priv.set_active(self.addr.getPrivacy())
|
2002-11-21 10:11:40 +05:30
|
|
|
self.note_field.get_buffer().set_text(self.addr.getNote())
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.srcreflist = []
|
|
|
|
|
|
|
|
self.sourcetab = Sources.SourceTab(self.srcreflist,self.parent,
|
2003-09-14 02:12:57 +05:30
|
|
|
self.top, self.window, self.slist,
|
2002-11-21 10:11:40 +05:30
|
|
|
self.top.get_widget('add_src'),
|
2003-03-03 10:02:53 +05:30
|
|
|
self.top.get_widget('edit_src'),
|
2002-11-21 10:11:40 +05:30
|
|
|
self.top.get_widget('del_src'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
date_stat = self.top.get_widget("date_stat")
|
|
|
|
self.date_check = DateEdit(self.addr_start,date_stat)
|
|
|
|
|
|
|
|
self.top.signal_autoconnect({
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object,
|
|
|
|
"on_addr_edit_ok_clicked" : self.ok_clicked,
|
|
|
|
})
|
|
|
|
|
|
|
|
def ok_clicked(self,obj):
|
|
|
|
"""
|
|
|
|
Called when the OK button is pressed. Gets data from the
|
|
|
|
form and updates the Address data structure.
|
|
|
|
"""
|
|
|
|
date = self.addr_start.get_text()
|
|
|
|
street = self.street.get_text()
|
|
|
|
city = self.city.get_text()
|
|
|
|
state = self.state.get_text()
|
|
|
|
country = self.country.get_text()
|
|
|
|
postal = self.postal.get_text()
|
2002-11-21 10:11:40 +05:30
|
|
|
b = self.note_field.get_buffer()
|
|
|
|
note = b.get_text(b.get_start_iter(),b.get_end_iter(),gtk.FALSE)
|
2002-10-20 19:55:16 +05:30
|
|
|
priv = self.priv.get_active()
|
|
|
|
|
|
|
|
if self.addr == None:
|
|
|
|
self.addr = RelLib.Address()
|
|
|
|
self.parent.plist.append(self.addr)
|
|
|
|
self.addr.setSourceRefList(self.srcreflist)
|
2002-11-21 10:11:40 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.update(date,street,city,state,country,postal,note,priv)
|
2003-06-11 08:56:02 +05:30
|
|
|
self.callback(self.addr)
|
2002-10-20 19:55:16 +05:30
|
|
|
Utils.destroy_passed_object(obj)
|
|
|
|
|
|
|
|
def check(self,get,set,data):
|
|
|
|
"""Compares a data item, updates if necessary, and sets the
|
|
|
|
parents lists_changed flag"""
|
|
|
|
if get() != data:
|
|
|
|
set(data)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
|
|
|
|
def update(self,date,street,city,state,country,postal,note,priv):
|
|
|
|
"""Compares the data items, and updates if necessary"""
|
|
|
|
d = Date.Date()
|
|
|
|
d.set(date)
|
|
|
|
|
|
|
|
if self.addr.getDate() != d.getDate():
|
|
|
|
self.addr.setDate(date)
|
|
|
|
self.parent.lists_changed = 1
|
|
|
|
|
|
|
|
self.check(self.addr.getStreet,self.addr.setStreet,street)
|
|
|
|
self.check(self.addr.getCountry,self.addr.setCountry,country)
|
|
|
|
self.check(self.addr.getCity,self.addr.setCity,city)
|
|
|
|
self.check(self.addr.getState,self.addr.setState,state)
|
|
|
|
self.check(self.addr.getPostal,self.addr.setPostal,postal)
|
|
|
|
self.check(self.addr.getNote,self.addr.setNote,note)
|
|
|
|
self.check(self.addr.getPrivacy,self.addr.setPrivacy,priv)
|
|
|
|
|