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