Skip to content

Commit

Permalink
dgui: fix DirectEntry._autoCapitalize() on Python 3.x (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdb committed Aug 14, 2019
1 parent 43a5719 commit 5c99cf1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions direct/src/gui/DirectEntry.py
Expand Up @@ -216,11 +216,11 @@ def _handleErasing(self, guiEvent):
self._autoCapitalize()

def _autoCapitalize(self):
name = self.get().decode('utf-8')
name = self.guiItem.getWtext()
# capitalize each word, allowing for things like McMutton
capName = ''
capName = u''
# track each individual word to detect prefixes like Mc
wordSoFar = ''
wordSoFar = u''
# track whether the previous character was part of a word or not
wasNonWordChar = True
for i, character in enumerate(name):
Expand All @@ -229,9 +229,9 @@ def _autoCapitalize(self):
# This assumes that string.lower and string.upper will return different
# values for all unicode letters.
# - Don't count apostrophes as a break between words
if character.lower() == character.upper() and character != "'":
if character.lower() == character.upper() and character != u"'":
# we are between words
wordSoFar = ''
wordSoFar = u''
wasNonWordChar = True
else:
capitalize = False
Expand All @@ -255,7 +255,8 @@ def _autoCapitalize(self):
wordSoFar += character
wasNonWordChar = False
capName += character
self.enterText(capName.encode('utf-8'))
self.guiItem.setWtext(capName)
self.guiItem.setCursorPosition(self.guiItem.getNumCharacters())

def focusOutCommandFunc(self):
if self['focusOutCommand']:
Expand Down

0 comments on commit 5c99cf1

Please sign in to comment.