【问题标题】:Python - ObjectListView FilterPython - ObjectListView 过滤器
【发布时间】:2015-03-10 17:07:27
【问题描述】:

我已阅读 here 并尝试使用 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 过滤器。我也尝试过使用self.SetFilter(self.filter_me),但也没有用。

【问题讨论】:

    标签: python filter wxpython objectlistview objectlistview-python


    【解决方案1】:

    将您的 filter_view 更改为:

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

    参见:ObjectListView.SetFilter

    【讨论】:

    • self.RepopulateList() 修复了它。谢谢!
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多