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): def setGeom(self):
# Determine argument type # Determine argument type
if self['geom'] == None: geom = self['geom']
if geom == None:
# Passed in None # Passed in None
geomList = (None,) * self['numStates'] 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 # Passed in a single node path, make a tuple out of it
geomList = (self['geom'],) * self['numStates'] geomList = (geom,) * 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
geomList = self['geom'] geomList = geom
# Create/destroy components # Create/destroy components
for i in range(self['numStates']): for i in range(self['numStates']):
component = 'geom' + `i` component = 'geom' + `i`

View File

@ -968,13 +968,17 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
def setFrameTexture(self): def setFrameTexture(self):
# this might be a single texture or a list of textures # this might be a single texture or a list of textures
textures = self['frameTexture'] textures = self['frameTexture']
if textures == None or isinstance(textures, Texture): if textures == None or \
textures = (textures,) isinstance(textures, Texture) or \
isinstance(textures, types.StringTypes):
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, types.StringTypes):
texture = loader.loadTexture(texture)
if texture: if texture:
self.frameStyle[i].setTexture(texture) self.frameStyle[i].setTexture(texture)
self.updateFrameStyle() self.updateFrameStyle()

View File

@ -42,14 +42,8 @@ class OnscreenGeom(PandaObject, NodePath):
NodePath.__init__(self) NodePath.__init__(self)
if parent == None: if parent == None:
parent = aspect2d parent = aspect2d
self.parent = parent
# Assign geometry self.setGeom(geom, parent = parent, sort = sort, color = color)
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)
# Adjust pose # Adjust pose
# Set pos # Set pos
@ -74,20 +68,35 @@ class OnscreenGeom(PandaObject, NodePath):
isinstance(scale, types.IntType)): isinstance(scale, types.IntType)):
self.setScale(scale) self.setScale(scale)
# Set color def setGeom(self, geom,
if color: parent = NodePath(),
# Set color, if specified transform = TransformState.makeIdentity(),
self.setColor(color[0], color[1], color[2], color[3]) 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() self.removeNode()
# Assign geometry # Assign geometry
if isinstance(geom, NodePath): if isinstance(geom, NodePath):
self.assign(geom.copyTo(self.parent)) self.assign(geom.copyTo(parent, sort))
elif type(geom) == type(''): elif isinstance(geom, types.StringTypes):
self.assign(loader.loadModelCopy(geom)) 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): def getGeom(self):
return self return self