polu_
polu_

Reputation: 433

Search items in wxPython ListCtrl

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.

Upvotes: 0

Views: 527

Answers (1)

VZ.
VZ.

Reputation: 22743

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.

Upvotes: 1

Related Questions