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: else:
return "Error: invalid object class: '%s'" % object_class 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): def get_link(self, object_class, prop, value):
""" """
Given a object_class, prop, and value return the object. 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): def button_press_event(self, treeview, event):
import gtk import gtk
if event.button == 3: index = None
x = int(event.x) button_code = None
y = int(event.y) event_time = None
path_info = treeview.get_path_at_pos(x, y) func = None
if path_info is not None: if type(event) == bool: # enter
path, col, cellx, celly = path_info 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.grab_focus()
treeview.set_cursor(path, col, 0) treeview.set_cursor(path, col, 0)
selection = treeview.get_selection() index = store.get_value(node, 0) # index Below,
store, node = selection.get_selected() # you need index, treeview, path, button_code,
index = None # func, and event_time
if node: if index is not None:
index = store.get_value(node, 0) # index popup = gtk.Menu()
popup = gtk.Menu() if (index is not None and self.__link[index]):
if (index is not None and self.__link[index]): # See details (edit, etc):
# See details (edit, etc): objclass, handle = self.__link[index]
objclass, handle = self.__link[index] menu_item = gtk.MenuItem(_("See %s details") % objclass)
menu_item = gtk.MenuItem(_("See %s details") % objclass) menu_item.connect("activate",
menu_item.connect("activate", lambda widget: self.on_table_doubleclick(treeview))
lambda widget: self.on_table_doubleclick(treeview, popup.append(menu_item)
path, 0)) menu_item.show()
popup.append(menu_item) # Add other items to menu:
menu_item.show() if (self._callback_leftclick or
# Add other items to menu: (index is not None and self.__link[index])):
if (self._callback_leftclick or objclass, handle = self.__link[index]
(index is not None and self.__link[index])): if objclass == 'Person':
objclass, handle = self.__link[index] menu_item = gtk.MenuItem(_("Make Active Person"))
if objclass == 'Person': menu_item.connect("activate",
menu_item = gtk.MenuItem(_("Make Active Person")) lambda widget: self.on_table_click(treeview))
menu_item.connect("activate", popup.append(menu_item)
lambda widget: self.on_table_click(treeview)) menu_item.show()
popup.append(menu_item) if (self.simpledoc.doc.dbstate.db !=
menu_item.show() self.simpledoc.doc.dbstate.db.basedb and
# Show the popup menu: (index is not None and self.__link[index])):
popup.popup(None, None, None, event.button, event.time) objclass, handle = self.__link[index]
return True 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 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 Handle events on tables. obj is a treeview
""" """
@ -139,68 +181,76 @@ class SimpleTable(object):
objclass, handle = self.__link[index] objclass, handle = self.__link[index]
if objclass == 'Person': if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle) person = self.access.dbase.get_person_from_handle(handle)
try: if person:
EditPerson(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], person) EditPerson(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], person)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Event': elif objclass == 'Event':
event = self.access.dbase.get_event_from_handle(handle) event = self.access.dbase.get_event_from_handle(handle)
try: if event:
EditEvent(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], event) EditEvent(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], event)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Family': elif objclass == 'Family':
ref = self.access.dbase.get_family_from_handle(handle) ref = self.access.dbase.get_family_from_handle(handle)
try: if ref:
EditFamily(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditFamily(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Source': elif objclass == 'Source':
ref = self.access.dbase.get_source_from_handle(handle) ref = self.access.dbase.get_source_from_handle(handle)
try: if ref:
EditSource(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditSource(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Place': elif objclass == 'Place':
ref = self.access.dbase.get_place_from_handle(handle) ref = self.access.dbase.get_place_from_handle(handle)
try: if ref:
EditPlace(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditPlace(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Repository': elif objclass == 'Repository':
ref = self.access.dbase.get_repository_from_handle(handle) ref = self.access.dbase.get_repository_from_handle(handle)
try: if ref:
EditRepository(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditRepository(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'Note': elif objclass == 'Note':
ref = self.access.dbase.get_note_from_handle(handle) ref = self.access.dbase.get_note_from_handle(handle)
try: if ref:
EditNote(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditNote(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass in ['Media', 'MediaObject']: elif objclass in ['Media', 'MediaObject']:
ref = self.access.dbase.get_object_from_handle(handle) ref = self.access.dbase.get_object_from_handle(handle)
try: if ref:
EditMedia(self.simpledoc.doc.dbstate, try:
self.simpledoc.doc.uistate, [], ref) EditMedia(self.simpledoc.doc.dbstate,
return True # handled event self.simpledoc.doc.uistate, [], ref)
except Errors.WindowActiveError: return True # handled event
pass except Errors.WindowActiveError:
pass
elif objclass == 'PersonList': elif objclass == 'PersonList':
from QuickReports import run_quick_report_by_name from QuickReports import run_quick_report_by_name
run_quick_report_by_name(self.simpledoc.doc.dbstate, run_quick_report_by_name(self.simpledoc.doc.dbstate,
@ -277,48 +327,35 @@ class SimpleTable(object):
retval.append(item) retval.append(item)
self.row_sort_val(col, item) self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person): elif isinstance(item, gen.lib.Person):
name = self.access.name(item) retval.append(self.access.describe(item))
retval.append(name)
if (self.__link_col == col or link is None): if (self.__link_col == col or link is None):
link = ('Person', item.handle) link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family): elif isinstance(item, gen.lib.Family):
father = self.access.father(item) retval.append(self.access.describe(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)
if (self.__link_col == col or link is None): if (self.__link_col == col or link is None):
link = ('Family', item.handle) link = ('Family', item.handle)
elif isinstance(item, gen.lib.Source): 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): if (self.__link_col == col or link is None):
link = ('Source', item.handle) link = ('Source', item.handle)
elif isinstance(item, gen.lib.Event): elif isinstance(item, gen.lib.Event):
name = self.access.event_type(item) retval.append(self.access.describe(item))
retval.append(name)
if (self.__link_col == col or link is None): if (self.__link_col == col or link is None):
link = ('Event', item.handle) link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject): 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): if (self.__link_col == col or link is None):
link = ('Media', item.handle) link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place): 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): if (self.__link_col == col or link is None):
link = ('Place', item.handle) link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository): 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): if (self.__link_col == col or link is None):
link = ('Repository', item.handle) link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note): 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): if (self.__link_col == col or link is None):
link = ('Note', item.handle) link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date): elif isinstance(item, gen.lib.Date):
@ -436,6 +473,7 @@ class SimpleTable(object):
#treeview.connect('row-activated', on_table_doubleclick, self) #treeview.connect('row-activated', on_table_doubleclick, self)
#treeview.connect('cursor-changed', on_table_click, self) #treeview.connect('cursor-changed', on_table_click, self)
treeview.connect('button-press-event', self.button_press_event) treeview.connect('button-press-event', self.button_press_event)
treeview.connect('select-cursor-row', self.button_press_event)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
types = [int] # index types = [int] # index
cnt = 0 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("Double-click row to see selected items.")
sdoc.paragraph("") sdoc.paragraph("")
stab.columns(_("Object"), _("Count/Total")) stab.columns(_("Object"), _("Count/Total"))
stab.row([_("People"), "Filter", "all people"], stab.row([_("People"), "Filter", "Person"],
"%d/%d" % (len(database.get_person_handles()), "%d/%d" % (len(database.get_person_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_family_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_event_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_place_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_source_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_repository_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_media_object_handles()),
len(database.basedb.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()), "%d/%d" % (len(database.get_note_handles()),
len(database.basedb.get_note_handles()))) len(database.basedb.get_note_handles())))
sdoc.paragraph("") sdoc.paragraph("")
@ -106,54 +106,118 @@ def run(database, document, filter_name, *args, **kwargs):
sdoc.title(_("Filtering on %s") % _(filter_name)) sdoc.title(_("Filtering on %s") % _(filter_name))
sdoc.paragraph("") sdoc.paragraph("")
matches = 0 matches = 0
if (filter_name == 'people not in filter'): if (filter_name == 'Inverse Person'):
stab.columns(_("Person"), _("Birth Date"), _("Name type")) sdb.dbase = database.basedb
proxy_handles = dict([(handle,1) for handle in database.iter_person_handles()]) 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(): for person in database.basedb.iter_people():
if person.handle not in proxy_handles: if person.handle not in proxy_handles:
stab.row(person, sdb.birth_or_fallback(person), stab.row(person, person.gramps_id,
str(person.get_primary_name().get_type())) sdb.birth_or_fallback(person))
matches += 1 matches += 1
elif (filter_name == 'all people'): elif (filter_name == 'Inverse Family'):
stab.columns(_("Person"), _("Birth Date"), _("Name type")) 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(): for person in database.iter_people():
stab.row(person, sdb.birth_or_fallback(person), stab.row(person, person.gramps_id, sdb.birth_or_fallback(person))
str(person.get_primary_name().get_type()))
matches += 1 matches += 1
elif (filter_name == 'all families'): elif (filter_name in ['all families', 'Family']):
stab.columns(_("Family")) stab.columns(_("Family"), _("Gramps ID"))
for family in database.iter_families(): for family in database.iter_families():
stab.row(family) stab.row(family, family.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all events'): elif (filter_name in ['all events', 'Event']):
stab.columns(_("Event")) stab.columns(_("Event"), _("Gramps ID"))
for obj in database.iter_events(): for obj in database.iter_events():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all places'): elif (filter_name in ['all places', 'Place']):
stab.columns(_("Place")) stab.columns(_("Place"), _("Gramps ID"))
for obj in database.iter_places(): for obj in database.iter_places():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all sources'): elif (filter_name in ['all sources', 'Source']):
stab.columns(_("Source")) stab.columns(_("Source"), _("Gramps ID"))
for obj in database.iter_sources(): for obj in database.iter_sources():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all repositories'): elif (filter_name in ['all repositories', 'Repository']):
stab.columns(_("Repository")) stab.columns(_("Repository"), _("Gramps ID"))
for obj in database.iter_repositories(): for obj in database.iter_repositories():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all media'): elif (filter_name in ['all media', 'MediaObject']):
stab.columns(_("Media")) stab.columns(_("Media"), _("Gramps ID"))
for obj in database.iter_media_objects(): for obj in database.iter_media_objects():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'all notes'): elif (filter_name in ['all notes', 'Note']):
stab.columns(_("Note")) stab.columns(_("Note"), _("Gramps ID"))
for obj in database.iter_notes(): for obj in database.iter_notes():
stab.row(obj) stab.row(obj, obj.gramps_id)
matches += 1 matches += 1
elif (filter_name == 'males'): elif (filter_name == 'males'):
stab.columns(_("Person"), _("Birth Date"), _("Name type")) stab.columns(_("Person"), _("Birth Date"), _("Name type"))