mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-05 03:15:07 -04:00
added autoCapitalize
This commit is contained in:
parent
e0d08e45d9
commit
9d335cb65e
@ -64,6 +64,7 @@ class DirectEntry(DirectFrame):
|
|||||||
# Sounds to be used for button events
|
# Sounds to be used for button events
|
||||||
('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
|
('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
|
||||||
('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
|
('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
|
||||||
|
('autoCapitalize', 0, self.autoCapitalizeFunc),
|
||||||
)
|
)
|
||||||
# Merge keyword options with default options
|
# Merge keyword options with default options
|
||||||
self.defineoptions(kw, optiondefs)
|
self.defineoptions(kw, optiondefs)
|
||||||
@ -119,8 +120,7 @@ class DirectEntry(DirectFrame):
|
|||||||
self.set(self['initialText'])
|
self.set(self['initialText'])
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self.ignore(self.guiItem.getFocusInEvent())
|
self.ignoreAll()
|
||||||
self.ignore(self.guiItem.getFocusOutEvent())
|
|
||||||
DirectFrame.destroy(self)
|
DirectFrame.destroy(self)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
@ -166,13 +166,47 @@ class DirectEntry(DirectFrame):
|
|||||||
# Pass any extra args
|
# Pass any extra args
|
||||||
apply(self['failedCommand'], [self.get()] + self['failedExtraArgs'])
|
apply(self['failedCommand'], [self.get()] + self['failedExtraArgs'])
|
||||||
|
|
||||||
|
def autoCapitalizeFunc(self):
|
||||||
|
if self['autoCapitalize']:
|
||||||
|
self.accept(self.guiItem.getTypeEvent(), self._handleTyping)
|
||||||
|
self.accept(self.guiItem.getEraseEvent(), self._handleErasing)
|
||||||
|
else:
|
||||||
|
self.ignore(self.guiItem.getTypeEvent())
|
||||||
|
self.ignore(self.guiItem.getEraseEvent())
|
||||||
|
|
||||||
def focusInCommandFunc(self):
|
def focusInCommandFunc(self):
|
||||||
if self['focusInCommand']:
|
if self['focusInCommand']:
|
||||||
apply(self['focusInCommand'], self['focusInExtraArgs'])
|
apply(self['focusInCommand'], self['focusInExtraArgs'])
|
||||||
|
if self['autoCapitalize']:
|
||||||
|
self.accept(self.guiItem.getTypeEvent(), self._handleTyping)
|
||||||
|
self.accept(self.guiItem.getEraseEvent(), self._handleErasing)
|
||||||
|
|
||||||
|
def _handleTyping(self, guiEvent):
|
||||||
|
self._autoCapitalize()
|
||||||
|
def _handleErasing(self, guiEvent):
|
||||||
|
self._autoCapitalize()
|
||||||
|
|
||||||
|
def _autoCapitalize(self):
|
||||||
|
name = self.get().decode('utf-8')
|
||||||
|
# capitalize each word
|
||||||
|
capName = ''
|
||||||
|
for i in xrange(len(name)):
|
||||||
|
character = name[i]
|
||||||
|
# is it a letter?
|
||||||
|
# This assumes that string.lower and string.upper will return different
|
||||||
|
# values for all unicode letters.
|
||||||
|
if string.lower(character) != string.upper(character):
|
||||||
|
# if it's not preceded by a letter, capitalize it
|
||||||
|
if (i == 0) or string.lower(name[i-1]) == string.upper(name[i-1]):
|
||||||
|
character = string.upper(character)
|
||||||
|
capName += character
|
||||||
|
self.enterText(capName.encode('utf-8'))
|
||||||
|
|
||||||
def focusOutCommandFunc(self):
|
def focusOutCommandFunc(self):
|
||||||
if self['focusOutCommand']:
|
if self['focusOutCommand']:
|
||||||
apply(self['focusOutCommand'], self['focusOutExtraArgs'])
|
apply(self['focusOutCommand'], self['focusOutExtraArgs'])
|
||||||
|
self.ignore(self.guiItem.getTypeEvent())
|
||||||
|
self.ignore(self.guiItem.getEraseEvent())
|
||||||
|
|
||||||
def set(self, text):
|
def set(self, text):
|
||||||
""" Changes the text currently showing in the typable region;
|
""" Changes the text currently showing in the typable region;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user