【问题标题】:python ObjectListView negate filterpython ObjectListView 否定过滤器
【发布时间】:2016-10-04 13:59:31
【问题描述】:
我需要一些帮助来为 ObjectListView 取消此过滤器。
def addFilter(self, text):
# OLV.Filter.Predicate()
meter_flt = OLV.Filter.TextSearch(self, text=text)
self.SetFilter(meter_flt)
这很好用,但如果我尝试像“鸡”一样过滤,那么它只会显示鸡。我希望它反转,所以如果我输入鸡肉,除了鸡肉之外的所有东西都应该显示出来。
感谢您的帮助!
【问题讨论】:
标签:
python
wxpython
filtering
objectlistview
objectlistview-python
【解决方案1】:
您可以使用Filter.Predicate
Filter.Predicate(booleanCallable) 只显示模型对象
给定的可调用返回true。可调用对象必须接受
单个参数,即要考虑的模型对象。
以下是用于处理要从项目列表中排除的多个文本的代码 sn-p。
def __init__(self):
self.text_list = [] # list of text to be excluded
self.SetFilter(Filter.Predicate(self.filterMethod))
def addFilter(self, text):
self.text_list.append(text)
self.RepopulateList() # so that our filter_method is applied again
def filterMethod(self,obj):
for text in self.text_list:
if {YOUR EXCLUSION LOGIC HERE}:
return False
return True