我已经阅读了这里,我正在尝试使用Filter.Predicate(booleanCallable)
过滤ObjectListView,如下所示:
class Book(object):
def __init__(self,name,author,length):
self.name=name
self.author=author
self.length=str(length)
class ObjectDataView(ObjectListView):
def __init__(self, parent):
ObjectListView.__init__(self, parent, size=(400,400), pos=(0,0), style=wx.LC_REPORT | wx.SUNKEN_BORDER)
self.SetColumns([
ColumnDefn("Name", "left", 400/3, "name"),
ColumnDefn("Author", "left", 400/3, "author"),
ColumnDefn("Length", "left", 400/3, "length"),
])
def filter_view(self):
self.SetFilter(Filter.Predicate(self.filter_me))
self.Update()
def filter_me(self,obj):
return obj.length == '10'
app=wx.App()
frame=wx.Frame(None,-1,"Check",size=(400,400))
panel=wx.Panel(frame,size=frame.GetSize())
view = ObjectDataView(panel)
view.AddObject(Book("hary1","ori",10))
view.AddObject(Book("hary2","ori",10))
view.AddObject(Book("hary3","s",15))
view.AddObject(Book("hary4","s",15))
view.AddObject(Book("hary5","s",15))
view.filter_view()
frame.Show()
app.SetTopWindow(frame)
app.MainLoop()
但是当我打电话给filter_view()
时,它什么也没做。我使用ObjectListView,因为它的功能之一是buitin Filter。我也尝试使用self.SetFilter(self.filter_me)
但它也没有用。
将filter_view更改为:
def filter_view(self):
self.SetFilter(olv.Filter.Predicate(self.filter_me))
self.RepopulateList()
请参阅: ObjectListView.SetFilter