1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2000-2007 Donald N. Allingham 5# Copyright (C) 2007-2008 Brian G. Matherly 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# 22 23""" 24Display all events on a particular day. 25""" 26 27from gramps.gen.simple import SimpleAccess, SimpleDoc, SimpleTable 28from gramps.gui.plug.quick import QuickTable 29from gramps.gen.const import GRAMPS_LOCALE as glocale 30_ = glocale.translation.gettext 31from gramps.gen.lib import Date 32 33def get_ref(db, objclass, handle): 34 """ 35 Looks up object in database 36 """ 37 if objclass == 'Person': 38 ref = db.get_person_from_handle(handle) 39 elif objclass == 'Family': 40 ref = db.get_family_from_handle(handle) 41 elif objclass == 'Event': 42 ref = db.get_event_from_handle(handle) 43 elif objclass == 'Source': 44 ref = db.get_source_from_handle(handle) 45 elif objclass == 'Place': 46 ref = db.get_place_from_handle(handle) 47 elif objclass == 'Repository': 48 ref = db.get_repository_from_handle(handle) 49 else: 50 ref = objclass 51 return ref 52 53def run(database, document, main_event): 54 """ 55 Displays events on a specific date of an event (or date) 56 57 Takes an Event or Date object 58 """ 59 if isinstance(main_event, Date): 60 main_date = main_event 61 else: 62 main_date = main_event.get_date_object() 63 64 cal = main_date.get_calendar(); 65 66 # setup the simple access functions 67 sdb = SimpleAccess(database) 68 sdoc = SimpleDoc(document) 69 stab = QuickTable(sdb) 70 stab.set_link_col(3) 71 yeartab = QuickTable(sdb) 72 yeartab.set_link_col(3) 73 histab = QuickTable(sdb) 74 histab.set_link_col(3) 75 76 # display the title 77 sdoc.title(_("Events of %(date)s") % 78 {"date": sdb.date_string(main_date)}) 79 sdoc.paragraph("") 80 stab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) 81 yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) 82 histab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) 83 84 for event in database.iter_events(): 85 date = event.get_date_object() 86 date.convert_calendar(cal) 87 if date.get_year() == 0: 88 continue 89 if (date.get_year() == main_date.get_year() and 90 date.get_month() == main_date.get_month() and 91 date.get_day() == main_date.get_day()): 92 for (objclass, handle) in database.find_backlink_handles(event.handle): 93 ref = get_ref(database, objclass, handle) 94 stab.row(date, 95 sdb.event_type(event), 96 sdb.event_place(event), ref) 97 elif (date.get_month() == main_date.get_month() and 98 date.get_day() == main_date.get_day() and 99 date.get_month() != 0): 100 for (objclass, handle) in database.find_backlink_handles(event.handle): 101 ref = get_ref(database, objclass, handle) 102 histab.row(date, 103 sdb.event_type(event), 104 sdb.event_place(event), ref) 105 elif (date.get_year() == main_date.get_year()): 106 for (objclass, handle) in database.find_backlink_handles(event.handle): 107 ref = get_ref(database, objclass, handle) 108 yeartab.row(date, 109 sdb.event_type(event), 110 sdb.event_place(event), ref) 111 112 document.has_data = False 113 if stab.get_row_count() > 0: 114 document.has_data = True 115 sdoc.paragraph(_("Events on this exact date")) 116 stab.write(sdoc) 117 else: 118 sdoc.paragraph(_("No events on this exact date")) 119 sdoc.paragraph("") 120 sdoc.paragraph("") 121 122 if histab.get_row_count() > 0: 123 document.has_data = True 124 sdoc.paragraph(_("Other events on this month/day in history")) 125 histab.write(sdoc) 126 else: 127 sdoc.paragraph(_("No other events on this month/day in history")) 128 sdoc.paragraph("") 129 sdoc.paragraph("") 130 131 if yeartab.get_row_count() > 0: 132 document.has_data = True 133 sdoc.paragraph(_("Other events in %(year)d") % 134 {"year":main_date.get_year()}) 135 yeartab.write(sdoc) 136 else: 137 sdoc.paragraph(_("No other events in %(year)d") % 138 {"year":main_date.get_year()}) 139 sdoc.paragraph("") 140 sdoc.paragraph("") 141