2008-01-02 Douglas S. Blank <dblank@cs.brynmawr.edu>

* src/Simple/_SimpleTable.py (SimpleTable.row): added obj handlers
	* src/plugins/References.py: new quick report for listing refs



svn: r9682
This commit is contained in:
Doug Blank 2008-01-02 13:20:26 +00:00
parent 1c87642339
commit cbce0ac6b4
3 changed files with 172 additions and 12 deletions

View File

@ -1,3 +1,7 @@
2008-01-02 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/Simple/_SimpleTable.py (SimpleTable.row): added obj handlers
* src/plugins/References.py: new quick report for listing refs
2008-01-02 Benny Malengier <benny.malengier@gramps-project.org>
* src/DbLoader.py: correct bug state -> dbstate

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Donald N. Allingham
# Copyright (C) 2008 Donald N. Allingham
#
# 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
@ -59,15 +59,16 @@ class SimpleTable:
"""
Handle events on tables. obj is a treeview
"""
from Editors import EditPerson, EditEvent
from Editors import (EditPerson, EditEvent, EditFamily, EditSource,
EditPlace, EditRepository)
selection = obj.get_selection()
store, node = selection.get_selected()
if not node:
return
index = store.get_value(node, 0) # index
if self.__link[index]:
htype, handle = self.__link[index]
if htype == 'Person':
objclass, handle = self.__link[index]
if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle)
try:
EditPerson(self.simpledoc.doc.dbstate,
@ -75,7 +76,7 @@ class SimpleTable:
return True # handled event
except Errors.WindowActiveError:
pass
elif htype == 'Event':
elif objclass == 'Event':
event = self.access.dbase.get_event_from_handle(handle)
try:
EditEvent(self.simpledoc.doc.dbstate,
@ -83,6 +84,43 @@ class SimpleTable:
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Family':
ref = self.access.dbase.get_family_from_handle(handle)
try:
EditFamily(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Source':
ref = self.access.dbase.get_source_from_handle(handle)
try:
EditSource(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Place':
ref = self.access.dbase.get_place_from_handle(handle)
try:
EditPlace(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Repository':
ref = self.access.dbase.get_repository_from_handle(handle)
try:
EditRepository(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Date':
run_quick_report_by_name(self.gui.dbstate,
self.gui.uistate,
'onthisday',
date)
return False # didn't handle event
def on_table_click(self, obj):
@ -95,23 +133,22 @@ class SimpleTable:
return
index = store.get_value(node, 0) # index
if self.__link[index]:
htype, handle = self.__link[index]
if htype == 'Person':
objclass, handle = self.__link[index]
if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle)
self.simpledoc.doc.dbstate.change_active_person(person)
return True
elif htype == 'Event':
pass
return False # didn't handle event
def row(self, *data):
"""
Add a row of data.
"""
# FIXME: add data and/or linkable types for all
from QuickReports import run_quick_report_by_name
retval = []
link = None
for item in data:
# FIXME: add better text representations of these objects
if type(item) in [str, unicode]:
retval.append(item)
elif isinstance(item, gen.lib.Person):
@ -119,25 +156,43 @@ class SimpleTable:
retval.append(name)
link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family):
retval.append(_('Family'))
father = self.access.father(item)
mother = self.access.mother(item)
text = ""
if father:
text += " " + self.access.name(father)
else:
text += " " + _("Unknown father")
text += " and"
if mother:
text += " " + self.access.name(mother)
else:
text += " " + _("Unknown mother")
retval.append(text)
link = ('Family', item.handle)
elif isinstance(item, gen.lib.Source):
retval.append(_('Source'))
link = ('Souce', item.handle)
elif isinstance(item, gen.lib.Event):
name = self.access.event_type(item)
retval.append(name)
link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject):
retval.append(_('Media'))
link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place):
retval.append(_('Place'))
link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository):
retval.append(_('Repository'))
link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note):
retval.append(_('Note'))
link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date):
text = DateHandler.displayer.display(item)
retval.append(text)
#link = ('Date', item)
link = ('Date', item)
else:
raise AttributeError, ("unknown object type: '%s': %s" %
(item, type(item)))

101
src/plugins/References.py Normal file
View File

@ -0,0 +1,101 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
#
# 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
#
"""
Display references for any object
"""
from Simple import SimpleAccess, SimpleDoc, SimpleTable
from gettext import gettext as _
from PluginUtils import register_quick_report
from ReportBase import *
def get_ref(db, objclass, handle):
"""
Looks up object in database
"""
if objclass == 'Person':
ref = db.get_person_from_handle(handle)
elif objclass == 'Family':
ref = db.get_family_from_handle(handle)
elif objclass == 'Event':
ref = db.get_event_from_handle(handle)
elif objclass == 'Source':
ref = db.get_source_from_handle(handle)
elif objclass == 'Place':
ref = db.get_place_from_handle(handle)
elif objclass == 'Repository':
ref = db.get_repository_from_handle(handle)
else:
ref = objclass
return ref
def run(database, document, object, item, trans):
"""
Display back-references for this object.
"""
# setup the simple access functions
sdb = SimpleAccess(database)
sdoc = SimpleDoc(document)
stab = SimpleTable(sdb, sdoc)
# display the title
sdoc.title(_("References for this %s") % trans)
sdoc.paragraph("\n")
stab.columns(_("Type"), _("Reference"))
for (objclass, handle) in database.find_backlink_handles(object.handle):
ref = get_ref(database, objclass, handle)
stab.row(objclass, ref)
if stab.get_row_count() > 0:
stab.write()
else:
sdoc.paragraph(_("No references for this %s") % trans)
sdoc.paragraph("")
sdoc.paragraph("")
#------------------------------------------------------------------------
#
# Register the report
#
#------------------------------------------------------------------------
refitems = [(CATEGORY_QR_PERSON, 'person', _("Person")),
(CATEGORY_QR_FAMILY,'family', _("Family")),
(CATEGORY_QR_EVENT, 'event', _("Event")),
(CATEGORY_QR_SOURCE, 'source', _("Source")),
(CATEGORY_QR_PLACE, 'place', _("Place")),
(CATEGORY_QR_REPOSITORY, 'repository', _("Repository")),
]
for (category,item,trans) in refitems:
register_quick_report(
name = item + 'refereneces',
category = category,
run_func = lambda db, doc, obj, item=item, trans=trans: \
run(db, doc, obj, item, trans),
translated_name = _("%s References") % trans,
status = _("Stable"),
description= _("Display references for a %s") % trans,
author_name="Douglas Blank",
author_email="dblank@cs.brynmawr.edu"
)