Skip to content

Commit 5c99cf1

Browse files
committed
dgui: fix DirectEntry._autoCapitalize() on Python 3.x (panda3d#628)
1 parent 43a5719 commit 5c99cf1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

direct/src/gui/DirectEntry.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ def _handleErasing(self, guiEvent):
216216
self._autoCapitalize()
217217

218218
def _autoCapitalize(self):
219-
name = self.get().decode('utf-8')
219+
name = self.guiItem.getWtext()
220220
# capitalize each word, allowing for things like McMutton
221-
capName = ''
221+
capName = u''
222222
# track each individual word to detect prefixes like Mc
223-
wordSoFar = ''
223+
wordSoFar = u''
224224
# track whether the previous character was part of a word or not
225225
wasNonWordChar = True
226226
for i, character in enumerate(name):
@@ -229,9 +229,9 @@ def _autoCapitalize(self):
229229
# This assumes that string.lower and string.upper will return different
230230
# values for all unicode letters.
231231
# - Don't count apostrophes as a break between words
232-
if character.lower() == character.upper() and character != "'":
232+
if character.lower() == character.upper() and character != u"'":
233233
# we are between words
234-
wordSoFar = ''
234+
wordSoFar = u''
235235
wasNonWordChar = True
236236
else:
237237
capitalize = False
@@ -255,7 +255,8 @@ def _autoCapitalize(self):
255255
wordSoFar += character
256256
wasNonWordChar = False
257257
capName += character
258-
self.enterText(capName.encode('utf-8'))
258+
self.guiItem.setWtext(capName)
259+
self.guiItem.setCursorPosition(self.guiItem.getNumCharacters())
259260

260261
def focusOutCommandFunc(self):
261262
if self['focusOutCommand']:

0 commit comments

Comments
 (0)