Contribution from Robert Chéramy <robert@cheramy.net>. Adds note filters to the filter proxy. Also adds note filters to the exporters.

svn: r11016
This commit is contained in:
Brian Matherly 2008-09-04 11:46:43 +00:00
parent 6c05a92cbf
commit 0254a5177f
5 changed files with 179 additions and 34 deletions

View File

@ -3,6 +3,7 @@
# #
# Copyright (C) 2007-2008 Donald N. Allingham # Copyright (C) 2007-2008 Donald N. Allingham
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -55,21 +56,30 @@ class WriterOptionBox:
self.person = person self.person = person
self.private = 0 self.private = 0
self.restrict = 0 self.restrict = 0
self.unlinked = 0
self.cfilter = None self.cfilter = None
self.nfilter = None
self.restrict_check = None self.restrict_check = None
self.private_check = None self.private_check = None
self.unlinked_check = None self.unlinked_check = None
self.filter_obj = None self.filter_obj = None
self.filter_note = None
def get_option_box(self): def get_option_box(self):
"""Build up a gtk.Table that contains the standard options.""" """Build up a gtk.Table that contains the standard options."""
table = gtk.Table(4, 2) table = gtk.Table(5, 2)
self.filter_obj = gtk.ComboBox() self.filter_obj = gtk.ComboBox()
label = gtk.Label(_('Filt_er')) label = gtk.Label(_('_Person Filter'))
label.set_use_underline(True) label.set_use_underline(True)
label.set_mnemonic_widget(self.filter_obj) label.set_mnemonic_widget(self.filter_obj)
# Objects for choosing a Note filter
self.filter_note = gtk.ComboBox()
label_note = gtk.Label(_('_Note Filter'))
label_note.set_use_underline(True)
label_note.set_mnemonic_widget(self.filter_note)
self.private_check = gtk.CheckButton( self.private_check = gtk.CheckButton(
_('_Do not include records marked private')) _('_Do not include records marked private'))
self.restrict_check = gtk.CheckButton( self.restrict_check = gtk.CheckButton(
@ -86,10 +96,13 @@ class WriterOptionBox:
table.set_col_spacings(6) table.set_col_spacings(6)
table.attach(label, 0, 1, 0, 1, xoptions=0, yoptions=0) table.attach(label, 0, 1, 0, 1, xoptions=0, yoptions=0)
table.attach(self.filter_obj, 1, 2, 0, 1, yoptions=0) table.attach(self.filter_obj, 1, 2, 0, 1, yoptions=0)
table.attach(self.private_check, 1, 2, 1, 2, yoptions=0) table.attach(label_note, 0, 1, 1, 2, xoptions =0, yoptions=0)
table.attach(self.restrict_check, 1, 2, 2, 3, yoptions=0) table.attach(self.filter_note, 1, 2, 1, 2, yoptions=0)
table.attach(self.unlinked_check, 1, 2, 3, 4, yoptions=0) table.attach(self.private_check, 1, 2, 2, 3, yoptions=0)
table.attach(self.restrict_check, 1, 2, 3, 4, yoptions=0)
table.attach(self.unlinked_check, 1, 2, 4, 5, yoptions=0)
# Populate the Person Filter
entire_db = GenericFilter() entire_db = GenericFilter()
entire_db.set_name(_("Entire Database")) entire_db.set_name(_("Entire Database"))
the_filters = [entire_db] the_filters = [entire_db]
@ -110,6 +123,19 @@ class WriterOptionBox:
self.filter_obj.set_model(model) self.filter_obj.set_model(model)
self.filter_obj.set_active(0) self.filter_obj.set_active(0)
# Populate the Notes Filter
notes_filters = [entire_db]
notes_filters.extend(CustomFilters.get_filters('Note'))
notes_model = gtk.ListStore(gobject.TYPE_STRING, object)
for item in notes_filters:
notes_model.append(row=[item.get_name(), item])
notes_cell = gtk.CellRendererText()
self.filter_note.pack_start(notes_cell, True)
self.filter_note.add_attribute(notes_cell, 'text', 0)
self.filter_note.set_model(notes_model)
self.filter_note.set_active(0)
table.show() table.show()
return table return table
@ -144,6 +170,7 @@ class WriterOptionBox:
private = privacy requested private = privacy requested
restrict = restrict information on living peoplel restrict = restrict information on living peoplel
cfitler = return the GenericFilter selected cfitler = return the GenericFilter selected
nfilter = return the NoteFilter selected
unlinked = restrict unlinked records unlinked = restrict unlinked records
""" """
@ -160,3 +187,8 @@ class WriterOptionBox:
node = self.filter_obj.get_active_iter() node = self.filter_obj.get_active_iter()
self.cfilter = model[node][1] self.cfilter = model[node][1]
model = self.filter_note.get_model()
node = self.filter_note.get_active_iter()
self.nfilter = model[node][1]

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -340,6 +341,9 @@ class GedcomWriter(BasicUtils.UpdateCallback):
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
self.progress_cnt += 1 self.progress_cnt += 1
if not option_box.nfilter.is_empty():
self.progress_cnt += 1
if option_box.unlinked: if option_box.unlinked:
self.progress_cnt += 1 self.progress_cnt += 1
@ -363,14 +367,22 @@ class GedcomWriter(BasicUtils.UpdateCallback):
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
# If the filter returned by cfilter is not empty, apply the # If the filter returned by cfilter is not empty, apply the
# FilterProxyDb # FilterProxyDb (Person Filter)
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
self.reset(_("Applying selected filter")) self.reset(_("Applying selected person filter"))
self.progress_cnt += 1 self.progress_cnt += 1
self.update(self.progress_cnt) self.update(self.progress_cnt)
self.dbase = gen.proxy.FilterProxyDb( self.dbase = gen.proxy.FilterProxyDb(
self.dbase, option_box.cfilter) self.dbase, option_box.cfilter)
# Apply the Note Filter
if not option_box.nfilter.is_empty():
self.reset(_("Applying selected note filter"))
self.progress_cnt += 1
self.update(self.progress_cnt)
self.dbase = gen.proxy.FilterProxyDb(
self.dbase, note_filter=option_box.nfilter)
# Apply the ReferencedProxyDb to remove any objects not referenced # Apply the ReferencedProxyDb to remove any objects not referenced
# after any of the other proxies have been applied # after any of the other proxies have been applied
if option_box.unlinked: if option_box.unlinked:

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2007 Donald N. Allingham # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -88,9 +89,15 @@ def export_data(database, filename, person, option_box, callback=None):
database = gen.proxy.LivingProxyDb( database = gen.proxy.LivingProxyDb(
database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
# Apply the Person Filter
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
database = gen.proxy.FilterProxyDb(database, option_box.cfilter) database = gen.proxy.FilterProxyDb(database, option_box.cfilter)
# Apply the Note Filter
if not option_box.nfilter.is_empty():
database = gen.proxy.FilterProxyDb(
database, note_filter=option_box.nfilter)
# Apply the ReferencedProxyDb to remove any objects not referenced # Apply the ReferencedProxyDb to remove any objects not referenced
# after any of the other proxies have been applied # after any of the other proxies have been applied
if option_box.unlinked: if option_box.unlinked:

View File

@ -3,6 +3,7 @@
# #
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -40,7 +41,8 @@ class FilterProxyDb(ProxyDbBase):
the user. the user.
""" """
def __init__(self, db, person_filter=None, event_filter=None): def __init__(self, db, person_filter=None, event_filter=None,
note_filter=None):
""" """
Create a new PrivateProxyDb instance. Create a new PrivateProxyDb instance.
""" """
@ -59,6 +61,12 @@ class FilterProxyDb(ProxyDbBase):
else: else:
self.elist = self.db.get_event_handles() self.elist = self.db.get_event_handles()
if note_filter:
self.nlist = set(note_filter.apply(
self.db, self.db.get_note_handles()))
else:
self.nlist = self.db.get_note_handles()
self.flist = set() self.flist = set()
for handle in list(self.plist): for handle in list(self.plist):
person = self.db.get_person_from_handle(handle) person = self.db.get_person_from_handle(handle)
@ -98,6 +106,9 @@ class FilterProxyDb(ProxyDbBase):
if dref in new_eref_list: if dref in new_eref_list:
person.set_death_ref(dref) person.set_death_ref(dref)
# Filter notes out
self.sanitize_person(person)
return person return person
else: else:
return None return None
@ -107,21 +118,32 @@ class FilterProxyDb(ProxyDbBase):
Finds a Source in the database from the passed gramps' ID. Finds a Source in the database from the passed gramps' ID.
If no such Source exists, None is returned. If no such Source exists, None is returned.
""" """
return self.db.get_source_from_handle(handle) source = self.db.get_source_from_handle(handle)
# Filter notes out
self.sanitize_notebase(source)
return source
def get_object_from_handle(self, handle): def get_object_from_handle(self, handle):
""" """
Finds an Object in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed GRAMPS' handle.
If no such Object exists, None is returned. If no such Object exists, None is returned.
""" """
return self.db.get_object_from_handle(handle) media = self.db.get_object_from_handle(handle)
# Filter notes out
self.sanitize_notebase(media)
self.sanitize_sourcebase(media)
return media
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
""" """
Finds a Place in the database from the passed gramps' ID. Finds a Place in the database from the passed GRAMPS' handle.
If no such Place exists, None is returned. If no such Place exists, None is returned.
""" """
return self.db.get_place_from_handle(handle) place = self.db.get_place_from_handle(handle)
# Filter notes out
self.sanitize_notebase(place)
self.sanitize_sourcebase(place)
return place
def get_event_from_handle(self, handle): def get_event_from_handle(self, handle):
""" """
@ -129,7 +151,11 @@ class FilterProxyDb(ProxyDbBase):
If no such Event exists, None is returned. If no such Event exists, None is returned.
""" """
if handle in self.elist: if handle in self.elist:
return self.db.get_event_from_handle(handle) event = self.db.get_event_from_handle(handle)
# Filter all notes out
self.sanitize_notebase(event)
self.sanitize_sourcebase(event)
return event
else: else:
return None return None
@ -154,6 +180,10 @@ class FilterProxyDb(ProxyDbBase):
clist = [ cref for cref in family.get_child_ref_list() clist = [ cref for cref in family.get_child_ref_list()
if cref.ref in self.plist ] if cref.ref in self.plist ]
family.set_child_ref_list(clist) family.set_child_ref_list(clist)
# Filter notes out
self.sanitize_notebase(family)
self.sanitize_sourcebase(family)
return family return family
else: else:
return None return None
@ -163,14 +193,21 @@ class FilterProxyDb(ProxyDbBase):
Finds a Repository in the database from the passed gramps' ID. Finds a Repository in the database from the passed gramps' ID.
If no such Repository exists, None is returned. If no such Repository exists, None is returned.
""" """
return self.db.get_repository_from_handle(handle) repository = self.db.get_repository_from_handle(handle)
# Filter notes out
self.sanitize_notebase(repository)
self.sanitize_addressbase(repository)
return repository
def get_note_from_handle(self, handle): def get_note_from_handle(self, handle):
""" """
Finds a Note in the database from the passed gramps' ID. Finds a Note in the database from the passed gramps' ID.
If no such Note exists, None is returned. If no such Note exists, None is returned.
""" """
if handle in self.nlist:
return self.db.get_note_from_handle(handle) return self.db.get_note_from_handle(handle)
else:
return None
def get_person_from_gramps_id(self, val): def get_person_from_gramps_id(self, val):
""" """
@ -178,17 +215,15 @@ class FilterProxyDb(ProxyDbBase):
If no such Person exists, None is returned. If no such Person exists, None is returned.
""" """
person = self.db.get_person_from_gramps_id(val) person = self.db.get_person_from_gramps_id(val)
if person.get_handle() not in self.plist: return self.get_person_from_handle(person.get_handle())
return None
else:
return person
def get_family_from_gramps_id(self, val): def get_family_from_gramps_id(self, val):
""" """
Finds a Family in the database from the passed GRAMPS ID. Finds a Family in the database from the passed GRAMPS ID.
If no such Family exists, None is returned. If no such Family exists, None is returned.
""" """
return self.db.get_family_from_gramps_id(val) family = self.db.get_family_from_gramps_id(val)
return self.get_family_from_handle(family.get_handle())
def get_event_from_gramps_id(self, val): def get_event_from_gramps_id(self, val):
""" """
@ -196,51 +231,54 @@ class FilterProxyDb(ProxyDbBase):
If no such Event exists, None is returned. If no such Event exists, None is returned.
""" """
event = self.db.get_event_from_gramps_id(val) event = self.db.get_event_from_gramps_id(val)
if event.get_handle() not in self.elist: return self.get_event_from_handle(event.get_handle())
return None
else:
return event
def get_place_from_gramps_id(self, val): def get_place_from_gramps_id(self, val):
""" """
Finds a Place in the database from the passed gramps' ID. Finds a Place in the database from the passed gramps' ID.
If no such Place exists, None is returned. If no such Place exists, None is returned.
""" """
return self.db.get_place_from_gramps_id(val) place = self.db.get_place_from_gramps_id(val)
return self.get_place_from_handle(place.get_handle())
def get_source_from_gramps_id(self, val): def get_source_from_gramps_id(self, val):
""" """
Finds a Source in the database from the passed gramps' ID. Finds a Source in the database from the passed gramps' ID.
If no such Source exists, None is returned. If no such Source exists, None is returned.
""" """
return self.db.get_source_from_gramps_id(val) source = self.db.get_source_from_gramps_id(val)
return self.get_source_from_handle(source.get_handle())
def get_object_from_gramps_id(self, val): def get_object_from_gramps_id(self, val):
""" """
Finds a MediaObject in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed gramps' ID.
If no such MediaObject exists, None is returned. If no such MediaObject exists, None is returned.
""" """
return self.db.get_object_from_gramps_id(val) media = self.db.get_object_from_gramps_id(val)
return self.get_object_from_handle(media.get_handle())
def get_repository_from_gramps_id(self, val): def get_repository_from_gramps_id(self, val):
""" """
Finds a Repository in the database from the passed gramps' ID. Finds a Repository in the database from the passed gramps' ID.
If no such Repository exists, None is returned. If no such Repository exists, None is returned.
""" """
return self.db.get_repository_from_gramps_id(val) repository = self.db.get_repository_from_gramps_id(val)
return self.get_repository_from_handle(repository.get_handle())
def get_note_from_gramps_id(self, val): def get_note_from_gramps_id(self, val):
""" """
Finds a Note in the database from the passed gramps' ID. Finds a Note in the database from the passed gramps' ID.
If no such Note exists, None is returned. If no such Note exists, None is returned.
""" """
return self.db.get_note_from_gramps_id(val) note = self.db.get_note_from_gramps_id(val)
return self.get_note_from_handle(note.get_handle())
def get_person_handles(self, sort_handles=True): def get_person_handles(self, sort_handles=True):
""" """
Return a list of database handles, one handle for each Person in Return a list of database handles, one handle for each Person in
the database. If sort_handles is True, the list is sorted by surnames the database. If sort_handles is True, the list is sorted by surnames
""" """
# FIXME: plist is not a sorted list of handles
return list(self.plist) return list(self.plist)
def get_place_handles(self, sort_handles=True): def get_place_handles(self, sort_handles=True):
@ -292,7 +330,7 @@ class FilterProxyDb(ProxyDbBase):
Return a list of database handles, one handle for each Note in Return a list of database handles, one handle for each Note in
the database. the database.
""" """
return self.db.get_note_handles() return list(self.nlist)
def get_researcher(self): def get_researcher(self):
"""returns the Researcher instance, providing information about """returns the Researcher instance, providing information about
@ -361,7 +399,7 @@ class FilterProxyDb(ProxyDbBase):
""" """
returns True if the handle exists in the current Note database. returns True if the handle exists in the current Note database.
""" """
return self.db.has_note_handle(handle) return handle in self.nlist
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
""" """
@ -384,4 +422,53 @@ class FilterProxyDb(ProxyDbBase):
> result_list = [i for i in find_backlink_handles(handle)] > result_list = [i for i in find_backlink_handles(handle)]
""" """
#FIXME: add a filter for returned handles (see private.py as an example)
return self.db.find_backlink_handles(handle, include_classes) return self.db.find_backlink_handles(handle, include_classes)
def sanitize_notebase(self, notebase):
"""
Filters notes out of the passed notebase object according to the Note Filter.
@param notebase: NoteBase object to clean
@type event: NoteBase
"""
note_list = notebase.get_note_list()
new_note_list = [ note for note in note_list if note in self.nlist ]
notebase.set_note_list(new_note_list)
def sanitize_sourcebase(self, sourcebase):
"""
Filter notes out of an SourceBase object
@param event: SourceBase object to clean
@type event: SourceBase
"""
sources = sourcebase.get_source_references()
for source in sources:
self.sanitize_notebase(source)
def sanitize_addressbase(self, addressbase):
addresses = addressbase.get_address_list()
for address in addresses:
self.sanitize_notebase(address)
self.sanitize_sourcebase(address)
def sanitize_person(self, person):
"""
Cleans filtered notes out of the passed person
@param event: Person object to clean
@type event: Person
"""
# Filter note references
self.sanitize_notebase(person)
self.sanitize_sourcebase(person)
self.sanitize_addressbase(person)
name = person.get_primary_name()
self.sanitize_notebase(name)
self.sanitize_sourcebase(name)
altnames = person.get_alternate_names()
for name in altnames:
self.sanitize_notebase(name)
self.sanitize_sourcebase(name)
self.sanitize_addressbase(person)

View File

@ -4,6 +4,7 @@
# Copyright (C) 2000-2008 Donald N. Allingham # Copyright (C) 2000-2008 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -78,9 +79,15 @@ def writeData(database, filename, person, option_box, callback=None):
database = gen.proxy.LivingProxyDb( database = gen.proxy.LivingProxyDb(
database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY) database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
# Apply the Person Filter
if not option_box.cfilter.is_empty(): if not option_box.cfilter.is_empty():
database = gen.proxy.FilterProxyDb(database, option_box.cfilter) database = gen.proxy.FilterProxyDb(database, option_box.cfilter)
# Apply the Note Filter
if not option_box.nfilter.is_empty():
database = gen.proxy.FilterProxyDb(
database, note_filter=option_box.nfilter)
# Apply the ReferencedProxyDb to remove any objects not referenced # Apply the ReferencedProxyDb to remove any objects not referenced
# after any of the other proxies have been applied # after any of the other proxies have been applied
if option_box.unlinked: if option_box.unlinked: