1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2000-2007 Donald N. Allingham 5# Copyright (C) 2009 Gary Burton 6# Copyright (C) 2010 Nick Hall 7# Copyright (C) 2011 Tim G L Lyons 8# 9# This program is free software; you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation; either version 2 of the License, or 12# (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program; if not, write to the Free Software 21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22# 23 24""" 25The EditAddress module provides the EditAddress class. This provides a 26mechanism for the user to edit address information. 27""" 28 29#------------------------------------------------------------------------- 30# 31# Python modules 32# 33#------------------------------------------------------------------------- 34 35#------------------------------------------------------------------------- 36# 37# GTK/Gnome modules 38# 39#------------------------------------------------------------------------- 40import gi 41gi.require_version('Gtk', '3.0') 42from gi.repository import Gtk 43 44#------------------------------------------------------------------------- 45# 46# gramps modules 47# 48#------------------------------------------------------------------------- 49from gramps.gen.const import GRAMPS_LOCALE as glocale 50_ = glocale.translation.sgettext 51from .editsecondary import EditSecondary 52from gramps.gen.lib import NoteType 53from ..glade import Glade 54from .displaytabs import CitationEmbedList, NoteTab 55from ..widgets import MonitoredDate, MonitoredEntry, PrivacyButton 56from gramps.gen.const import URL_MANUAL_SECT3 57 58#------------------------------------------------------------------------- 59# 60# Constants 61# 62#------------------------------------------------------------------------- 63 64WIKI_HELP_PAGE = URL_MANUAL_SECT3 65WIKI_HELP_SEC = _('manual|Address_Editor_dialog') 66 67#------------------------------------------------------------------------- 68# 69# EditAddress class 70# 71#------------------------------------------------------------------------- 72class EditAddress(EditSecondary): 73 """ 74 Displays a dialog that allows the user to edit an address. 75 """ 76 77 78 def __init__(self, dbstate, uistate, track, addr, callback): 79 """ 80 Displays the dialog box. 81 82 parent - The class that called the Address editor. 83 addr - The address that is to be edited 84 """ 85 EditSecondary.__init__(self, dbstate, uistate, track, addr, callback) 86 87 def _local_init(self): 88 89 self.top = Glade() 90 self.set_window(self.top.toplevel, 91 self.top.get_object("title"), 92 _('Address Editor')) 93 self.setup_configs('interface.address', 650, 450) 94 95 def _setup_fields(self): 96 self.addr_start = MonitoredDate( 97 self.top.get_object("date_entry"), 98 self.top.get_object("date_stat"), 99 self.obj.get_date_object(), 100 self.uistate, 101 self.track, 102 self.db.readonly) 103 104 self.street = MonitoredEntry( 105 self.top.get_object("street"), self.obj.set_street, 106 self.obj.get_street, self.db.readonly) 107 108 self.city = MonitoredEntry( 109 self.top.get_object("city"), self.obj.set_city, 110 self.obj.get_city, self.db.readonly) 111 112 self.locality = MonitoredEntry( 113 self.top.get_object("locality"), self.obj.set_locality, 114 self.obj.get_locality, self.db.readonly) 115 116 self.state = MonitoredEntry( 117 self.top.get_object("state"), self.obj.set_state, 118 self.obj.get_state, self.db.readonly) 119 120 self.country = MonitoredEntry( 121 self.top.get_object("country"), self.obj.set_country, 122 self.obj.get_country, self.db.readonly) 123 124 self.postal = MonitoredEntry( 125 self.top.get_object("postal"), self.obj.set_postal_code, 126 self.obj.get_postal_code, self.db.readonly) 127 128 self.phone = MonitoredEntry( 129 self.top.get_object("phone"), self.obj.set_phone, 130 self.obj.get_phone, self.db.readonly) 131 132 self.priv = PrivacyButton(self.top.get_object("private"), 133 self.obj, self.db.readonly) 134 135 def _connect_signals(self): 136 self.define_cancel_button(self.top.get_object('cancel')) 137 self.define_ok_button(self.top.get_object('ok'),self.save) 138 self.define_help_button(self.top.get_object('help'), 139 WIKI_HELP_PAGE, WIKI_HELP_SEC) 140 141 def _create_tabbed_pages(self): 142 """ 143 Create the notebook tabs and inserts them into the main 144 window. 145 """ 146 147 notebook = Gtk.Notebook() 148 149 self.srcref_list = CitationEmbedList(self.dbstate, 150 self.uistate, 151 self.track, 152 self.obj.get_citation_list()) 153 self._add_tab(notebook, self.srcref_list) 154 self.track_ref_for_deletion("srcref_list") 155 156 self.note_tab = NoteTab(self.dbstate, self.uistate, self.track, 157 self.obj.get_note_list(), 158 notetype=NoteType.ADDRESS) 159 self._add_tab(notebook, self.note_tab) 160 self.track_ref_for_deletion("note_tab") 161 162 self._setup_notebook_tabs( notebook) 163 notebook.show_all() 164 self.top.get_object('vbox').pack_start(notebook, True, True, 0) 165 166 def build_menu_names(self, obj): 167 return (_('Address'),_('Address Editor')) 168 169 def save(self,*obj): 170 """ 171 Called when the OK button is pressed. Gets data from the 172 form and updates the Address data structure. 173 """ 174 if self.callback: 175 self.callback(self.obj) 176 self.close() 177