Added SimpleAccess.describe method that gives a simple description of an object instance; protection for null objects; new quick views for proxies

svn: r15498
This commit is contained in:
Doug Blank 2010-05-29 20:13:09 +00:00
parent 44aafc8569
commit 2a44a7dd77
3 changed files with 280 additions and 143 deletions

View File

@ -924,6 +924,41 @@ class SimpleAccess(object):
else:
return "Error: invalid object class: '%s'" % object_class
def describe(self, obj):
"""
Given a object, return a string describing the object.
"""
if isinstance(obj, gen.lib.Person):
return self.name(obj)
elif isinstance(obj, gen.lib.Event):
return self.event_type(obj)
elif isinstance(obj, gen.lib.Family):
father = self.father(obj)
mother = self.mother(obj)
if father:
father_text = self.name(father)
else:
father_text = _("Unknown father")
if mother:
mother_text = self.name(mother)
else:
mother_text = _("Unknown mother")
return "%s and %s" % (mother_text, father_text)
elif isinstance(obj, gen.lib.MediaObject):
return obj.desc
elif isinstance(obj, gen.lib.Source):
return self.title(obj)
elif isinstance(obj, gen.lib.Place):
return place_name(self.dbase, obj.handle)
elif isinstance(obj, gen.lib.Repository):
return obj.type
elif isinstance(obj, gen.lib.Note):
return obj.type
elif obj is None:
return ""
else:
return "Error: incorrect object class: '%s'" % type(obj)
def get_link(self, object_class, prop, value):
"""
Given a object_class, prop, and value return the object.

View File

@ -83,45 +83,87 @@ class SimpleTable(object):
def button_press_event(self, treeview, event):
import gtk
if event.button == 3:
x = int(event.x)
y = int(event.y)
path_info = treeview.get_path_at_pos(x, y)
if path_info is not None:
path, col, cellx, celly = path_info
index = None
button_code = None
event_time = None
func = None
if type(event) == bool: # enter
button_code = 3
event_time = 0
selection = treeview.get_selection()
store, node = selection.get_selected()
if node:
treeview.grab_focus()
index = store.get_value(node, 0)
# FIXME: make popup come where cursor is
#rectangle = treeview.get_visible_rect()
#column = treeview.get_column(0)
#rectangle = treeview.get_cell_area("0:0",
#x, y = rectangle.x, rectangle.y
#func = lambda menu: (x, y, True)
elif event.button == 3:
button_code = 3
event_time = event.time
x = int(event.x)
y = int(event.y)
path_info = treeview.get_path_at_pos(x, y)
func = None
if path_info is not None:
path, col, cellx, celly = path_info
selection = treeview.get_selection()
store, node = selection.get_selected()
if path:
treeview.grab_focus()
treeview.set_cursor(path, col, 0)
selection = treeview.get_selection()
store, node = selection.get_selected()
index = None
if node:
index = store.get_value(node, 0) # index
popup = gtk.Menu()
if (index is not None and self.__link[index]):
# See details (edit, etc):
objclass, handle = self.__link[index]
menu_item = gtk.MenuItem(_("See %s details") % objclass)
menu_item.connect("activate",
lambda widget: self.on_table_doubleclick(treeview,
path, 0))
popup.append(menu_item)
menu_item.show()
# Add other items to menu:
if (self._callback_leftclick or
(index is not None and self.__link[index])):
objclass, handle = self.__link[index]
if objclass == 'Person':
menu_item = gtk.MenuItem(_("Make Active Person"))
menu_item.connect("activate",
lambda widget: self.on_table_click(treeview))
popup.append(menu_item)
menu_item.show()
# Show the popup menu:
popup.popup(None, None, None, event.button, event.time)
return True
index = store.get_value(node, 0) # index Below,
# you need index, treeview, path, button_code,
# func, and event_time
if index is not None:
popup = gtk.Menu()
if (index is not None and self.__link[index]):
# See details (edit, etc):
objclass, handle = self.__link[index]
menu_item = gtk.MenuItem(_("See %s details") % objclass)
menu_item.connect("activate",
lambda widget: self.on_table_doubleclick(treeview))
popup.append(menu_item)
menu_item.show()
# Add other items to menu:
if (self._callback_leftclick or
(index is not None and self.__link[index])):
objclass, handle = self.__link[index]
if objclass == 'Person':
menu_item = gtk.MenuItem(_("Make Active Person"))
menu_item.connect("activate",
lambda widget: self.on_table_click(treeview))
popup.append(menu_item)
menu_item.show()
if (self.simpledoc.doc.dbstate.db !=
self.simpledoc.doc.dbstate.db.basedb and
(index is not None and self.__link[index])):
objclass, handle = self.__link[index]
if (objclass == 'Filter' and
handle[0] in ['Person', 'Family', 'Place', 'Event',
'Repository', 'Note', 'MediaObject',
'Source']):
menu_item = gtk.MenuItem(_("See data not in Filter"))
menu_item.connect("activate",
lambda widget: self.show_not_in_filter(handle[0]))
popup.append(menu_item)
menu_item.show()
# Show the popup menu:
popup.popup(None, None, func, button_code, event_time)
return True
return False
def on_table_doubleclick(self, obj, path, view_column):
def show_not_in_filter(self, obj_class):
from QuickReports import run_quick_report_by_name
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
'Inverse %s' % obj_class)
def on_table_doubleclick(self, obj):
"""
Handle events on tables. obj is a treeview
"""
@ -139,68 +181,76 @@ class SimpleTable(object):
objclass, handle = self.__link[index]
if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle)
try:
EditPerson(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], person)
return True # handled event
except Errors.WindowActiveError:
pass
if person:
try:
EditPerson(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], person)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Event':
event = self.access.dbase.get_event_from_handle(handle)
try:
EditEvent(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], event)
return True # handled event
except Errors.WindowActiveError:
pass
if event:
try:
EditEvent(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], event)
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
if ref:
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
if ref:
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
if ref:
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
if ref:
try:
EditRepository(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Note':
ref = self.access.dbase.get_note_from_handle(handle)
try:
EditNote(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
if ref:
try:
EditNote(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass in ['Media', 'MediaObject']:
ref = self.access.dbase.get_object_from_handle(handle)
try:
EditMedia(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
if ref:
try:
EditMedia(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'PersonList':
from QuickReports import run_quick_report_by_name
run_quick_report_by_name(self.simpledoc.doc.dbstate,
@ -277,48 +327,35 @@ class SimpleTable(object):
retval.append(item)
self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person):
name = self.access.name(item)
retval.append(name)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family):
father = self.access.father(item)
mother = self.access.mother(item)
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)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Family', item.handle)
elif isinstance(item, gen.lib.Source):
retval.append(item.gramps_id)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Source', item.handle)
elif isinstance(item, gen.lib.Event):
name = self.access.event_type(item)
retval.append(name)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject):
retval.append(item.gramps_id)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place):
retval.append(item.gramps_id)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository):
retval.append(item.gramps_id)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note):
retval.append(item.gramps_id)
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date):
@ -436,6 +473,7 @@ class SimpleTable(object):
#treeview.connect('row-activated', on_table_doubleclick, self)
#treeview.connect('cursor-changed', on_table_click, self)
treeview.connect('button-press-event', self.button_press_event)
treeview.connect('select-cursor-row', self.button_press_event)
renderer = gtk.CellRendererText()
types = [int] # index
cnt = 0

View File

@ -72,28 +72,28 @@ def run(database, document, filter_name, *args, **kwargs):
sdoc.paragraph("Double-click row to see selected items.")
sdoc.paragraph("")
stab.columns(_("Object"), _("Count/Total"))
stab.row([_("People"), "Filter", "all people"],
stab.row([_("People"), "Filter", "Person"],
"%d/%d" % (len(database.get_person_handles()),
len(database.basedb.get_person_handles())))
stab.row([_("Families"), "Filter", "all families"],
stab.row([_("Families"), "Filter", "Family"],
"%d/%d" % (len(database.get_family_handles()),
len(database.basedb.get_family_handles())))
stab.row([_("Events"), "Filter", "all events"],
stab.row([_("Events"), "Filter", "Event"],
"%d/%d" % (len(database.get_event_handles()),
len(database.basedb.get_event_handles())))
stab.row([_("Places"), "Filter", "all places"],
stab.row([_("Places"), "Filter", "Place"],
"%d/%d" % (len(database.get_place_handles()),
len(database.basedb.get_place_handles())))
stab.row([_("Sources"), "Filter", "all sources"],
stab.row([_("Sources"), "Filter", "Source"],
"%d/%d" % (len(database.get_source_handles()),
len(database.basedb.get_source_handles())))
stab.row([_("Repositories"), "Filter", "all repositories"],
stab.row([_("Repositories"), "Filter", "Repository"],
"%d/%d" % (len(database.get_repository_handles()),
len(database.basedb.get_repository_handles())))
stab.row([_("Media"), "Filter", "all media"],
stab.row([_("Media"), "Filter", "MediaObject"],
"%d/%d" % (len(database.get_media_object_handles()),
len(database.basedb.get_media_object_handles())))
stab.row([_("Notes"), "Filter", "all notes"],
stab.row([_("Notes"), "Filter", "Note"],
"%d/%d" % (len(database.get_note_handles()),
len(database.basedb.get_note_handles())))
sdoc.paragraph("")
@ -106,54 +106,118 @@ def run(database, document, filter_name, *args, **kwargs):
sdoc.title(_("Filtering on %s") % _(filter_name))
sdoc.paragraph("")
matches = 0
if (filter_name == 'people not in filter'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
proxy_handles = dict([(handle,1) for handle in database.iter_person_handles()])
if (filter_name == 'Inverse Person'):
sdb.dbase = database.basedb
stab.columns(_("Person"), _("Gramps ID"), _("Birth Date"))
proxy_handles = dict([(handle,1) for handle in
database.iter_person_handles()])
for person in database.basedb.iter_people():
if person.handle not in proxy_handles:
stab.row(person, sdb.birth_or_fallback(person),
str(person.get_primary_name().get_type()))
matches += 1
elif (filter_name == 'all people'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))
stab.row(person, person.gramps_id,
sdb.birth_or_fallback(person))
matches += 1
elif (filter_name == 'Inverse Family'):
sdb.dbase = database.basedb
stab.columns(_("Family"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_family_handles()])
for family in database.basedb.iter_families():
if family.handle not in proxy_handles:
stab.row(family, family.gramps_id)
matches += 1
elif (filter_name == 'Inverse Event'):
sdb.dbase = database.basedb
stab.columns(_("Event"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_event_handles()])
for event in database.basedb.iter_events():
if event.handle not in proxy_handles:
stab.row(event, event.gramps_id)
matches += 1
elif (filter_name == 'Inverse Place'):
sdb.dbase = database.basedb
stab.columns(_("Place"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_place_handles()])
for place in database.basedb.iter_places():
if place.handle not in proxy_handles:
stab.row(place, place.gramps_id)
matches += 1
elif (filter_name == 'Inverse Source'):
sdb.dbase = database.basedb
stab.columns(_("Source"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_source_handles()])
for source in database.basedb.iter_sources():
if source.handle not in proxy_handles:
stab.row(source, source.gramps_id)
matches += 1
elif (filter_name == 'Inverse Repository'):
sdb.dbase = database.basedb
stab.columns(_("Repository"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_repository_handles()])
for repository in database.basedb.iter_repositories():
if repository.handle not in proxy_handles:
stab.row(repository, repository.gramps_id)
matches += 1
elif (filter_name == 'Inverse MediaObject'):
sdb.dbase = database.basedb
stab.columns(_("Media"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_media_object_handles()])
for media in database.basedb.iter_media_objects():
if media.handle not in proxy_handles:
stab.row(media, media.gramps_id)
matches += 1
elif (filter_name == 'Inverse Note'):
sdb.dbase = database.basedb
stab.columns(_("Note"), _("Gramps ID"))
proxy_handles = dict([(handle,1) for handle in
database.iter_note_handles()])
for note in database.basedb.iter_notes():
if note.handle not in proxy_handles:
stab.row(note, note.gramps_id)
matches += 1
elif (filter_name in ['all people', 'Person']):
stab.columns(_("Person"), _("Gramps ID"), _("Birth Date"))
for person in database.iter_people():
stab.row(person, sdb.birth_or_fallback(person),
str(person.get_primary_name().get_type()))
stab.row(person, person.gramps_id, sdb.birth_or_fallback(person))
matches += 1
elif (filter_name == 'all families'):
stab.columns(_("Family"))
elif (filter_name in ['all families', 'Family']):
stab.columns(_("Family"), _("Gramps ID"))
for family in database.iter_families():
stab.row(family)
stab.row(family, family.gramps_id)
matches += 1
elif (filter_name == 'all events'):
stab.columns(_("Event"))
elif (filter_name in ['all events', 'Event']):
stab.columns(_("Event"), _("Gramps ID"))
for obj in database.iter_events():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'all places'):
stab.columns(_("Place"))
elif (filter_name in ['all places', 'Place']):
stab.columns(_("Place"), _("Gramps ID"))
for obj in database.iter_places():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'all sources'):
stab.columns(_("Source"))
elif (filter_name in ['all sources', 'Source']):
stab.columns(_("Source"), _("Gramps ID"))
for obj in database.iter_sources():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'all repositories'):
stab.columns(_("Repository"))
elif (filter_name in ['all repositories', 'Repository']):
stab.columns(_("Repository"), _("Gramps ID"))
for obj in database.iter_repositories():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'all media'):
stab.columns(_("Media"))
elif (filter_name in ['all media', 'MediaObject']):
stab.columns(_("Media"), _("Gramps ID"))
for obj in database.iter_media_objects():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'all notes'):
stab.columns(_("Note"))
elif (filter_name in ['all notes', 'Note']):
stab.columns(_("Note"), _("Gramps ID"))
for obj in database.iter_notes():
stab.row(obj)
stab.row(obj, obj.gramps_id)
matches += 1
elif (filter_name == 'males'):
stab.columns(_("Person"), _("Birth Date"), _("Name type"))