Merge pull request #349 from prculley/filters

Add Progress indicators to filters and reports
This commit is contained in:
Sam Manzi 2017-02-12 15:39:35 +11:00 committed by GitHub
commit ace8cb415f
13 changed files with 93 additions and 7 deletions

View File

@ -106,6 +106,8 @@ def find_deep_relations(db, user, person, path, seen, target_people):
if handle in seen: if handle in seen:
return [] return []
seen.append(handle) seen.append(handle)
if user:
user.step_progress()
return_paths = [] return_paths = []
person_path = path + [handle] person_path = path + [handle]
@ -118,8 +120,6 @@ def find_deep_relations(db, user, person, path, seen, target_people):
for family_person in family_people: for family_person in family_people:
pers = db.get_person_from_handle(family_person) pers = db.get_person_from_handle(family_person)
return_paths += find_deep_relations(db, user, pers, person_path, seen, target_people) return_paths += find_deep_relations(db, user, pers, person_path, seen, target_people)
if user:
user.step_progress()
return return_paths return return_paths

View File

@ -64,12 +64,20 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
self.with_people = [] self.with_people = []
filt = MatchesFilter(self.list) filt = MatchesFilter(self.list)
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for handle in db.iter_person_handles(): for handle in db.iter_person_handles():
person = db.get_person_from_handle(handle) person = db.get_person_from_handle(handle)
if user:
user.step_progress()
if person and filt.apply(db, person): if person and filt.apply(db, person):
#store all people in the filter so as to compare later #store all people in the filter so as to compare later
self.with_people.append(person.handle) self.with_people.append(person.handle)
#fill list of ancestor of person if not present yet #fill list of ancestor of person if not present yet
if handle not in self.ancestor_cache: if handle not in self.ancestor_cache:
self.add_ancs(db, person) self.add_ancs(db, person)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()

View File

@ -62,9 +62,17 @@ class IsAncestorOfFilterMatch(IsAncestorOf):
filt = MatchesFilter(self.list[0:1]) filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person): if filt.apply(db, person):
self.init_ancestor_list(db, person, first) self.init_ancestor_list(db, person, first)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()
def reset(self): def reset(self):

View File

@ -53,9 +53,17 @@ class IsChildOfFilterMatch(Rule):
self.map = set() self.map = set()
filt = MatchesFilter(self.list) filt = MatchesFilter(self.list)
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person): if filt.apply(db, person):
self.init_list(person) self.init_list(person)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()
def reset(self): def reset(self):

View File

@ -55,8 +55,16 @@ class IsDescendantFamilyOfFilterMatch(IsDescendantFamilyOf):
filt = MatchesFilter(self.list[0:1]) filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person): if filt.apply(db, person):
self.add_matches(person) self.add_matches(person)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()

View File

@ -62,9 +62,17 @@ class IsDescendantOfFilterMatch(IsDescendantOf):
filt = MatchesFilter(self.list[0:1]) filt = MatchesFilter(self.list[0:1])
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person): if filt.apply(db, person):
self.init_list(person, first) self.init_list(person, first)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()
def reset(self): def reset(self):

View File

@ -53,9 +53,17 @@ class IsParentOfFilterMatch(Rule):
self.map = set() self.map = set()
filt = MatchesFilter(self.list) filt = MatchesFilter(self.list)
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply(db, person): if filt.apply(db, person):
self.init_list(person) self.init_list(person)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()
def reset(self): def reset(self):

View File

@ -52,9 +52,17 @@ class IsSiblingOfFilterMatch(Rule):
self.map = set() self.map = set()
filt = MatchesFilter(self.list) filt = MatchesFilter(self.list)
filt.requestprepare(db, user) filt.requestprepare(db, user)
if user:
user.begin_progress(self.category,
_('Retrieving all sub-filter matches'),
db.get_number_of_people())
for person in db.iter_people(): for person in db.iter_people():
if user:
user.step_progress()
if filt.apply (db, person): if filt.apply (db, person):
self.init_list (person) self.init_list (person)
if user:
user.end_progress()
filt.requestreset() filt.requestreset()
def reset(self): def reset(self):
@ -67,8 +75,9 @@ class IsSiblingOfFilterMatch(Rule):
if not person: if not person:
return return
fam_id = person.get_main_parents_family_handle() fam_id = person.get_main_parents_family_handle()
fam = self.db.get_family_from_handle(fam_id) if fam_id:
if fam: fam = self.db.get_family_from_handle(fam_id)
self.map.update(child_ref.ref if fam:
for child_ref in fam.get_child_ref_list() self.map.update(
child_ref.ref for child_ref in fam.get_child_ref_list()
if child_ref and child_ref.ref != person.handle) if child_ref and child_ref.ref != person.handle)

