2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-01-31 07:35:01 +05:30
|
|
|
# Copyright (C) 2000-2007 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-11-13 00:15:07 +05:30
|
|
|
# $Id$
|
|
|
|
|
2004-09-19 20:47:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-18 21:59:43 +05:30
|
|
|
from TransUtils import sgettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-02-08 20:59:28 +05:30
|
|
|
from gtk import glade
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2006-11-26 06:59:58 +05:30
|
|
|
import Config
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2005-12-07 01:24:16 +05:30
|
|
|
import GrampsDisplay
|
2008-02-08 20:59:28 +05:30
|
|
|
from Editors import EditPrimary
|
2008-05-11 21:52:14 +05:30
|
|
|
from objectentries import PlaceEntry
|
2005-08-18 11:28:28 +05:30
|
|
|
|
2006-07-03 09:55:33 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2008-02-08 20:59:28 +05:30
|
|
|
from DisplayTabs import (SourceEmbedList, NoteTab, GalleryTab,
|
|
|
|
EventBackRefList, AttrEmbedList)
|
2008-05-11 21:52:14 +05:30
|
|
|
from widgets import (MonitoredEntry, PrivacyButton,
|
2008-05-09 01:10:56 +05:30
|
|
|
MonitoredDataType, MonitoredDate)
|
2004-09-19 20:47:57 +05:30
|
|
|
|
2005-06-09 02:47:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-18 21:59:43 +05:30
|
|
|
WIKI_HELP_PAGE = 'Gramps_3.0_Wiki_Manual_-_Entering_and_Editing_Data:_Detailed'
|
|
|
|
WIKI_HELP_SEC = _('manual|Editing_Information_About_Events')
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-03-04 10:00:05 +05:30
|
|
|
# EditEvent class
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-04 12:04:48 +05:30
|
|
|
class EditEvent(EditPrimary):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
def __init__(self, dbstate, uistate, track, event, callback=None):
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2006-03-04 12:04:48 +05:30
|
|
|
EditPrimary.__init__(self, dbstate, uistate, track,
|
2008-02-09 06:37:23 +05:30
|
|
|
event, dbstate.db.get_event_from_handle,
|
|
|
|
dbstate.db.get_event_from_gramps_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-04-01 05:16:34 +05:30
|
|
|
self._init_event()
|
|
|
|
|
|
|
|
def _init_event(self):
|
|
|
|
self.commit_event = self.db.commit_event
|
|
|
|
|
2006-04-01 01:16:41 +05:30
|
|
|
def empty_object(self):
|
2007-10-08 22:11:39 +05:30
|
|
|
return gen.lib.Event()
|
2006-04-01 01:16:41 +05:30
|
|
|
|
2006-11-27 02:48:30 +05:30
|
|
|
def get_menu_title(self):
|
|
|
|
if self.obj.get_handle():
|
|
|
|
event_name = self.obj.get_description()
|
|
|
|
if not event_name:
|
|
|
|
event_name = str(self.obj.get_type())
|
|
|
|
dialog_title = _('Event: %s') % event_name
|
|
|
|
else:
|
|
|
|
dialog_title = _('New Event')
|
|
|
|
return dialog_title
|
|
|
|
|
2006-04-01 05:16:34 +05:30
|
|
|
def get_custom_events(self):
|
2006-05-21 23:47:52 +05:30
|
|
|
return self.dbstate.db.get_person_event_types() + \
|
2006-04-01 05:16:34 +05:30
|
|
|
self.dbstate.db.get_family_event_types()
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def _local_init(self):
|
2008-02-08 20:59:28 +05:30
|
|
|
self.top = glade.XML(const.GLADE_FILE, "event_edit","gramps")
|
2007-01-23 22:32:55 +05:30
|
|
|
self.set_window(self.top.get_widget("event_edit"), None,
|
2007-03-22 03:41:52 +05:30
|
|
|
self.get_menu_title())
|
2005-06-07 05:20:33 +05:30
|
|
|
|
2006-05-17 10:05:03 +05:30
|
|
|
self.place = self.top.get_widget('place')
|
|
|
|
self.share_btn = self.top.get_widget('select_place')
|
|
|
|
self.add_del_btn = self.top.get_widget('add_del_place')
|
|
|
|
|
2006-11-26 06:59:58 +05:30
|
|
|
width = Config.get(Config.EVENT_WIDTH)
|
|
|
|
height = Config.get(Config.EVENT_HEIGHT)
|
|
|
|
self.window.resize(width, height)
|
|
|
|
|
2006-02-23 08:43:15 +05:30
|
|
|
def _connect_signals(self):
|
2008-02-08 20:59:28 +05:30
|
|
|
self.top.get_widget('button111').connect('clicked', self.close)
|
|
|
|
self.top.get_widget('button126').connect('clicked', self.help_clicked)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-06-26 11:59:48 +05:30
|
|
|
self.ok_button = self.top.get_widget('ok')
|
|
|
|
self.ok_button.set_sensitive(not self.db.readonly)
|
2008-02-08 20:59:28 +05:30
|
|
|
self.ok_button.connect('clicked', self.save)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-02-23 08:43:15 +05:30
|
|
|
def _setup_fields(self):
|
2006-05-17 10:05:03 +05:30
|
|
|
|
|
|
|
# place, select_place, add_del_place
|
|
|
|
|
2008-02-09 06:37:23 +05:30
|
|
|
self.place_field = PlaceEntry(self.dbstate, self.uistate, self.track,
|
|
|
|
self.top.get_widget("place"),
|
|
|
|
self.obj.set_place_handle,
|
|
|
|
self.obj.get_place_handle,
|
|
|
|
self.add_del_btn, self.share_btn)
|
2006-02-24 10:35:46 +05:30
|
|
|
|
2008-02-09 06:37:23 +05:30
|
|
|
self.descr_field = MonitoredEntry(self.top.get_widget("event_description"),
|
|
|
|
self.obj.set_description,
|
|
|
|
self.obj.get_description,
|
|
|
|
self.db.readonly)
|
|
|
|
|
|
|
|
self.gid = MonitoredEntry(self.top.get_widget("gid"),
|
|
|
|
self.obj.set_gramps_id,
|
|
|
|
self.obj.get_gramps_id, self.db.readonly)
|
|
|
|
|
|
|
|
self.priv = PrivacyButton( self.top.get_widget("private"),
|
|
|
|
self.obj, self.db.readonly)
|
|
|
|
|
|
|
|
self.event_menu = MonitoredDataType(self.top.get_widget("personal_events"),
|
|
|
|
self.obj.set_type,
|
|
|
|
self.obj.get_type,
|
|
|
|
custom_values=self.get_custom_events())
|
|
|
|
|
|
|
|
self.date_field = MonitoredDate(self.top.get_widget("date_entry"),
|
|
|
|
self.top.get_widget("date_stat"),
|
|
|
|
self.obj.get_date_object(),
|
|
|
|
self.uistate, self.track,
|
|
|
|
self.db.readonly)
|
2004-02-20 07:56:47 +05:30
|
|
|
|
2006-02-03 04:18:21 +05:30
|
|
|
def _create_tabbed_pages(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create the notebook tabs and inserts them into the main
|
2006-02-03 04:18:21 +05:30
|
|
|
window.
|
|
|
|
"""
|
2006-03-01 10:38:11 +05:30
|
|
|
notebook = gtk.Notebook()
|
|
|
|
|
|
|
|
self.srcref_list = self._add_tab(
|
|
|
|
notebook,
|
2006-10-09 08:15:26 +05:30
|
|
|
SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
self.note_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
NoteTab(self.dbstate, self.uistate, self.track,
|
2007-10-08 22:11:39 +05:30
|
|
|
self.obj.get_note_list(), notetype=gen.lib.NoteType.EVENT))
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
self.gallery_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
GalleryTab(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_media_list()))
|
2006-04-21 04:02:17 +05:30
|
|
|
|
2007-12-15 03:48:19 +05:30
|
|
|
self.attr_ref_list = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
AttrEmbedList(self.dbstate, self.uistate, self.track,
|
|
|
|
self.obj.get_attribute_list()))
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
self.backref_tab = self._add_tab(
|
|
|
|
notebook,
|
|
|
|
EventBackRefList(self.dbstate, self.uistate, self.track,
|
2006-04-21 09:44:00 +05:30
|
|
|
self.dbstate.db.find_backlink_handles(self.obj.handle)))
|
2006-08-14 09:02:20 +05:30
|
|
|
|
2007-01-16 12:42:10 +05:30
|
|
|
self._setup_notebook_tabs( notebook)
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
notebook.show_all()
|
2008-02-08 20:59:28 +05:30
|
|
|
self.top.get_widget('vbox').pack_start(notebook, True)
|
2006-03-01 10:38:11 +05:30
|
|
|
|
|
|
|
def _cleanup_on_exit(self):
|
|
|
|
self.backref_tab.close()
|
2006-11-26 06:59:58 +05:30
|
|
|
(width, height) = self.window.get_size()
|
|
|
|
Config.set(Config.EVENT_WIDTH, width)
|
|
|
|
Config.set(Config.EVENT_HEIGHT, height)
|
|
|
|
Config.sync()
|
2006-02-03 04:18:21 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
def build_menu_names(self, event):
|
2006-11-27 02:48:30 +05:30
|
|
|
return (_('Edit Event'), self.get_menu_title())
|
2005-12-23 05:13:32 +05:30
|
|
|
|
2008-02-08 20:59:28 +05:30
|
|
|
def help_clicked(self, obj):
|
2003-11-18 09:56:06 +05:30
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2008-04-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC)
|
2008-02-08 20:59:28 +05:30
|
|
|
def save(self, *obj):
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button.set_sensitive(False)
|
2006-04-01 01:16:41 +05:30
|
|
|
if self.object_is_empty():
|
|
|
|
ErrorDialog(_("Cannot save event"),
|
|
|
|
_("No data exists for this event. Please "
|
|
|
|
"enter data or cancel the edit."))
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button.set_sensitive(True)
|
2006-04-01 01:16:41 +05:30
|
|
|
return
|
2008-02-09 06:37:23 +05:30
|
|
|
|
|
|
|
(uses_dupe_id, id) = self._uses_duplicate_id()
|
|
|
|
if uses_dupe_id:
|
|
|
|
prim_object = self.get_from_gramps_id(id)
|
|
|
|
name = prim_object.get_description()
|
|
|
|
msg1 = _("Cannot save event. ID already exists.")
|
|
|
|
msg2 = _("You have attempted to use the existing GRAMPS ID with "
|
|
|
|
"value %(id)s. This value is already used by '"
|
|
|
|
"%(prim_object)s'. Please enter a different ID or leave "
|
|
|
|
"blank to get the next available ID value.") % {
|
|
|
|
'id' : id, 'prim_object' : name }
|
|
|
|
ErrorDialog(msg1, msg2)
|
|
|
|
self.ok_button.set_sensitive(True)
|
|
|
|
return
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-06-16 09:02:51 +05:30
|
|
|
t = self.obj.get_type()
|
|
|
|
if t.is_custom() and str(t) == '':
|
|
|
|
ErrorDialog(
|
|
|
|
_("Cannot save event"),
|
|
|
|
_("The event type cannot be empty"))
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button.set_sensitive(True)
|
2006-06-16 09:02:51 +05:30
|
|
|
return
|
|
|
|
|
2008-02-08 19:10:04 +05:30
|
|
|
if not self.obj.handle:
|
2005-06-08 10:10:33 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2008-02-08 19:10:04 +05:30
|
|
|
self.db.add_event(self.obj, trans)
|
|
|
|
self.db.transaction_commit(trans, _("Add Event"))
|
2006-02-08 10:38:28 +05:30
|
|
|
else:
|
2008-02-08 19:10:04 +05:30
|
|
|
orig = self.get_from_handle(self.obj.handle)
|
2008-02-08 20:59:28 +05:30
|
|
|
if cmp(self.obj.serialize(), orig.serialize()):
|
2006-02-08 10:38:28 +05:30
|
|
|
trans = self.db.transaction_begin()
|
2008-02-08 19:10:04 +05:30
|
|
|
if not self.obj.get_gramps_id():
|
|
|
|
self.obj.set_gramps_id(self.db.find_next_event_gramps_id())
|
2008-02-08 20:59:28 +05:30
|
|
|
self.commit_event(self.obj, trans)
|
|
|
|
self.db.transaction_commit(trans, _("Edit Event"))
|
2006-02-08 10:38:28 +05:30
|
|
|
|
2006-02-04 04:01:46 +05:30
|
|
|
if self.callback:
|
2006-03-01 10:38:11 +05:30
|
|
|
self.callback(self.obj)
|
2006-04-22 08:53:57 +05:30
|
|
|
self.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-09-09 22:40:13 +05:30
|
|
|
def data_has_changed(self):
|
|
|
|
"""
|
|
|
|
A date comparison can fail incorrectly because we have made the
|
|
|
|
decision to store entered text in the date. However, there is no
|
|
|
|
entered date when importing from a XML file, so we can get an
|
|
|
|
incorrect fail.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self.db.readonly:
|
|
|
|
return False
|
|
|
|
elif self.obj.handle:
|
|
|
|
orig = self.get_from_handle(self.obj.handle)
|
|
|
|
if orig:
|
|
|
|
cmp_obj = orig
|
|
|
|
else:
|
|
|
|
cmp_obj = self.empty_object()
|
|
|
|
return cmp(cmp_obj.serialize(True)[1:],
|
|
|
|
self.obj.serialize(True)[1:]) != 0
|
|
|
|
else:
|
|
|
|
cmp_obj = self.empty_object()
|
|
|
|
return cmp(cmp_obj.serialize(True)[1:],
|
|
|
|
self.obj.serialize()[1:]) != 0
|
|
|
|
|
|
|
|
|
2006-04-01 05:16:34 +05:30
|
|
|
class EditPersonEvent(EditEvent):
|
|
|
|
|
2007-01-31 07:35:01 +05:30
|
|
|
def __init__(self, dbstate, uistate, track, event, callback=None):
|
|
|
|
EditEvent.__init__(self, dbstate, uistate, track, event, callback)
|
2006-04-01 05:16:34 +05:30
|
|
|
|
|
|
|
def _init_event(self):
|
|
|
|
self.commit_event = self.db.commit_personal_event
|
|
|
|
|
|
|
|
def get_custom_events(self):
|
2006-05-21 23:47:52 +05:30
|
|
|
return self.dbstate.db.get_person_event_types()
|
2006-04-01 05:16:34 +05:30
|
|
|
|
|
|
|
class EditFamilyEvent(EditEvent):
|
|
|
|
|
2007-01-31 07:35:01 +05:30
|
|
|
def __init__(self, dbstate, uistate, track, event, callback=None):
|
|
|
|
EditEvent.__init__(self, dbstate, uistate, track, event, callback)
|
2006-04-01 05:16:34 +05:30
|
|
|
|
|
|
|
def _init_event(self):
|
|
|
|
self.commit_event = self.db.commit_family_event
|
|
|
|
|
|
|
|
def get_custom_events(self):
|
|
|
|
return self.dbstate.db.get_family_event_types()
|
|
|
|
|
2005-06-08 10:10:33 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Delete Query class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DelEventQuery:
|
2008-02-08 20:59:28 +05:30
|
|
|
def __init__(self, dbstate, uistate, event, person_list, family_list):
|
2005-06-08 10:10:33 +05:30
|
|
|
self.event = event
|
2007-01-23 09:07:13 +05:30
|
|
|
self.db = dbstate.db
|
|
|
|
self.uistate = uistate
|
2005-06-08 10:10:33 +05:30
|
|
|
self.person_list = person_list
|
|
|
|
self.family_list = family_list
|
|
|
|
|
|
|
|
def query_response(self):
|
|
|
|
trans = self.db.transaction_begin()
|
|
|
|
self.db.disable_signals()
|
|
|
|
|
|
|
|
ev_handle_list = [self.event.get_handle()]
|
|
|
|
|
|
|
|
for handle in self.person_list:
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
2008-02-08 20:59:28 +05:30
|
|
|
person.remove_handle_references('Event', ev_handle_list)
|
|
|
|
self.db.commit_person(person, trans)
|
2005-06-08 10:10:33 +05:30
|
|
|
|
|
|
|
for handle in self.family_list:
|
|
|
|
family = self.db.get_family_from_handle(handle)
|
2008-02-08 20:59:28 +05:30
|
|
|
family.remove_handle_references('Event', ev_handle_list)
|
|
|
|
self.db.commit_family(family, trans)
|
2005-06-08 10:10:33 +05:30
|
|
|
|
|
|
|
self.db.enable_signals()
|
2008-02-08 20:59:28 +05:30
|
|
|
self.db.remove_event(self.event.get_handle(), trans)
|
2005-06-08 10:10:33 +05:30
|
|
|
self.db.transaction_commit(
|
|
|
|
trans,_("Delete Event (%s)") % self.event.get_gramps_id())
|