简单来说,我正在用 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以供进一步参考。