View File

@ -45,6 +45,7 @@ class Report:
def __init__(self, database, options_class, user): def __init__(self, database, options_class, user):
self.database = database self.database = database
self.options_class = options_class self.options_class = options_class
self._user = user
self.doc = options_class.get_document() self.doc = options_class.get_document()

View File

@ -587,7 +587,8 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
self.__total += items self.__total += items
assert not skip assert not skip
if dfilter: if dfilter:
for handle in dfilter.apply(self.db, user=User()): for handle in dfilter.apply(self.db,
user=User(parent=self.uistate.window)):
status_ppl.heartbeat() status_ppl.heartbeat()
data = data_map(handle) data = data_map(handle)
add_func(handle, data) add_func(handle, data)

View File

@ -193,8 +193,14 @@ class RelGraphReport(Report):
self._db.iter_person_handles()) self._db.iter_person_handles())
if len(person_handles) > 1: if len(person_handles) > 1:
if self._user:
self._user.begin_progress(_("Relationship Graph"),
_("Generating report"),
len(person_handles) * 2)
self.add_persons_and_families(person_handles) self.add_persons_and_families(person_handles)
self.add_child_links_to_families(person_handles) self.add_child_links_to_families(person_handles)
if self._user:
self._user.end_progress()
def add_child_links_to_families(self, person_handles): def add_child_links_to_families(self, person_handles):
""" """
@ -205,6 +211,8 @@ class RelGraphReport(Report):
person_dict = dict([handle, 1] for handle in person_handles) person_dict = dict([handle, 1] for handle in person_handles)
for person_handle in person_handles: for person_handle in person_handles:
if self._user:
self._user.step_progress()
person = self._db.get_person_from_handle(person_handle) person = self._db.get_person_from_handle(person_handle)
p_id = person.get_gramps_id() p_id = person.get_gramps_id()
for fam_handle in person.get_parent_family_handle_list(): for fam_handle in person.get_parent_family_handle_list():
@ -261,6 +269,8 @@ class RelGraphReport(Report):
# so we don't do it twice # so we don't do it twice
families_done = {} families_done = {}
for person_handle in person_handles: for person_handle in person_handles:
if self._user:
self._user.step_progress()
# determine per person if we use HTML style label # determine per person if we use HTML style label
if self.includeimg: if self.includeimg:
self.use_html_output = True self.use_html_output = True

View File

@ -812,12 +812,21 @@ class IndivCompleteReport(Report):
raise ReportError(_('Empty report'), raise ReportError(_('Empty report'),
_('You did not specify anybody')) _('You did not specify anybody'))
if self._user:
self._user.begin_progress(_("Complete Individual Report"),
_("Generating report"),
len(ind_list))
for count, person_handle in enumerate(ind_list): for count, person_handle in enumerate(ind_list):
if self._user:
self._user.step_progress()
self.person = self._db.get_person_from_handle(person_handle) self.person = self._db.get_person_from_handle(person_handle)
if self.person is None: if self.person is None:
continue continue
self.family_notes_list = [] self.family_notes_list = []
self.write_person(count) self.write_person(count)
if self._user:
self._user.end_progress()
def write_person(self, count): def write_person(self, count):
""" write a person """ """ write a person """

View File

@ -98,7 +98,13 @@ class NoteLinkReport(Report):
self.doc.end_row() self.doc.end_row()
if self._user:
self._user.begin_progress(_("Note Link Check Report"),
_("Generating report"),
self.database.get_number_of_notes())
for note in self.database.iter_notes(): for note in self.database.iter_notes():
if self._user:
self._user.step_progress()
for (ldomain, ltype, lprop, lvalue) in note.get_links(): for (ldomain, ltype, lprop, lvalue) in note.get_links():
if ldomain == "gramps": if ldomain == "gramps":
tagtype = _(ltype) tagtype = _(ltype)
@ -141,6 +147,8 @@ class NoteLinkReport(Report):
self.doc.end_cell() self.doc.end_cell()
self.doc.end_row() self.doc.end_row()
if self._user:
self._user.end_progress()
self.doc.end_table() self.doc.end_table()