0

我已阅读此处,并尝试使用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),但也没有用。

4

1 回答 1

2

将您的 filter_view 更改为:

def filter_view(self):
    self.SetFilter(olv.Filter.Predicate(self.filter_me))
    self.RepopulateList()

请参阅:ObjectListView.SetFilter

于 2015-03-11T10:10:00.330 回答