首页 > 解决方案 > kivy:如何从 FileChooserListView 中的所有项目中删除突出显示

问题描述

我希望能够从 kivy FileChooserListView 中的所有项目中删除突出显示。我看到我可以通过将 FileChooserListView().selection 设置为空列表来删除实际选择[]。但这不会删除以前选择的项目的突出显示。谢谢您的帮助。

标签: pythonkivy

解决方案


似乎没有任何方法可以直接做到这一点,但我认为这个丑陋的黑客会起作用:

class FakeEntry():
    def __init__(self, **kwargs):
        self.path = kwargs.pop('path', None)

class FakeEvent():
    def __init__(self):
        self.profile = []
        self.button = None
        self.is_double_tap = False

'''
Clear all selections in the specified FileChooser
'''
def clear_selection(file_chooser, *args):
    layout = file_chooser.layout
    if layout.VIEWNAME == 'list':
        layout.ids.treeview.deselect_node()
    fakeTouch = FakeEvent()
    for path in file_chooser.selection[:]:
        file_chooser.entry_touched(FakeEntry(path=path), fakeTouch)

推荐阅读