python ObjectListView 否定过滤器

python ObjectListView negate filter

我需要一些帮助来为 ObjectListView 取消此过滤器。

def addFilter(self, text):
    # OLV.Filter.Predicate()
    meter_flt = OLV.Filter.TextSearch(self, text=text)
    self.SetFilter(meter_flt)

效果很好,但如果我尝试像 "chicken" 那样进行过滤,那么它只会显示鸡。我希望它反转,所以如果我输入 chicken,除了 chicken 之外的所有内容都应该显示。

感谢您的帮助!

您可以使用Filter.Predicate

Filter.Predicate(booleanCallable) Show only the model objects for which the given callable returns true. The callable must accept a single parameter, which is the model object to be considered.

以下是用于处理要从项目列表中排除的多个文本的代码片段。

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