View Full Version : [PYTHON] List boxes! Please Help!


Zebra 9
Feb 02, 2007, 06:13 PM
Ok, I'm working on changing a screen and I need a List Box. I got it on the screen and put all the selections I wanted. Now the problem is that I have no idea of what to do to access which selection was selected!!!:confused::cry:

I tryed all sorts of stuff and got no where. Please Help!

Gaurav
Feb 04, 2007, 11:43 AM
Just quickly looking in Locutus's API, one of these:

# INT getSelectedListBoxID(STRING szName)
int (string szName )

# STRING getSelectedListBoxString(STRING szName)
string ( string szName )

would probably do the trick.

Zebra 9
Feb 06, 2007, 12:39 PM
I tried that code and it doesn't seem to work. I think I did it right. well I have a zip with a log and some of the functions I'm using.

Gaurav
Feb 06, 2007, 06:19 PM
I put your code into the Sevopedia and got the same results. Confirmed - getSelectedListBoxID and getSelectedListBoxString do not work as we think they should.

I did a search and these methods are not called from anywhere in the vanilla python or SDK code. Since CyGInterfaceScreen is not in the SDK and (mostly) undocumented, I cannot say if they are implemented at all.

Zebra 9
Feb 07, 2007, 11:25 AM
So what should I do?

Dale
Feb 07, 2007, 12:46 PM
Try a drop-down combo box. This is how I implement them:

CvEventManager.py:

def __init__(self):
..
..
..
CvUtil.EventYourPopup : ('YourPopup', self.YourApply, self.YourBegin),
}
..
..
..
def YourBegin(self, argsList):
CvYourEventManager.YourBox()
return

def YourApply(self, playerID, userData, popupReturn):
CvYourEventManager.YourBoxHandler(playerID, userData, popupReturn)
return


CvUtil.py:

Somewhere near the top:
..
EventYourPopup = 5100 # some unique number
..


CvYourEventManager.py:

def YourBox(self):
popup = PyPopup.PyPopup(CvUtil.EventYourPopup, contextType = EventContextTypes.EVENTCONTEXT_ALL)
szTitle = localText.getText("TXT_KEY_YOUR_TITLE", ())
szText = localText.getText("TXT_KEY_YOUR_TEXT", ())
ListTypes = {
0 : 'Option1',
1 : 'Option2',
2 : 'Option3',
}
popup.setHeaderString(szTitle)
popup.addSeparator()
popup.setBodyString(szText)
popup.addSeparator()
popup.createPythonPullDown('Select an option', 3)
for i in range(0, len(ListTypes)):
popup.addPullDownString(ListTypes[i], i, 3)
popup.popup.setSelectedPulldownID(1, 3)
popup.addSeparator()
popup.launch()

def YourBoxHandler(self, playerID, netUserData, popupReturn):
autoIdx = popupReturn.getSelectedPullDownValue(3)
if(autoIdx == 0):
# do **** here
elif(autoIdx == 1):
# do **** here
elif(autoIdx == 2):
# do **** here

Zebra 9
Feb 08, 2007, 05:01 PM
Will that work on the civic screen? That looks like popup code.

Dale
Feb 08, 2007, 08:32 PM
Sorry didn't realise it was for civic screen. Not mentioned anywhere.

I think you're stuck mate.

Zebra 9
Feb 09, 2007, 05:55 PM
Is there any alternative? I have to have a list box or at least something like it or it won't work.