*** empty log message ***

This commit is contained in:
Mike Goslin 2000-11-29 20:39:31 +00:00
parent f9f6b012c8
commit 1a928e113f

View File

@ -1,155 +1,157 @@
"""PickList module: contains the PickList class""" """PickList module: contains the PickList class"""
from ShowBaseGlobal import * from ShowBaseGlobal import *
import PandaObject import PandaObject
import Frame import Frame
import Button import Button
class PickList(PandaObject.PandaObject): class PickList(PandaObject.PandaObject):
"""PickList class: display a menu of choices and report users """PickList class: display a menu of choices and report users
choice (via mouse or keyboard) as an event with the choice as choice (via mouse or keyboard) as an event with the choice as
an extra argument an extra argument
""" """
# special methods # special methods
def __init__(self, name, choiceList): def __init__(self, name, choiceList):
self.name = name self.name = name
self.frame = Frame.Frame(name) self.frame = Frame.Frame(name)
# listen for keyboard events # listen for keyboard events
self.accept("up-up", self.__decrementChoice) self.accept("up-up", self.__decrementChoice)
self.accept("down-up", self.__incrementChoice) self.accept("down-up", self.__incrementChoice)
self.accept("enter-up", self.__makeChoice, [1]) self.accept("enter-up", self.__makeChoice, [1])
# initialization # initialization
self.choice = -1 self.choice = -1
self.choiceList = [] self.choiceList = []
self.eventName = self.name self.eventName = self.name
self.frame.setOffset(0.015) self.frame.setOffset(0.015)
# display the menu # display the menu
self.__displayChoices(choiceList) self.__displayChoices(choiceList)
def cleanup(self): def cleanup(self):
"""cleanup(self) """cleanup(self)
Remove events and cleanup the display Remove events and cleanup the display
""" """
# remove keyboard events # remove keyboard events
self.ignore("up-up") self.ignore("up-up")
self.ignore("down-up") self.ignore("down-up")
self.ignore("enter-up") self.ignore("enter-up")
# ignore all the buttons # ignore all the buttons
for item in self.frame.getItems(): for item in self.frame.getItems():
self.ignore(item.getGuiItem().getUpRolloverEvent()) self.ignore(item.getGuiItem().getUpRolloverEvent())
self.ignore(item.getGuiItem().getUpRolloverEvent()) self.ignore(item.getGuiItem().getUpRolloverEvent())
self.ignore(item.getGuiItem().getDownRolloverEvent()) self.ignore(item.getGuiItem().getDownRolloverEvent())
# reset the display # reset the display
self.frame.unmanage() self.frame.unmanage()
del(self.frame) del(self.frame)
# accessing # accessing
def getName(self): def getName(self):
return self.name return self.name
def getEventName(self): def getEventName(self):
return self.eventName return self.eventName
def setEventName(self, eventName): def setEventName(self, eventName):
self.eventName = eventName self.eventName = eventName
# actions # actions
def __displayChoices(self, choiceList): def __displayChoices(self, choiceList):
"""__displayChoices(self, string[]) """__displayChoices(self, string[])
Display the list of choices Display the list of choices
""" """
for choice in choiceList: for choice in choiceList:
# create a button for each choice # create a button for each choice
button = Button.Button(choice) button = Button.Button(choice)
choiceIndex = choiceList.index(choice) choiceIndex = choiceList.index(choice)
# set the rollover-up event # set the rollover-up event
eventName = self.name + "-up-" + str(choiceIndex) eventName = self.name + "-up-" + str(choiceIndex)
button.button.setUpRolloverEvent(eventName) button.button.setUpRolloverEvent(eventName)
self.accept(eventName, self.__updateButtonChoice, [choiceIndex]) self.accept(eventName, self.__updateButtonChoice, [choiceIndex])
# set the rollover-down event # set the rollover-down event
eventName = self.name + "-down-" + str(choiceIndex) eventName = self.name + "-down-" + str(choiceIndex)
button.button.setDownRolloverEvent(eventName) button.button.setDownRolloverEvent(eventName)
self.accept(eventName, self.__makeChoice) self.accept(eventName, self.__makeChoice)
# set exit event # set exit event
eventName = self.name + "-exit-" + str(choiceIndex) eventName = self.name + "-exit-" + str(choiceIndex)
button.button.setUpEvent(eventName) button.button.setUpEvent(eventName)
self.accept(eventName, self.__exitChoice) self.accept(eventName, self.__exitChoice)
# keep a list of the choice buttons # keep a list of the choice buttons
self.frame.addItem(button) self.frame.addItem(button)
self.choiceList.append(button) self.choiceList.append(button)
# set up the frame # set up the frame
self.frame.makeWideAsWidest() self.frame.makeWideAsWidest()
self.frame.makeVertical() self.frame.makeVertical()
self.frame.recompute() self.frame.recompute()
def manage(self): def manage(self):
self.frame.manage() self.frame.manage()
def unmanage(self): def unmanage(self):
self.frame.unmanage() self.frame.unmanage()
# event handlers # event handlers
def __incrementChoice(self): def __incrementChoice(self):
# handle the up arrow # handle the up arrow
if (self.choice >= 0): if (self.choice >= 0):
# exit lest choice, if it exists # exit lest choice, if it exists
self.choiceList[self.choice].getGuiItem().exit() self.choiceList[self.choice].getGuiItem().exit()
self.choice = self.choice + 1 self.choice = self.choice + 1
if (self.choice > len(self.choiceList) - 1): if (self.choice > len(self.choiceList) - 1):
self.choice = 0 self.choice = 0
# enter the new choice # enter the new choice
self.choiceList[self.choice].getGuiItem().enter() self.choiceList[self.choice].getGuiItem().enter()
def __decrementChoice(self): def __decrementChoice(self):
# handle the down arrow # handle the down arrow
if (self.choice >= 0): if (self.choice >= 0):
self.choiceList[self.choice].getGuiItem().exit() self.choiceList[self.choice].getGuiItem().exit()
self.choice = self.choice - 1 self.choice = self.choice - 1
if (self.choice < 0): if (self.choice < 0):
self.choice = len(self.choiceList) - 1 self.choice = len(self.choiceList) - 1
# enter this choice # enter this choice
self.choiceList[self.choice].getGuiItem().enter() self.choiceList[self.choice].getGuiItem().enter()
def __updateButtonChoice(self, newChoice): def __updateButtonChoice(self, newChoice):
# handle the mouse rollovers # handle the mouse rollovers
self.choice = newChoice self.choice = newChoice
# make sure all the other buttons have exited # make sure all the other buttons have exited
for choice in self.choiceList: for choice in self.choiceList:
if not (self.choiceList.index(choice) == self.choice): if not (self.choiceList.index(choice) == self.choice):
choice.getGuiItem().exit() choice.getGuiItem().exit()
# throw a rollover event
def __exitChoice(self): messenger.send(self.name + "-rollover")
# reset choice when mouse exits a button
self.choice = -1 def __exitChoice(self):
# reset choice when mouse exits a button
def __makeChoice(self, button=0): self.choice = -1
# handle the enter key
if (self.choice == -1): def __makeChoice(self, button=0):
# nothing selected yet # handle the enter key
return None if (self.choice == -1):
else: # nothing selected yet
# if the keyboard was used, update the button manually return None
if (button): else:
self.choiceList[self.choice].getGuiItem().down() # if the keyboard was used, update the button manually
def buttonUp(state): if (button):
state.choice.getGuiItem().up() self.choiceList[self.choice].getGuiItem().down()
return Task.done def buttonUp(state):
task = Task.Task(buttonUp) state.choice.getGuiItem().up()
task.choice = self.choiceList[self.choice] return Task.done
taskMgr.spawnTaskNamed(Task.doLater(.035, task, task = Task.Task(buttonUp)
"buttonUp-Later"), task.choice = self.choiceList[self.choice]
"doLater-buttonUp-later") taskMgr.spawnTaskNamed(Task.doLater(.035, task,
# let everyone know a choice was made "buttonUp-Later"),
messenger.send(self.eventName, [self.choice]) "doLater-buttonUp-later")
# let everyone know a choice was made
messenger.send(self.eventName, [self.choice])