0

我需要一些幫助,否定此ObjectListView的過濾器。python ObjectListView否定過濾器

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

這很好,但如果我嘗試過濾像「雞」,那麼它只是顯示雞。我希望它被顛倒過來,所以如果我輸入雞肉,應該顯示除雞肉之外的所有東西。

感謝您的幫助!

回答

0

您可以使用Filter.Predicate

Filter.Predicate(booleanCallable)只顯示 其給定的調用返回true模型對象。可調用函數必須接受一個參數 ,這是要考慮的模型對象。

以下是用於處理從項目列表中排除的多個文本的代碼片段。

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