Updated Direct Frame to use text_mayChange syntax

Updated DirectOptionMenu to allow selection when holding down mouse button
This commit is contained in:
Mark Mine 2002-10-08 00:32:12 +00:00
parent 2481a688df
commit d9f964c51c
2 changed files with 28 additions and 14 deletions

View File

@ -23,7 +23,9 @@ class DirectFrame(DirectGuiWidget):
('geom', None, self.setGeom), ('geom', None, self.setGeom),
# A foreground text node # A foreground text node
('text', None, self.setText), ('text', None, self.setText),
('textMayChange', 1, None), # Change default value of text mayChange flag from 0
# (OnscreenText.py) to 1
('text_mayChange', 1, None),
) )
# Merge keyword options with default options # Merge keyword options with default options
self.defineoptions(kw, optiondefs, self.defineoptions(kw, optiondefs,
@ -75,7 +77,6 @@ class DirectFrame(DirectGuiWidget):
(), parent = self.stateNodePath[i], (), parent = self.stateNodePath[i],
text = text, scale = 1, text = text, scale = 1,
sort = TEXT_SORT_INDEX, sort = TEXT_SORT_INDEX,
mayChange = self['textMayChange'],
) )
def setGeom(self): def setGeom(self):

View File

@ -43,23 +43,29 @@ class DirectOptionMenu(DirectButton):
relief = RAISED) relief = RAISED)
# This needs to popup the menu too # This needs to popup the menu too
self.popupMarker.bind(B1PRESS, self.showPopupMenu) self.popupMarker.bind(B1PRESS, self.showPopupMenu)
# Check if item is highlighted on release and select it if it is
self.popupMarker.bind(B1RELEASE, self.selectHighlightedIndex)
# Make popup marker have the same click sound # Make popup marker have the same click sound
self.popupMarker.guiItem.setSound( self.popupMarker.guiItem.setSound(
B1PRESS + self.popupMarker.guiId,self['clickSound']) B1PRESS + self.popupMarker.guiId,self['clickSound'])
# This is created when you set the menu's items # This is created when you set the menu's items
self.popupMenu = None self.popupMenu = None
self.selectedIndex = None self.selectedIndex = None
self.highlightedIndex = None
# A big screen encompassing frame to catch the cancel clicks # A big screen encompassing frame to catch the cancel clicks
self.cancelFrame = self.createcomponent( self.cancelFrame = self.createcomponent(
'cancelframe', (), None, 'cancelframe', (), None,
DirectFrame, (self,), DirectFrame, (self,),
frameSize = (-1,1,-1,1), frameSize = (-1,1,-1,1),
relief = None) relief = None,
state = 'normal')
# Make sure this is on top of all the other widgets # Make sure this is on top of all the other widgets
self.cancelFrame.setBin('gui-popup', 0) self.cancelFrame.setBin('gui-popup', 0)
self.cancelFrame.bind(B1PRESS, self.hidePopupMenu) self.cancelFrame.bind(B1PRESS, self.hidePopupMenu)
# Default action on press is to show popup menu # Default action on press is to show popup menu
self.bind(B1PRESS, self.showPopupMenu) self.bind(B1PRESS, self.showPopupMenu)
# Check if item is highlighted on release and select it if it is
self.bind(B1RELEASE, self.selectHighlightedIndex)
# Call option initialization functions # Call option initialization functions
self.initialiseoptions(DirectOptionMenu) self.initialiseoptions(DirectOptionMenu)
# Need to call this since we explicitly set frame size # Need to call this since we explicitly set frame size
@ -123,11 +129,12 @@ class DirectOptionMenu(DirectButton):
item.setPos(-self.minX, 0 , -self.maxZ - i * self.maxHeight) item.setPos(-self.minX, 0 , -self.maxZ - i * self.maxHeight)
item.bind(B1RELEASE, self.hidePopupMenu) item.bind(B1RELEASE, self.hidePopupMenu)
# Highlight background when mouse is in item # Highlight background when mouse is in item
item.bind(ENTER, lambda x, item=item: self._highlightItem(item)) item.bind(WITHIN,
lambda x,i=i,item=item:self._highlightItem(item, i))
# Restore specified color upon exiting # Restore specified color upon exiting
fc = item['frameColor'] fc = item['frameColor']
item.bind( item.bind(WITHOUT,
EXIT,lambda x,item=item,fc=fc: self._unhighlightItem(item,fc)) lambda x,item=item,fc=fc: self._unhighlightItem(item,fc))
# Set popup menu frame size to encompass all items # Set popup menu frame size to encompass all items
f = self.component('popupMenu') f = self.component('popupMenu')
f['frameSize'] = (0, self.maxWidth, -self.maxHeight * itemIndex, 0) f['frameSize'] = (0, self.maxWidth, -self.maxHeight * itemIndex, 0)
@ -206,11 +213,24 @@ class DirectOptionMenu(DirectButton):
self.popupMenu.hide() self.popupMenu.hide()
self.cancelFrame.hide() self.cancelFrame.hide()
def _highlightItem(self, item): def _highlightItem(self, item, index):
""" Set frame color of highlighted item, record index """
item['frameColor'] = self['highlightColor'] item['frameColor'] = self['highlightColor']
self.highlightedIndex = index
def _unhighlightItem(self, item, frameColor): def _unhighlightItem(self, item, frameColor):
""" Clear frame color, clear highlightedIndex """
item['frameColor'] = frameColor item['frameColor'] = frameColor
self.highlightedIndex = None
def selectHighlightedIndex(self, event = None):
"""
Check to see if item is highlighted (by cursor being within
that item). If so, selected it. If not, do nothing
"""
if self.highlightedIndex is not None:
self.set(self.highlightedIndex)
self.hidePopupMenu()
def index(self, index): def index(self, index):
intIndex = None intIndex = None
@ -246,10 +266,3 @@ class DirectOptionMenu(DirectButton):
Command is executed in response to selecting menu items Command is executed in response to selecting menu items
""" """
pass pass