|
@@ -81,7 +81,6 @@ class DirectEntry(DirectFrame):
|
|
|
# Pass in empty text to avoid extra work, since its really
|
|
# Pass in empty text to avoid extra work, since its really
|
|
|
# The PGEntry which will use the TextNode to generate geometry
|
|
# The PGEntry which will use the TextNode to generate geometry
|
|
|
text = '',
|
|
text = '',
|
|
|
- # PGEntry assumes left alignment
|
|
|
|
|
align = TextNode.ALeft,
|
|
align = TextNode.ALeft,
|
|
|
font = font,
|
|
font = font,
|
|
|
scale = 1,
|
|
scale = 1,
|
|
@@ -159,46 +158,49 @@ class DirectEntry(DirectFrame):
|
|
|
apply(self['focusOutCommand'], self['focusOutExtraArgs'])
|
|
apply(self['focusOutCommand'], self['focusOutExtraArgs'])
|
|
|
|
|
|
|
|
def set(self, text):
|
|
def set(self, text):
|
|
|
|
|
+ """ Changes the text currently showing in the typable region;
|
|
|
|
|
+ does not change the current cursor position. Also see
|
|
|
|
|
+ enterText(). """
|
|
|
|
|
+
|
|
|
self.unicodeText = isinstance(text, types.UnicodeType)
|
|
self.unicodeText = isinstance(text, types.UnicodeType)
|
|
|
if self.unicodeText:
|
|
if self.unicodeText:
|
|
|
self.guiItem.setWtext(text)
|
|
self.guiItem.setWtext(text)
|
|
|
else:
|
|
else:
|
|
|
self.guiItem.setText(text)
|
|
self.guiItem.setText(text)
|
|
|
|
|
|
|
|
- def get(self):
|
|
|
|
|
|
|
+ def get(self, plain = False):
|
|
|
|
|
+ """ Returns the text currently showing in the typable region.
|
|
|
|
|
+ If plain is True, the returned text will not include any
|
|
|
|
|
+ formatting characters like nested color-change codes. """
|
|
|
|
|
+
|
|
|
|
|
+ wantWide = self.unicodeText or self.guiItem.isWtext()
|
|
|
if not self.directWtext.getValue():
|
|
if not self.directWtext.getValue():
|
|
|
# If the user has configured wide-text off, then always
|
|
# If the user has configured wide-text off, then always
|
|
|
# return an 8-bit string. This will be encoded if
|
|
# return an 8-bit string. This will be encoded if
|
|
|
# necessary, according to Panda's default encoding.
|
|
# necessary, according to Panda's default encoding.
|
|
|
- return self.guiItem.getText()
|
|
|
|
|
|
|
+ wantWide = False
|
|
|
|
|
|
|
|
- if self.unicodeText:
|
|
|
|
|
- return self.guiItem.getWtext()
|
|
|
|
|
|
|
+ if plain:
|
|
|
|
|
+ if wantWide:
|
|
|
|
|
+ return self.guiItem.getPlainWtext()
|
|
|
|
|
+ else:
|
|
|
|
|
+ return self.guiItem.getPlainText()
|
|
|
else:
|
|
else:
|
|
|
- # Although we weren't expecting a wide character, the user
|
|
|
|
|
- # might give us one. If this happens, we have to return a
|
|
|
|
|
- # wide string.
|
|
|
|
|
- wtext = self.guiItem.getWtext()
|
|
|
|
|
- text = self.guiItem.getText()
|
|
|
|
|
- try:
|
|
|
|
|
- matches = (wtext == unicode(text))
|
|
|
|
|
- except:
|
|
|
|
|
- return wtext
|
|
|
|
|
- if matches:
|
|
|
|
|
- return text
|
|
|
|
|
|
|
+ if wantWide:
|
|
|
|
|
+ return self.guiItem.getWtext()
|
|
|
else:
|
|
else:
|
|
|
- return wtext
|
|
|
|
|
|
|
+ return self.guiItem.getText()
|
|
|
|
|
|
|
|
def setCursorPosition(self, pos):
|
|
def setCursorPosition(self, pos):
|
|
|
if (pos < 0):
|
|
if (pos < 0):
|
|
|
- self.guiItem.setCursorPosition(len(self.get()) + pos)
|
|
|
|
|
|
|
+ self.guiItem.setCursorPosition(self.guiItem.getNumCharacters() + pos)
|
|
|
else:
|
|
else:
|
|
|
self.guiItem.setCursorPosition(pos)
|
|
self.guiItem.setCursorPosition(pos)
|
|
|
|
|
|
|
|
def enterText(self, text):
|
|
def enterText(self, text):
|
|
|
""" sets the entry's text, and moves the cursor to the end """
|
|
""" sets the entry's text, and moves the cursor to the end """
|
|
|
self.set(text)
|
|
self.set(text)
|
|
|
- self.setCursorPosition(len(self.get()))
|
|
|
|
|
|
|
+ self.setCursorPosition(self.guiItem.getNumCharacters())
|
|
|
|
|
|
|
|
def getBounds(self, state = 0):
|
|
def getBounds(self, state = 0):
|
|
|
# Compute the width and height for the entry itself, ignoring
|
|
# Compute the width and height for the entry itself, ignoring
|