further robustification

This commit is contained in:
David Rose 2005-08-31 14:17:28 +00:00
parent a4d06505c2
commit 89d5783e95
3 changed files with 40 additions and 23 deletions

View File

@ -81,15 +81,19 @@ class DirectFrame(DirectGuiWidget):
def setGeom(self):
# Determine argument type
if self['geom'] == None:
geom = self['geom']
if geom == None:
# Passed in None
geomList = (None,) * self['numStates']
elif isinstance(self['geom'], NodePath):
elif isinstance(geom, NodePath) or \
isinstance(geom, types.StringTypes):
# Passed in a single node path, make a tuple out of it
geomList = (self['geom'],) * self['numStates']
geomList = (geom,) * self['numStates']
else:
# Otherwise, hope that the user has passed in a tuple/list
geomList = self['geom']
geomList = geom
# Create/destroy components
for i in range(self['numStates']):
component = 'geom' + `i`

View File

@ -968,13 +968,17 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
def setFrameTexture(self):
# this might be a single texture or a list of textures
textures = self['frameTexture']
if textures == None or isinstance(textures, Texture):
textures = (textures,)
if textures == None or \
isinstance(textures, Texture) or \
isinstance(textures, types.StringTypes):
textures = (textures,) * self['numStates']
for i in range(self['numStates']):
if i >= len(textures):
texture = textures[-1]
else:
texture = textures[i]
if isinstance(texture, types.StringTypes):
texture = loader.loadTexture(texture)
if texture:
self.frameStyle[i].setTexture(texture)
self.updateFrameStyle()

View File

@ -42,14 +42,8 @@ class OnscreenGeom(PandaObject, NodePath):
NodePath.__init__(self)
if parent == None:
parent = aspect2d
self.parent = parent
# Assign geometry
self.sort = sort
if isinstance(geom, NodePath):
self.assign(geom.copyTo(parent, self.sort))
elif type(geom) == type(''):
self.assign(loader.loadModelCopy(geom))
self.reparentTo(parent, self.sort)
self.setGeom(geom, parent = parent, sort = sort, color = color)
# Adjust pose
# Set pos
@ -74,20 +68,35 @@ class OnscreenGeom(PandaObject, NodePath):
isinstance(scale, types.IntType)):
self.setScale(scale)
# Set color
if color:
# Set color, if specified
self.setColor(color[0], color[1], color[2], color[3])
def setGeom(self, geom,
parent = NodePath(),
transform = TransformState.makeIdentity(),
sort = 0,
color = None):
# Get the original parent, transform, and sort, if any, so we can
# preserve them across this call.
if not self.isEmpty():
parent = self.getParent()
transform = self.getTransform()
sort = self.getSort()
if self.hasColor():
color = self.getColor()
def setGeom(self, geom):
# Assign geometry
self.removeNode()
# Assign geometry
if isinstance(geom, NodePath):
self.assign(geom.copyTo(self.parent))
elif type(geom) == type(''):
self.assign(geom.copyTo(parent, sort))
elif isinstance(geom, types.StringTypes):
self.assign(loader.loadModelCopy(geom))
self.reparentTo(self.parent)
self.reparentTo(parent, sort)
if not self.isEmpty():
self.setTransform(transform)
# Set color, if specified
if color:
self.setColor(color[0], color[1], color[2], color[3])
def getGeom(self):
return self