Hi all,
I am trying to work with two lists for a wx.ListBox. One list holds
the strings the user sees in the list, and the other holds those
strings' corresponding values. For example, I have four different
different patterns from which the user can choose, set in the "names"
list, and each pattern has a corresponding integer value, set in the
"vals" list. Were this Javascript, I could just create a "select" tag,
and add "option" tags to it, putting a "value" attribute in each
option. I could then get that box's selected item's text OR value.
However, it seems that there is no way to get the item in vals of the
item the user selects in my listbox. Here is an example. Note that,
just before the dialog is created, I do some if statements to
determine which patterns it makes sense to show. This is for my
Battleship game and uses the lbc package I posted about a couple days
ago.
import wx, lbc
dirs=["up", "down", "left", "right"] #directions to show in the list
dir_values=["0", "1", "2", "3"] #the corresponding values for the list items
if(board.y==0): dirs.remove("up"); dir_values.remove("0")
if(board.y==board.rows-1): dirs.remove("down"); dir_values.remove("1")
if(board.x==0): dirs.remove("left"); dir_values.remove("2")
if(board.x==board.cols-1): dirs.remove("right"); dir_values.remove("3")
dlg=lbc.Dialog(title="Launch Torpedo", parent=board.parentFrame)
pattern_lst=dlg.AddListBox(label=pattern_lbl, names=dirs, values=dir_values)
When I run it, though, if only "down" and "right show in the dialog,
they are automatically assigned indecies of 0 and 1, understandably.
However, I want to know how to use those strings' entries in my
"dir_values" list instead of relying on the index of the selected item
and going through a whole bunch of logic. This would not be a problem
if I were to not decide which values should and should not be in the
list, but it makes no sense to offer a pattern that would result in
hitting nothing. Oh, note that "board" is a playing board object
which, among other things, holds the player's position and the board's
total size so I can see if the entered coordinates are at the edge of
the board or not. I hope this makes some sense. What it boils down to
is this: in wx.ListBox, can I have a list of strings to show to the
user correspond to a parallel list of values to be drawn from
depending on which string the user selects? TIA!
···
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap