From 679392ab4b0a2c1c7b848da29343aca04f398b18 Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Mon, 15 Dec 2008 21:42:58 +0000 Subject: [PATCH] Add an option progress meter argument to GenericFilter.apply If present it must be an instance of Utils.ProgressMeter. * src/Filters/_GenericFilter.py * src/plugins/WebCal.py * src/plugins/NarrativeWeb.py svn: r11481 --- src/Filters/_GenericFilter.py | 29 +++++++++++++++++++---------- src/plugins/NarrativeWeb.py | 4 ++-- src/plugins/WebCal.py | 6 +++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Filters/_GenericFilter.py b/src/Filters/_GenericFilter.py index 4fa0b4760..bd6ec7dc1 100644 --- a/src/Filters/_GenericFilter.py +++ b/src/Filters/_GenericFilter.py @@ -112,7 +112,7 @@ class GenericFilter: def find_from_handle(self, db, handle): return db.get_person_from_handle(handle) - def check_func(self, db, id_list, task): + def check_func(self, db, id_list, task, progress=None): final_list = [] if id_list is None: @@ -121,6 +121,8 @@ class GenericFilter: while data: person = self.make_obj() person.unserialize(data[1]) + if progress: + progress.step() if task(db, person) != self.invert: final_list.append(data[0]) data = cursor.next() @@ -128,11 +130,13 @@ class GenericFilter: else: for handle in id_list: person = self.find_from_handle(db, handle) + if progress: + progress.step() if task(db, person) != self.invert: final_list.append(handle) return final_list - def check_and(self, db, id_list): + def check_and(self, db, id_list, progress=None): final_list = [] flist = self.flist if id_list is None: @@ -141,6 +145,8 @@ class GenericFilter: while data: person = self.make_obj() person.unserialize(data[1]) + if progress: + progress.step() val = True for rule in flist: if not rule.apply(db, person): @@ -153,6 +159,8 @@ class GenericFilter: else: for handle in id_list: person = self.find_from_handle(db, handle) + if progress: + progress.step() val = True for rule in flist: if not rule.apply(db, person): @@ -162,14 +170,14 @@ class GenericFilter: final_list.append(handle) return final_list - def check_or(self, db, id_list): - return self.check_func(db, id_list, self.or_test) + def check_or(self, db, id_list, progress=None): + return self.check_func(db, id_list, self.or_test, progress) - def check_one(self, db, id_list): - return self.check_func(db, id_list, self.one_test) + def check_one(self, db, id_list, progress=None): + return self.check_func(db, id_list, self.one_test, progress) - def check_xor(self, db, id_list): - return self.check_func(db, id_list, self.xor_test) + def check_xor(self, db, id_list, progress=None): + return self.check_func(db, id_list, self.xor_test, progress) def xor_test(self, db, person): test = False @@ -202,11 +210,12 @@ class GenericFilter: def check(self, db, handle): return self.get_check_func()(db, [handle]) - def apply(self, db, id_list=None): + # progress is optional. If present it must be an instance of Utils.ProgressMeter + def apply(self, db, id_list=None, progress=None): m = self.get_check_func() for rule in self.flist: rule.prepare(db) - res = m(db, id_list) + res = m(db, id_list, progress) for rule in self.flist: rule.reset() return res diff --git a/src/plugins/NarrativeWeb.py b/src/plugins/NarrativeWeb.py index 0d8d8f47b..21102b39e 100644 --- a/src/plugins/NarrativeWeb.py +++ b/src/plugins/NarrativeWeb.py @@ -2752,8 +2752,8 @@ class NavWebReport(Report): # gets the person list and applies the requested filter ind_list = self.database.get_person_handles(sort_handles=False) - self.progress.set_pass(_('Filtering'), 1) - ind_list = self.filter.apply(self.database, ind_list) + self.progress.set_pass(_('Applying Filter...'), len(ind_list)) + ind_list = self.filter.apply(self.database, ind_list, self.progress) return ind_list def copy_css(self, css_file): diff --git a/src/plugins/WebCal.py b/src/plugins/WebCal.py index 9f59c7569..4c07dcd76 100644 --- a/src/plugins/WebCal.py +++ b/src/plugins/WebCal.py @@ -1193,9 +1193,9 @@ class WebCalReport(Report): if person is dead, then do nothing more!!! """ - self.progress.set_pass(_('Applying Filter...'), '') - people = self.filter.apply(self.database, - self.database.get_person_handles(sort_handles=False)) + people = self.database.get_person_handles(sort_handles=False) + self.progress.set_pass(_('Applying Filter...'), len(people)) + people = self.filter.apply(self.database, people, self.progress) self.progress.set_pass(_("Reading database..."), len(people)) for person_handle in people: