mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
direct.gui: Correct strings checks
- str in Python3 is always unicode, but not in Python2. Avoid crashes when unicode is used Signed-off-by: deflected <deflected@github>
This commit is contained in:
parent
14af38712b
commit
9300bca1a4
@ -10,9 +10,9 @@ from .OnscreenGeom import OnscreenGeom
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
stringTypes = (str,)
|
||||
stringType = str
|
||||
else:
|
||||
stringTypes = (str, unicode)
|
||||
stringType = basestring
|
||||
|
||||
|
||||
class DirectFrame(DirectGuiWidget):
|
||||
@ -60,7 +60,7 @@ class DirectFrame(DirectGuiWidget):
|
||||
# Determine if user passed in single string or a sequence
|
||||
if self['text'] == None:
|
||||
textList = (None,) * self['numStates']
|
||||
elif isinstance(self['text'], stringTypes):
|
||||
elif isinstance(self['text'], stringType):
|
||||
# If just passing in a single string, make a tuple out of it
|
||||
textList = (self['text'],) * self['numStates']
|
||||
else:
|
||||
@ -103,7 +103,7 @@ class DirectFrame(DirectGuiWidget):
|
||||
# Passed in None
|
||||
geomList = (None,) * self['numStates']
|
||||
elif isinstance(geom, NodePath) or \
|
||||
isinstance(geom, stringTypes):
|
||||
isinstance(geom, stringType):
|
||||
# Passed in a single node path, make a tuple out of it
|
||||
geomList = (geom,) * self['numStates']
|
||||
else:
|
||||
@ -145,14 +145,14 @@ class DirectFrame(DirectGuiWidget):
|
||||
imageList = (None,) * self['numStates']
|
||||
elif isinstance(arg, NodePath) or \
|
||||
isinstance(arg, Texture) or \
|
||||
isinstance(arg, stringTypes):
|
||||
isinstance(arg, stringType):
|
||||
# Passed in a single node path, make a tuple out of it
|
||||
imageList = (arg,) * self['numStates']
|
||||
else:
|
||||
# Otherwise, hope that the user has passed in a tuple/list
|
||||
if ((len(arg) == 2) and
|
||||
isinstance(arg[0], stringTypes) and
|
||||
isinstance(arg[1], stringTypes)):
|
||||
isinstance(arg[0], stringType) and
|
||||
isinstance(arg[1], stringType)):
|
||||
# Its a model/node pair of strings
|
||||
imageList = (arg,) * self['numStates']
|
||||
else:
|
||||
|
@ -12,6 +12,12 @@ from .OnscreenImage import *
|
||||
from direct.directtools.DirectUtil import ROUND_TO
|
||||
from direct.showbase import DirectObject
|
||||
from direct.task import Task
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
stringType = str
|
||||
else:
|
||||
stringType = basestring
|
||||
|
||||
guiObjectCollector = PStatCollector("Client::GuiObjects")
|
||||
|
||||
@ -943,7 +949,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
# Convert None, and string arguments
|
||||
if relief == None:
|
||||
relief = PGFrameStyle.TNone
|
||||
elif isinstance(relief, str):
|
||||
elif isinstance(relief, stringType):
|
||||
# Convert string to frame style int
|
||||
relief = DGG.FrameStyleDict[relief]
|
||||
# Set style
|
||||
@ -984,14 +990,14 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
textures = self['frameTexture']
|
||||
if textures == None or \
|
||||
isinstance(textures, Texture) or \
|
||||
isinstance(textures, str):
|
||||
isinstance(textures, stringType):
|
||||
textures = (textures,) * self['numStates']
|
||||
for i in range(self['numStates']):
|
||||
if i >= len(textures):
|
||||
texture = textures[-1]
|
||||
else:
|
||||
texture = textures[i]
|
||||
if isinstance(texture, str):
|
||||
if isinstance(texture, stringType):
|
||||
texture = loader.loadTexture(texture)
|
||||
if texture:
|
||||
self.frameStyle[i].setTexture(texture)
|
||||
|
@ -5,7 +5,12 @@ __all__ = ['DirectWaitBar']
|
||||
from panda3d.core import *
|
||||
from . import DirectGuiGlobals as DGG
|
||||
from .DirectFrame import *
|
||||
import types
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
stringType = str
|
||||
else:
|
||||
stringType = basestring
|
||||
|
||||
"""
|
||||
import DirectWaitBar
|
||||
@ -93,7 +98,7 @@ class DirectWaitBar(DirectFrame):
|
||||
"""Updates the bar texture, which you can set using bar['barTexture']."""
|
||||
# this must be a single texture (or a string).
|
||||
texture = self['barTexture']
|
||||
if isinstance(texture, str):
|
||||
if isinstance(texture, stringType):
|
||||
texture = loader.loadTexture(texture)
|
||||
if texture:
|
||||
self.barStyle.setTexture(texture)
|
||||
|
@ -4,7 +4,12 @@ __all__ = ['OnscreenGeom']
|
||||
|
||||
from panda3d.core import *
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
stringType = str
|
||||
else:
|
||||
stringType = basestring
|
||||
|
||||
class OnscreenGeom(DirectObject, NodePath):
|
||||
def __init__(self, geom = None,
|
||||
@ -93,7 +98,7 @@ class OnscreenGeom(DirectObject, NodePath):
|
||||
# Assign geometry
|
||||
if isinstance(geom, NodePath):
|
||||
self.assign(geom.copyTo(parent, sort))
|
||||
elif isinstance(geom, str):
|
||||
elif isinstance(geom, stringType):
|
||||
self.assign(loader.loadModel(geom))
|
||||
self.reparentTo(parent, sort)
|
||||
|
||||
|
@ -4,6 +4,12 @@ __all__ = ['OnscreenImage']
|
||||
|
||||
from panda3d.core import *
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
stringType = str
|
||||
else:
|
||||
stringType = basestring
|
||||
|
||||
|
||||
class OnscreenImage(DirectObject, NodePath):
|
||||
@ -95,7 +101,7 @@ class OnscreenImage(DirectObject, NodePath):
|
||||
# Assign geometry
|
||||
if isinstance(image, NodePath):
|
||||
self.assign(image.copyTo(parent, sort))
|
||||
elif isinstance(image, str) or \
|
||||
elif isinstance(image, stringType) or \
|
||||
isinstance(image, Texture):
|
||||
if isinstance(image, Texture):
|
||||
# It's a Texture
|
||||
|
Loading…
x
Reference in New Issue
Block a user