* src/FilterEditor/_EditFilter.py: Support invert attribute.

* src/Filters/_GenericFilter.py: Support invert attribute.
	* src/Filters/_FilterList.py (save): Save invert attribute.
	* src/Filters/_FilterParser.py (startElement): Parse invert attribute.


svn: r7126
This commit is contained in:
Alex Roitman 2006-08-05 01:06:33 +00:00
parent 19a3a5fea4
commit af33023e61
5 changed files with 30 additions and 9 deletions

View File

@ -1,4 +1,8 @@
2006-08-04 Alex Roitman <shura@gramps-project.org>
* src/FilterEditor/_EditFilter.py: Support invert attribute.
* src/Filters/_GenericFilter.py: Support invert attribute.
* src/Filters/_FilterList.py (save): Save invert attribute.
* src/Filters/_FilterParser.py (startElement): Parse invert attribute.
* src/Filters/Rules/Family/__init__.py (editor_rule_list): Import
and use new rule.
* src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new file.

View File

@ -86,6 +86,7 @@ class EditFilter(ManagedWindow.ManagedWindow):
self.fname = self.get_widget('filter_name')
self.logical = self.get_widget('rule_apply')
self.logical_not = self.get_widget('logical_not')
self.comment = self.get_widget('comment')
self.ok_btn = self.get_widget('ok')
self.edit_btn = self.get_widget('edit')
@ -109,6 +110,7 @@ class EditFilter(ManagedWindow.ManagedWindow):
self.logical.set_active(2)
else:
self.logical.set_active(0)
self.logical_not.set_active(self.filter.get_invert())
if self.filter.get_name():
self.fname.set_text(self.filter.get_name())
self.comment.set_text(self.filter.get_comment())
@ -159,6 +161,7 @@ class EditFilter(ManagedWindow.ManagedWindow):
else:
op = 'and'
self.filter.set_logical_op(op)
self.filter.set_invert(self.logical_not.get_active())
self.filterdb.add(self.space,self.filter)
self.update()
self.close()

View File

@ -92,6 +92,8 @@ class FilterList:
for the_filter in filter_list:
f.write(' <filter name="%s"' %self.fix(the_filter.get_name()))
f.write(' function="%s"' % the_filter.get_logical_op())
if the_filter.invert:
f.write(' invert="1"')
comment = the_filter.get_comment()
if comment:
f.write(' comment="%s"' % self.fix(comment))

View File

@ -73,6 +73,8 @@ class FilterParser(handler.ContentHandler):
except ValueError:
op = attrs['function']
self.f.set_logical_op(op)
if attrs.has_key('invert'):
self.f.set_invert(attrs['invert'])
if attrs.has_key('comment'):
self.f.set_comment(attrs['comment'])
self.gfilter_list.add(self.namespace,self.f)

View File

@ -42,12 +42,14 @@ class GenericFilter:
self.name = source.name
self.comment = source.comment
self.logical_op = source.logical_op
self.invert = source.invert
else:
self.need_param = 0
self.flist = []
self.name = ''
self.comment = ''
self.logical_op = 'and'
self.invert = False
def match(self,handle):
return True
@ -64,6 +66,12 @@ class GenericFilter:
def get_logical_op(self):
return self.logical_op
def set_invert(self,val):
self.invert = bool(val)
def get_invert(self):
return self.invert
def get_name(self):
return self.name
@ -102,29 +110,27 @@ class GenericFilter:
if id_list == None:
cursor = self.get_cursor(db)
data = cursor.next()
data = cursor.first()
while data:
person = self.make_obj()
person.unserialize(data[1])
if task(db,person):
if task(db,person) != self.invert:
final_list.append(data[0])
data = cursor.next()
cursor.close()
else:
for handle in id_list:
person = self.find_from_handle(db, handle)
if task(db,person):
if task(db,person) != self.invert:
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_and(self,db,id_list):
final_list = []
flist = self.flist
if id_list == None:
cursor = self.get_cursor(db)
data = cursor.next()
data = cursor.first()
while data:
person = self.make_obj()
person.unserialize(data[1])
@ -133,9 +139,10 @@ class GenericFilter:
if not rule.apply(db,person):
val = False
break
if not val:
if val != self.invert:
final_list.append(data[0])
data = cursor.next()
cursor.close()
else:
for handle in id_list:
person = self.find_from_handle(db, handle)
@ -144,10 +151,13 @@ class GenericFilter:
if not rule.apply(db,person):
val = False
break
if val:
if val != self.invert:
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_one(self,db,id_list):
return self.check_func(db,id_list,self.one_test)