英文:
Search items in wxPython ListCtrl
问题
以下是您要翻译的内容:
在简单的术语中,我正在使用wxPython和psutil构建一个玩具任务管理器。我在列表顶部放置了一个searchCtrl。但是,我找不到一种方法来仅显示匹配的项目在列表中。我尝试创建一个包含所有任务的列表,然后删除除匹配项之外的所有项目,但不幸的是,由于列表每5秒更新一次,这种方法不起作用。
def on_search_task(self, e): # 此函数在触发搜索事件时执行
index = 0
keepitems = []
for x in self.alltasks:
for a in dict(x).values():
if a.find(e.GetString()) >= 0:
print("在{}处匹配 - {}".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,供进一步参考。
英文:
In simple terms , I am building a toy task manager with wxpython and psutil. I have a searchCtrl on top of the list. But I couldn't find a way to show only the matched items in that the list. I tried creating a list of all tasks and then deleting all items but the matched items , but unfortunately that doesn't work as the list was getting updated every 5 seconds.
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)
I hope I was able to describe the problem and my goal. Source code with current progress is also available on GitHub here <https://github.com/bauripalash/taskboy> for further reference.
答案1
得分: 1
你需要使用一个“虚拟”列表控件,即一个按需返回项目并在OnGetItemText()
中进行过滤的控件。请参考这个wiki链接以获取关于虚拟列表控件的简要解释。
英文:
You need to use a "virtual" list control, i.e. one returning items on demand, and do the filtering in your OnGetItemText()
. See the wiki for a brief explanation of virtual list controls.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论