This is a part of the code which successfully displays the values in the dict art in a wxListBox. However, nothing I try returns other than -1 from the last line below. Can anyone see why it doesn't work?
art = {'A1':'Horace Silver', 'A2':'Murray Perahia', 'A3':'Kieth Jarret',
'A4':'Andras Schiff', 'A5':'Tord Gustavsen Trio'}
art = dict(sorted(art.items(), key=lambda item: item[1]))
self.list_box_1.InsertItems(list(art.values()),0)
print(self.list_box_1.FindString('ray', True))
I have tried with and without case sensitivity, single and double quotes around the string, whole words and parts. No error messages are sent.
I gave up looking for the error and discovered that this function works:-
def checkname(self,l,n):
for i in range(l.GetCount()):
name = l.GetString(i)
x = name.find(n,0)
if x > -1:
return [i, name]
l is the name of a listbox and n is the string to find. It is limited to looking from the beginning.
As the
FindStringfunction is looking for a match on the label, you will need to manually find partial matches.One way to achieve that is to use the
wx.ListBoxGetStrings() function and then query that.Something like this: (here I query the labels for "
ra" and then set each item found as Selected)