0

简单来说,我正在用 wxpython 和 psutil 构建一个玩具任务管理器。我在列表顶部有一个 searchCtrl。但我找不到只显示该列表中匹配项目的方法。我尝试创建所有任务的列表,然后删除除匹配项之外的所有项目,但不幸的是,这不起作用,因为列表每 5 秒更新一次。

    def on_search_task(self , e): # this function got executed when the a search event is fired
        index = 0
        keepitems = []
        for x in self.alltasks:
            for a in dict(x).values():
                if a.find(e.GetString()) >= 0:
                    print("match at {} - {}".format(index , self.alltasks.index(x)))
                    print(self.alltasks.index(x) == index)
                else:
                    keepitems.append(index)

            index += 1

        for x in keepitems:
            self.task_list.DeleteItem(x)

我希望我能够描述问题和我的目标。GitHub 上也提供了当前进度的源代码https://github.com/bauripalash/taskboy以供进一步参考。

4

1 回答 1

1

您需要使用“虚拟”列表控件,即按需返回项目,并在您的OnGetItemText(). 有关虚拟列表控件的简要说明,请参见wiki

于 2020-01-07T12:43:25.173 回答