【发布时间】:2020-01-06 12:08:04
【问题描述】:
简单来说,我正在用 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 以供进一步参考。
【问题讨论】:
-
为什么每 5 秒更新一次列表?需要iot更新吗?你在用定时器吗?也许当您过滤列表时应该停止它?
-
每5秒更新一次任务的RAM使用率、CPU使用率等数据。我可以停止计时器并过滤项目,但过滤项目的数据不会更新。
标签: python wxpython wxwidgets taskmanager listctrl