Re: lbc ListBox item sorting

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 19 Jun 2011 16:47:41 -0400

Sorry that the Lbc for Python documentation is not better. I will try to improve it in the next release. In the meantime, I suggest that anyone using it also look at Lbc documentation in the .NET version, which I spent more time detailing. The concepts are usually the same. That version is at


http://EmpowermentZone.com/appsetup.exe

I also suggest examining the code in lbc.py and test_lbc.py for usage examples. The Lbc API is used to build several canned dialogs.

Regarding a listbox, it is possible to have two parallel lists of items, one corresponding to what is visibly displayed in the control, and the other corresponding to what is returned to a variable when an item is selected. The two lists can be set to the same strings, but they can also be different.

For example, the names list might correspond to file names, and the values list might correspond to the full paths of those file names. If the listbox is showing a list of recent files, for example, the user would probably not want to read the complete path of each item. Rather, the file name only would be sufficient. Yet, tasks that operate on files work most reliably when they are given complete paths.

Another example, might be English names of programs, and values that are full paths to their executables. If no distinction is needed, then simply set the values list to the same thing as the names list.

Jamal

On 6/18/2011 9:17 PM, Alex Hall wrote:
Hi all,
When I use a ListBox, I see that I can give it a names list and a
values list. I understand that names are what is shown to the user,
but what do values do? They do not seem to be used in the AddListBox
method at all.

A second question goes along with this: when I pass a list to be the
names list in a ListBox, all is well. When I pass a dictionary,
though, all my items suddenly get out of order. For example, if I pass
["apple", "banana", "orange"] as the names list in the AddListBox
method, the items appear in that order. When I instead do this:
items={
  "apples":"red",
  "bananas":"yellow",
  "oranges":"orange"
}
and then add to my dialog:
dlg.AddListBox(label="fruit", names=items.keys())
I get a list with the three fruits out of order, appearing as "apples,
oranges, bananas" in the list instead. I imagine this is a python
problem in the keys() method of the dictionary, but I cannot imagine
why it would do it at all. How do I get around it so that items appear
in the same order as they do in my dictionary? Thanks!


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: