I am wondering if it is possible to simulate that a DirectButton has been activated. I have a basic frame comprised of 9 DirectButtons. I then put all of those buttons into a dict…
self.buttonDict = {'1': self.statusButton,
'2': self.equipmentButton,
'3': self.magicButton,
'4': self.itemsButton,
'5': self.abilitiesButton,
'6': self.partyButton,
'7': self.tradeButton,
'8': self.searchButton,
'9': self.quitButton}
I select the buttons via arrow_up and arrow_down like so…
def selectionUp(self):
black = self.buttonDict[str(self.activeButton)]
black['text_fg']=(0,0,0,1)
#You've hit the top, wrap around
if self.activeButton == 1:
self.activeButton = self.totalButtons
else:
self.activeButton -= 1
red = self.buttonDict[str(self.activeButton)]
red['text_fg']=(1,0,0,1)
def selectionDown(self):
black = self.buttonDict[str(self.activeButton)]
black['text_fg']=(0,0,0,1)
#You've hit the bottom, wrap around
if self.activeButton == self.totalButtons:
self.activeButton = 1
else:
self.activeButton += 1
red = self.buttonDict[str(self.activeButton)]
red['text_fg']=(1,0,0,1)
Then self.accept(‘enter’, self.confirmSelection) calls…
def confirmSelection(self):
if self.activeButton == 1:
self.showStatus()
elif self.activeButton == 2:
self.notImplemented()
elif self.activeButton == 3:
self.notImplemented()
elif self.activeButton == 4:
self.notImplemented()
elif self.activeButton == 5:
self.notImplemented()
elif self.activeButton == 6:
self.notImplemented()
elif self.activeButton == 7:
self.notImplemented()
elif self.activeButton == 8:
self.notImplemented()
elif self.activeButton == 9:
sys.exit()
As you can tell most of those features have yet to be implemented, but that is neither here nor there.
I’m wondering if there is a way that I can clean it up a bit. Something like this…
def confirmSelection(self):
confirm = self.buttonDict[str(self.activeButton)]
RUN THE COMMAND >> confirm['command']