diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index e2cdb262df..320df38e8c 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -403,14 +403,14 @@ class Actor(PandaObject, NodePath): return self.__hasLOD def update(self, lod=0): - """ update(lod) - """ - if (lod < len(self.__partBundleDict.values())): - partBundles = self.__partBundleDict.values()[lod].values() - for partBundle in partBundles: - partBundle.node().update() - else: - self.notify.warning('update() - no lod: %d' % lod) + """ update(lod) + """ + if (lod < len(self.__partBundleDict.values())): + partBundles = self.__partBundleDict.values()[lod].values() + for partBundle in partBundles: + partBundle.node().update() + else: + self.notify.warning('update() - no lod: %d' % lod) def getFrameRate(self, animName=None, partName=None): """getFrameRate(self, string, string=None) @@ -507,21 +507,21 @@ class Actor(PandaObject, NodePath): return None def getNumFrames(self, animName=None, partName=None): - """ getNumFrames(animName, partName) - """ - lodName = self.__animControlDict.keys()[0] - if (partName == None): - partName = self.__animControlDict[lodName].keys()[0] - if (animName == None): - animName = self.getCurrentAnim(partName) - if (self.__animControlDict[lodName].has_key(partName)): - animControl = self.getAnimControl(animName, partName, lodName) - if (animControl != None): - return animControl.getNumFrames() - else: - Actor.notify.error('no anim control!') - else: - Actor.notify.warning('no part named: %s' % (partName)) + """ getNumFrames(animName, partName) + """ + lodName = self.__animControlDict.keys()[0] + if (partName == None): + partName = self.__animControlDict[lodName].keys()[0] + if (animName == None): + animName = self.getCurrentAnim(partName) + if (self.__animControlDict[lodName].has_key(partName)): + animControl = self.getAnimControl(animName, partName, lodName) + if (animControl != None): + return animControl.getNumFrames() + else: + Actor.notify.error('no anim control!') + else: + Actor.notify.warning('no part named: %s' % (partName)) def getCurrentAnim(self, partName=None): """getCurrentAnim(self, string=None) @@ -930,19 +930,19 @@ class Actor(PandaObject, NodePath): animControl = self.getAnimControl(animName, thisPart, thisLod) if (animControl != None): - if (fromFrame == None): + if (fromFrame == None): animControl.play() - else: - animControl.play(fromFrame, toFrame) + else: + animControl.play(fromFrame, toFrame) else: animControl = self.getAnimControl(animName, partName, thisLod) if (animControl != None): - if (fromFrame == None): - animControl.play() - else: - animControl.play(fromFrame, toFrame) + if (fromFrame == None): + animControl.play() + else: + animControl.play(fromFrame, toFrame) def loop(self, animName, restart=1, partName=None): @@ -981,7 +981,7 @@ class Actor(PandaObject, NodePath): animControl = self.getAnimControl(animName, thisPart, thisLod) if (animControl != None): - animControl.pingpong(restart, fromFrame, toFrame) + animControl.pingpong(restart, fromFrame, toFrame) else: # loop a specific part animControl = self.getAnimControl(animName, partName, diff --git a/direct/src/actor/DistributedActor.py b/direct/src/actor/DistributedActor.py index cb61ea75df..2636b51180 100644 --- a/direct/src/actor/DistributedActor.py +++ b/direct/src/actor/DistributedActor.py @@ -21,7 +21,7 @@ class DistributedActor(DistributedNode.DistributedNode, Actor.Actor): def disable(self): # remove all anims, on all parts and all lods - if (not self.isEmpty()): + if (not self.isEmpty()): Actor.Actor.unloadAnims(self, None, None, None) DistributedNode.DistributedNode.disable(self) diff --git a/direct/src/directtools/DirectCameraControl.py b/direct/src/directtools/DirectCameraControl.py index 7d03633530..35b2c71626 100644 --- a/direct/src/directtools/DirectCameraControl.py +++ b/direct/src/directtools/DirectCameraControl.py @@ -10,8 +10,8 @@ class DirectCameraControl(PandaObject): # Create the grid self.startT = 0.0 self.startF = 0 - self.orthoViewRoll = 0.0 - self.lastView = 0 + self.orthoViewRoll = 0.0 + self.lastView = 0 self.coa = Point3(0,100,0) self.coaMarker = loader.loadModel('models/misc/sphere') self.coaMarker.setName('DirectCameraCOAMarker') @@ -24,7 +24,7 @@ class DirectCameraControl(PandaObject): self.nullHitPointCount = 0 self.cqEntries = [] self.coaMarkerRef = direct.group.attachNewNode('coaMarkerRef') - self.camManipRef = direct.group.attachNewNode('camManipRef') + self.camManipRef = direct.group.attachNewNode('camManipRef') t = CAM_MOVE_DURATION self.actionEvents = [ ['DIRECT_mouse2', self.mouseFlyStart], @@ -63,7 +63,7 @@ class DirectCameraControl(PandaObject): def mouseFlyStart(self): # Record undo point direct.pushUndo([direct.camera]) - # Where are we in the display region? + # Where are we in the display region? if ((abs(direct.dr.mouseX) < 0.9) and (abs(direct.dr.mouseY) < 0.9)): # MOUSE IS IN CENTRAL REGION # Hide the marker for this kind of motion @@ -84,7 +84,7 @@ class DirectCameraControl(PandaObject): self.spawnMouseRotateTask() def mouseFlyStop(self): - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') stopT = globalClock.getFrameTime() deltaT = stopT - self.startT stopF = globalClock.getFrameCount() @@ -110,7 +110,7 @@ class DirectCameraControl(PandaObject): def spawnXZTranslateOrHPanYZoom(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Spawn the new task t = Task.Task(self.XZTranslateOrHPanYZoomTask) # For HPanYZoom @@ -120,20 +120,20 @@ class DirectCameraControl(PandaObject): def spawnXZTranslateOrHPPan(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Spawn new task taskMgr.spawnMethodNamed(self.XZTranslateOrHPPanTask, 'manipulateCamera') def spawnXZTranslate(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Spawn new task taskMgr.spawnMethodNamed(self.XZTranslateTask, 'manipulateCamera') def spawnHPanYZoom(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Spawn new task t = Task.Task(self.HPanYZoomTask) coaDist = Vec3(self.coaMarker.getPos(direct.camera)).length() @@ -142,7 +142,7 @@ class DirectCameraControl(PandaObject): def spawnHPPan(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Spawn new task taskMgr.spawnMethodNamed(self.HPPanTask, 'manipulateCamera') @@ -206,10 +206,10 @@ class DirectCameraControl(PandaObject): def spawnMouseRotateTask(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Set at markers position in render coordinates - self.camManipRef.setPos(self.coaMarkerPos) - self.camManipRef.setHpr(direct.camera, ZERO_POINT) + self.camManipRef.setPos(self.coaMarkerPos) + self.camManipRef.setHpr(direct.camera, ZERO_POINT) t = Task.Task(self.mouseRotateTask) if abs(direct.dr.mouseX) > 0.9: t.constrainedDir = 'y' @@ -246,14 +246,14 @@ class DirectCameraControl(PandaObject): def spawnMouseRollTask(self): # Kill any existing tasks - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Set at markers position in render coordinates - self.camManipRef.setPos(self.coaMarkerPos) - self.camManipRef.setHpr(direct.camera, ZERO_POINT) + self.camManipRef.setPos(self.coaMarkerPos) + self.camManipRef.setHpr(direct.camera, ZERO_POINT) t = Task.Task(self.mouseRollTask) t.coaCenter = getScreenXY(self.coaMarker) t.lastAngle = getCrankAngle(t.coaCenter) - t.wrtMat = direct.camera.getMat( self.camManipRef ) + t.wrtMat = direct.camera.getMat( self.camManipRef ) taskMgr.spawnTaskNamed(t, 'manipulateCamera') def mouseRollTask(self, state): @@ -384,19 +384,19 @@ class DirectCameraControl(PandaObject): self.updateCoaMarkerSize() def uprightCam(self): - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Record undo point direct.pushUndo([direct.camera]) # Pitch camera till upright currH = direct.camera.getH() - direct.camera.lerpHpr(currH, 0, 0, + direct.camera.lerpHpr(currH, 0, 0, CAM_MOVE_DURATION, other = render, blendType = 'easeInOut', task = 'manipulateCamera') def orbitUprightCam(self): - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Record undo point direct.pushUndo([direct.camera]) # Transform camera z axis to render space @@ -421,10 +421,10 @@ class DirectCameraControl(PandaObject): self.camManipRef.setPos(self.coaMarker, Vec3(0)) self.camManipRef.setHpr(render, rotAngle, 0, 0) # Reparent Cam to ref Coordinate system - parent = direct.camera.getParent() - direct.camera.wrtReparentTo(self.camManipRef) + parent = direct.camera.getParent() + direct.camera.wrtReparentTo(self.camManipRef) # Rotate ref CS to final orientation - t = self.camManipRef.lerpHpr(rotAngle, orbitAngle, 0, + t = self.camManipRef.lerpHpr(rotAngle, orbitAngle, 0, CAM_MOVE_DURATION, other = render, blendType = 'easeInOut', @@ -434,22 +434,22 @@ class DirectCameraControl(PandaObject): t.uponDeath = self.reparentCam def centerCam(self): - self.centerCamIn(1.0) + self.centerCamIn(1.0) def centerCamNow(self): self.centerCamIn(0.) def centerCamIn(self, t): - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Record undo point direct.pushUndo([direct.camera]) # Determine marker location markerToCam = self.coaMarker.getPos( direct.camera ) - dist = Vec3(markerToCam - ZERO_POINT).length() - scaledCenterVec = Y_AXIS * dist - delta = markerToCam - scaledCenterVec - self.camManipRef.setPosHpr(direct.camera, Point3(0), Point3(0)) - t = direct.camera.lerpPos(Point3(delta), + dist = Vec3(markerToCam - ZERO_POINT).length() + scaledCenterVec = Y_AXIS * dist + delta = markerToCam - scaledCenterVec + self.camManipRef.setPosHpr(direct.camera, Point3(0), Point3(0)) + t = direct.camera.lerpPos(Point3(delta), CAM_MOVE_DURATION, other = self.camManipRef, blendType = 'easeInOut', @@ -457,16 +457,16 @@ class DirectCameraControl(PandaObject): t.uponDeath = self.updateCoaMarkerSizeOnDeath def zoomCam(self, zoomFactor, t): - taskMgr.removeTasksNamed('manipulateCamera') + taskMgr.removeTasksNamed('manipulateCamera') # Record undo point direct.pushUndo([direct.camera]) - # Find a point zoom factor times the current separation + # Find a point zoom factor times the current separation # of the widget and cam zoomPtToCam = self.coaMarker.getPos(direct.camera) * zoomFactor - # Put a target nodePath there - self.camManipRef.setPos(direct.camera, zoomPtToCam) - # Move to that point - t = direct.camera.lerpPos(ZERO_POINT, + # Put a target nodePath there + self.camManipRef.setPos(direct.camera, zoomPtToCam) + # Move to that point + t = direct.camera.lerpPos(ZERO_POINT, CAM_MOVE_DURATION, other = self.camManipRef, blendType = 'easeInOut', @@ -526,20 +526,20 @@ class DirectCameraControl(PandaObject): def swingCamAboutWidget(self, degrees, t): # Remove existing camera manipulation task - taskMgr.removeTasksNamed('manipulateCamera') - + taskMgr.removeTasksNamed('manipulateCamera') + # Record undo point direct.pushUndo([direct.camera]) - # Coincident with widget + # Coincident with widget self.camManipRef.setPos(self.coaMarker, ZERO_POINT) - # But aligned with render space - self.camManipRef.setHpr(ZERO_POINT) + # But aligned with render space + self.camManipRef.setHpr(ZERO_POINT) - parent = direct.camera.getParent() - direct.camera.wrtReparentTo(self.camManipRef) + parent = direct.camera.getParent() + direct.camera.wrtReparentTo(self.camManipRef) - manipTask = self.camManipRef.lerpHpr(VBase3(degrees,0,0), + manipTask = self.camManipRef.lerpHpr(VBase3(degrees,0,0), CAM_MOVE_DURATION, blendType = 'easeInOut', task = 'manipulateCamera') @@ -576,9 +576,9 @@ class DirectCameraControl(PandaObject): # Move a target there self.camManipRef.setPos(direct.camera, deltaMove) - parent = direct.camera.getParent() - direct.camera.wrtReparentTo(self.camManipRef) - fitTask = direct.camera.lerpPos(Point3(0,0,0), + parent = direct.camera.getParent() + direct.camera.wrtReparentTo(self.camManipRef) + fitTask = direct.camera.lerpPos(Point3(0,0,0), CAM_MOVE_DURATION, blendType = 'easeInOut', task = 'manipulateCamera') @@ -620,8 +620,8 @@ class DirectCameraControl(PandaObject): return Task.cont def enableMouseFly(self): - # disable C++ fly interface - base.disableMouse() + # disable C++ fly interface + base.disableMouse() # Enable events for event in self.actionEvents: self.accept(event[0], event[1], extraArgs = event[2:]) @@ -631,10 +631,10 @@ class DirectCameraControl(PandaObject): def disableMouseFly(self): # Hide the marker self.coaMarker.reparentTo(hidden) - # Ignore events + # Ignore events for event in self.actionEvents: self.ignore(event[0]) - base.enableMouse() + base.enableMouse() def removeManipulateCameraTask(self): taskMgr.removeTasksNamed('manipulateCamera') diff --git a/direct/src/directtools/DirectGrid.py b/direct/src/directtools/DirectGrid.py index 0dcc742be7..80efbe759b 100644 --- a/direct/src/directtools/DirectGrid.py +++ b/direct/src/directtools/DirectGrid.py @@ -9,42 +9,42 @@ class DirectGrid(NodePath,PandaObject): # Don't wireframe or light useDirectRenderStyle(self) - # Load up grid parts to initialize grid object - # Polygon used to mark grid plane - self.gridBack = loader.loadModel('models/misc/gridBack') - self.gridBack.reparentTo(self) - self.gridBack.setColor(0.5,0.5,0.5,0.5) + # Load up grid parts to initialize grid object + # Polygon used to mark grid plane + self.gridBack = loader.loadModel('models/misc/gridBack') + self.gridBack.reparentTo(self) + self.gridBack.setColor(0.5,0.5,0.5,0.5) - # Grid Lines + # Grid Lines self.lines = self.attachNewNode('gridLines') - self.minorLines = LineNodePath(self.lines) + self.minorLines = LineNodePath(self.lines) self.minorLines.lineNode.setName('minorLines') - self.minorLines.setColor(VBase4(0.3,0.55,1,1)) - self.minorLines.setThickness(1) + self.minorLines.setColor(VBase4(0.3,0.55,1,1)) + self.minorLines.setThickness(1) - self.majorLines = LineNodePath(self.lines) + self.majorLines = LineNodePath(self.lines) self.majorLines.lineNode.setName('majorLines') - self.majorLines.setColor(VBase4(0.3,0.55,1,1)) - self.majorLines.setThickness(5) + self.majorLines.setColor(VBase4(0.3,0.55,1,1)) + self.majorLines.setThickness(5) - self.centerLines = LineNodePath(self.lines) + self.centerLines = LineNodePath(self.lines) self.centerLines.lineNode.setName('centerLines') - self.centerLines.setColor(VBase4(1,0,0,0)) - self.centerLines.setThickness(3) + self.centerLines.setColor(VBase4(1,0,0,0)) + self.centerLines.setThickness(3) - # Small marker to hilight snap-to-grid point - self.snapMarker = loader.loadModel('models/misc/sphere') - self.snapMarker.node().setName('gridSnapMarker') - self.snapMarker.reparentTo(self) - self.snapMarker.setColor(1,0,0,1) - self.snapMarker.setScale(0.3) + # Small marker to hilight snap-to-grid point + self.snapMarker = loader.loadModel('models/misc/sphere') + self.snapMarker.node().setName('gridSnapMarker') + self.snapMarker.reparentTo(self) + self.snapMarker.setColor(1,0,0,1) + self.snapMarker.setScale(0.3) self.snapPos = Point3(0) - # Initialize Grid characteristics + # Initialize Grid characteristics self.fXyzSnap = 1 self.fHprSnap = 1 - self.gridSize = 100.0 - self.gridSpacing = 5.0 + self.gridSize = 100.0 + self.gridSpacing = 5.0 self.snapAngle = 15.0 self.enable() @@ -67,15 +67,15 @@ class DirectGrid(NodePath,PandaObject): return self.fEnabled def updateGrid(self): - # Update grid lines based upon current grid spacing and grid size - # First reset existing grid lines - self.minorLines.reset() - self.majorLines.reset() - self.centerLines.reset() + # Update grid lines based upon current grid spacing and grid size + # First reset existing grid lines + self.minorLines.reset() + self.majorLines.reset() + self.centerLines.reset() - # Now redraw lines - numLines = math.ceil(self.gridSize/self.gridSpacing) - scaledSize = numLines * self.gridSpacing + # Now redraw lines + numLines = math.ceil(self.gridSize/self.gridSpacing) + scaledSize = numLines * self.gridSpacing center = self.centerLines minor = self.minorLines @@ -125,11 +125,11 @@ class DirectGrid(NodePath,PandaObject): ROUND_TO(self.snapPos[1], self.gridSpacing), ROUND_TO(self.snapPos[2], self.gridSpacing)) - # Move snap marker to this point - self.snapMarker.setPos(self.snapPos) - - # Return the hit point - return self.snapPos + # Move snap marker to this point + self.snapMarker.setPos(self.snapPos) + + # Return the hit point + return self.snapPos def computeSnapAngle(self, angle): return ROUND_TO(angle, self.snapAngle) @@ -148,9 +148,9 @@ class DirectGrid(NodePath,PandaObject): return self.gridSpacing def setGridSize(self, size): - # Set size of grid back and redraw lines + # Set size of grid back and redraw lines self.gridSize = size - self.updateGrid() + self.updateGrid() def getGridSize(self): return self.gridSize diff --git a/direct/src/directtools/DirectManipulation.py b/direct/src/directtools/DirectManipulation.py index 2b36a513c1..6d235223d2 100644 --- a/direct/src/directtools/DirectManipulation.py +++ b/direct/src/directtools/DirectManipulation.py @@ -138,12 +138,12 @@ class DirectManipulationControl(PandaObject): return Task.cont def enableManipulation(self): - # Accept events + # Accept events for event in self.actionEvents: self.accept(event[0], event[1], extraArgs = event[2:]) def disableManipulation(self): - # Ignore events + # Ignore events for event in self.actionEvents: self.ignore(event[0]) @@ -276,7 +276,7 @@ class DirectManipulationControl(PandaObject): self.fHitInit = 0 self.prevHit.assign(self.hitPt) else: - offset = self.hitPt - self.prevHit + offset = self.hitPt - self.prevHit direct.widget.setPos(direct.widget, offset) def rotate1D(self, state): @@ -466,7 +466,7 @@ class DirectManipulationControl(PandaObject): ## Utility functions ## def plantSelectedNodePath(self): - """ Move selected object to intersection point of cursor on scene """ + """ Move selected object to intersection point of cursor on scene """ # Check for intersection node, hitPt, hitPtDist = direct.iRay.pickGeom( fIntersectUnpickable = 1) @@ -747,25 +747,25 @@ class ObjectHandles(NodePath,PandaObject): def createObjectHandleLines(self): # X post self.xPost = self.xPostGroup.attachNewNode('x-post-visible') - lines = LineNodePath(self.xPost) - lines.setColor(VBase4(1,0,0,1)) - lines.setThickness(5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.xPost) + lines.setColor(VBase4(1,0,0,1)) + lines.setThickness(5) + lines.moveTo(0,0,0) lines.drawTo(1.5,0,0) lines.create() - lines = LineNodePath(self.xPost) - lines.setColor(VBase4(1,0,0,1)) - lines.setThickness(1.5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.xPost) + lines.setColor(VBase4(1,0,0,1)) + lines.setThickness(1.5) + lines.moveTo(0,0,0) lines.drawTo(-1.5,0,0) lines.create() - # X ring + # X ring self.xRing = self.xRingGroup.attachNewNode('x-ring-visible') - lines = LineNodePath(self.xRing) - lines.setColor(VBase4(1,0,0,1)) - lines.setThickness(3) - lines.moveTo(0,1,0) + lines = LineNodePath(self.xRing) + lines.setColor(VBase4(1,0,0,1)) + lines.setThickness(3) + lines.moveTo(0,1,0) for ang in range(15, 370, 15): lines.drawTo(0, math.cos(deg2Rad(ang)), @@ -774,25 +774,25 @@ class ObjectHandles(NodePath,PandaObject): # Y post self.yPost = self.yPostGroup.attachNewNode('y-post-visible') - lines = LineNodePath(self.yPost) - lines.setColor(VBase4(0,1,0,1)) - lines.setThickness(5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.yPost) + lines.setColor(VBase4(0,1,0,1)) + lines.setThickness(5) + lines.moveTo(0,0,0) lines.drawTo(0,1.5,0) lines.create() - lines = LineNodePath(self.yPost) - lines.setColor(VBase4(0,1,0,1)) - lines.setThickness(1.5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.yPost) + lines.setColor(VBase4(0,1,0,1)) + lines.setThickness(1.5) + lines.moveTo(0,0,0) lines.drawTo(0,-1.5,0) lines.create() - # Y ring + # Y ring self.yRing = self.yRingGroup.attachNewNode('y-ring-visible') - lines = LineNodePath(self.yRing) - lines.setColor(VBase4(0,1,0,1)) - lines.setThickness(3) - lines.moveTo(1,0,0) + lines = LineNodePath(self.yRing) + lines.setColor(VBase4(0,1,0,1)) + lines.setThickness(3) + lines.moveTo(1,0,0) for ang in range(15, 370, 15): lines.drawTo(math.cos(deg2Rad(ang)), 0, @@ -801,25 +801,25 @@ class ObjectHandles(NodePath,PandaObject): # Z post self.zPost = self.zPostGroup.attachNewNode('z-post-visible') - lines = LineNodePath(self.zPost) - lines.setColor(VBase4(0,0,1,1)) - lines.setThickness(5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.zPost) + lines.setColor(VBase4(0,0,1,1)) + lines.setThickness(5) + lines.moveTo(0,0,0) lines.drawTo(0,0,1.5) lines.create() - lines = LineNodePath(self.zPost) - lines.setColor(VBase4(0,0,1,1)) - lines.setThickness(1.5) - lines.moveTo(0,0,0) + lines = LineNodePath(self.zPost) + lines.setColor(VBase4(0,0,1,1)) + lines.setThickness(1.5) + lines.moveTo(0,0,0) lines.drawTo(0,0,-1.5) lines.create() - # Z ring + # Z ring self.zRing = self.zRingGroup.attachNewNode('z-ring-visible') - lines = LineNodePath(self.zRing) - lines.setColor(VBase4(0,0,1,1)) - lines.setThickness(3) - lines.moveTo(1,0,0) + lines = LineNodePath(self.zRing) + lines.setColor(VBase4(0,0,1,1)) + lines.setThickness(3) + lines.moveTo(1,0,0) for ang in range(15, 370, 15): lines.drawTo(math.cos(deg2Rad(ang)), math.sin(deg2Rad(ang)), @@ -829,28 +829,28 @@ class ObjectHandles(NodePath,PandaObject): def createGuideLines(self): self.guideLines = self.attachNewNode('guideLines') # X guide lines - lines = LineNodePath(self.guideLines) - lines.setColor(VBase4(1,0,0,1)) - lines.setThickness(0.5) - lines.moveTo(-500,0,0) + lines = LineNodePath(self.guideLines) + lines.setColor(VBase4(1,0,0,1)) + lines.setThickness(0.5) + lines.moveTo(-500,0,0) lines.drawTo(500,0,0) lines.create() lines.node().setName('x-guide') # Y guide lines - lines = LineNodePath(self.guideLines) - lines.setColor(VBase4(0,1,0,1)) - lines.setThickness(0.5) - lines.moveTo(0,-500,0) + lines = LineNodePath(self.guideLines) + lines.setColor(VBase4(0,1,0,1)) + lines.setThickness(0.5) + lines.moveTo(0,-500,0) lines.drawTo(0,500,0) lines.create() lines.node().setName('y-guide') # Z guide lines - lines = LineNodePath(self.guideLines) - lines.setColor(VBase4(0,0,1,1)) - lines.setThickness(0.5) - lines.moveTo(0,0,-500) + lines = LineNodePath(self.guideLines) + lines.setColor(VBase4(0,0,1,1)) + lines.setThickness(0.5) + lines.moveTo(0,0,-500) lines.drawTo(0,0,500) lines.create() lines.node().setName('z-guide') diff --git a/direct/src/directtools/DirectSelection.py b/direct/src/directtools/DirectSelection.py index 13cb4b4d1b..141bb66f89 100644 --- a/direct/src/directtools/DirectSelection.py +++ b/direct/src/directtools/DirectSelection.py @@ -60,12 +60,12 @@ class SelectedNodePaths(PandaObject): def select(self, nodePath, fMultiSelect = 0): """ Select the specified node path. Multiselect as required """ - # Do nothing if nothing selected + # Do nothing if nothing selected if not nodePath: print 'Nothing selected!!' return None - # Reset selected objects and highlight if multiSelect is false + # Reset selected objects and highlight if multiSelect is false if not fMultiSelect: self.deselectAll() @@ -208,17 +208,17 @@ class SelectedNodePaths(PandaObject): self.forEachSelectedNodePathDo(DirectNodePath.dehighlight) def removeSelected(self): - selected = self.last + selected = self.last if selected: selected.remove() __builtin__.last = self.last = None def removeAll(self): - # Remove all selected nodePaths from the Scene Graph + # Remove all selected nodePaths from the Scene Graph self.forEachSelectedNodePathDo(NodePath.remove) def toggleVisSelected(self): - selected = self.last + selected = self.last # Toggle visibility of selected node paths if selected: selected.toggleVis() @@ -228,7 +228,7 @@ class SelectedNodePaths(PandaObject): self.forEachSelectedNodePathDo(NodePath.toggleVis) def isolateSelected(self): - selected = self.last + selected = self.last if selected: selected.isolate() @@ -271,7 +271,7 @@ class DirectBoundingBox: lines = LineNodePath(hidden) lines.node().setName('bboxLines') lines.setColor( VBase4( 1., 0., 0., 1. ) ) - lines.setThickness( 0.5 ) + lines.setThickness( 0.5 ) minX = self.min[0] minY = self.min[1] @@ -281,29 +281,29 @@ class DirectBoundingBox: maxZ = self.max[2] # Bottom face - lines.moveTo( minX, minY, minZ ) - lines.drawTo( maxX, minY, minZ ) - lines.drawTo( maxX, maxY, minZ ) - lines.drawTo( minX, maxY, minZ ) - lines.drawTo( minX, minY, minZ ) + lines.moveTo( minX, minY, minZ ) + lines.drawTo( maxX, minY, minZ ) + lines.drawTo( maxX, maxY, minZ ) + lines.drawTo( minX, maxY, minZ ) + lines.drawTo( minX, minY, minZ ) - # Front Edge/Top face - lines.drawTo( minX, minY, maxZ ) - lines.drawTo( maxX, minY, maxZ ) - lines.drawTo( maxX, maxY, maxZ ) - lines.drawTo( minX, maxY, maxZ ) - lines.drawTo( minX, minY, maxZ ) + # Front Edge/Top face + lines.drawTo( minX, minY, maxZ ) + lines.drawTo( maxX, minY, maxZ ) + lines.drawTo( maxX, maxY, maxZ ) + lines.drawTo( minX, maxY, maxZ ) + lines.drawTo( minX, minY, maxZ ) - # Three remaining edges - lines.moveTo( maxX, minY, minZ ) - lines.drawTo( maxX, minY, maxZ ) - lines.moveTo( maxX, maxY, minZ ) - lines.drawTo( maxX, maxY, maxZ ) - lines.moveTo( minX, maxY, minZ ) - lines.drawTo( minX, maxY, maxZ ) + # Three remaining edges + lines.moveTo( maxX, minY, minZ ) + lines.drawTo( maxX, minY, maxZ ) + lines.moveTo( maxX, maxY, minZ ) + lines.drawTo( maxX, maxY, maxZ ) + lines.moveTo( minX, maxY, minZ ) + lines.drawTo( minX, maxY, maxZ ) # Create and return bbox lines - lines.create() + lines.create() # Make sure bbox is never lit or drawn in wireframe useDirectRenderStyle(lines) @@ -321,26 +321,26 @@ class DirectBoundingBox: maxZ = self.max[2] # Bottom face - ls.setVertex( 0, minX, minY, minZ ) - ls.setVertex( 1, maxX, minY, minZ ) - ls.setVertex( 2, maxX, maxY, minZ ) - ls.setVertex( 3, minX, maxY, minZ ) - ls.setVertex( 4, minX, minY, minZ ) + ls.setVertex( 0, minX, minY, minZ ) + ls.setVertex( 1, maxX, minY, minZ ) + ls.setVertex( 2, maxX, maxY, minZ ) + ls.setVertex( 3, minX, maxY, minZ ) + ls.setVertex( 4, minX, minY, minZ ) - # Front Edge/Top face - ls.setVertex( 5, minX, minY, maxZ ) - ls.setVertex( 6, maxX, minY, maxZ ) - ls.setVertex( 7, maxX, maxY, maxZ ) - ls.setVertex( 8, minX, maxY, maxZ ) - ls.setVertex( 9, minX, minY, maxZ ) + # Front Edge/Top face + ls.setVertex( 5, minX, minY, maxZ ) + ls.setVertex( 6, maxX, minY, maxZ ) + ls.setVertex( 7, maxX, maxY, maxZ ) + ls.setVertex( 8, minX, maxY, maxZ ) + ls.setVertex( 9, minX, minY, maxZ ) - # Three remaining edges - ls.setVertex( 10, maxX, minY, minZ ) - ls.setVertex( 11, maxX, minY, maxZ ) - ls.setVertex( 12, maxX, maxY, minZ ) - ls.setVertex( 13, maxX, maxY, maxZ ) - ls.setVertex( 14, minX, maxY, minZ ) - ls.setVertex( 15, minX, maxY, maxZ ) + # Three remaining edges + ls.setVertex( 10, maxX, minY, minZ ) + ls.setVertex( 11, maxX, minY, maxZ ) + ls.setVertex( 12, maxX, maxY, minZ ) + ls.setVertex( 13, maxX, maxY, maxZ ) + ls.setVertex( 14, minX, maxY, minZ ) + ls.setVertex( 15, minX, maxY, maxZ ) def getBounds(self): # Get a node path's bounds diff --git a/direct/src/directutil/Mopath.py b/direct/src/directutil/Mopath.py index 7ed753252b..aa45967448 100644 --- a/direct/src/directutil/Mopath.py +++ b/direct/src/directutil/Mopath.py @@ -8,40 +8,40 @@ class Mopath(PandaObject): nameIndex = 1 def __init__(self, name = None): - if (name == None): - name = 'mopath%d' % self.nameIndex - self.nameIndex = self.nameIndex + 1 - self.name = name - self.reset() + if (name == None): + name = 'mopath%d' % self.nameIndex + self.nameIndex = self.nameIndex + 1 + self.name = name + self.reset() def getMaxT(self): - return self.maxT + return self.maxT def loadFile(self, filename): - nodePath = loader.loadModel(filename) + nodePath = loader.loadModel(filename) if nodePath: self.__extractCurves(nodePath) - if (self.xyzNurbsCurve != None): - self.maxT = self.xyzNurbsCurve.getMaxT() - elif (self.hprNurbsCurve != None): - self.maxT = self.hprNurbsCurve.getMaxT() - elif (self.tNurbsCurve != None): - self.maxT = self.tNurbsCurve.getMaxT() - else: - print 'Mopath: no valid curves in file: %s' % filename + if (self.xyzNurbsCurve != None): + self.maxT = self.xyzNurbsCurve.getMaxT() + elif (self.hprNurbsCurve != None): + self.maxT = self.hprNurbsCurve.getMaxT() + elif (self.tNurbsCurve != None): + self.maxT = self.tNurbsCurve.getMaxT() + else: + print 'Mopath: no valid curves in file: %s' % filename nodePath.removeNode() - else: - print 'Mopath: no data in file: %s' % filename + else: + print 'Mopath: no data in file: %s' % filename def reset(self): - self.maxT = 0.0 - self.loop = 0 - self.xyzNurbsCurve = None - self.hprNurbsCurve = None - self.tNurbsCurve = None - self.node = None + self.maxT = 0.0 + self.loop = 0 + self.xyzNurbsCurve = None + self.hprNurbsCurve = None + self.tNurbsCurve = None + self.node = None def __extractCurves(self, nodePath): node = nodePath.node() @@ -50,70 +50,70 @@ class Mopath(PandaObject): self.xyzNurbsCurve = node elif node.getCurveType() == PCTHPR: self.hprNurbsCurve = node - elif node.getCurveType() == PCTNONE: - if (self.xyzNurbsCurve == None): - self.xyzNurbsCurve = node - else: - print 'Mopath: got a PCT_NONE curve and an XYZ Curve!' - elif (node.getCurveType() == PCTT): - self.tNurbsCurve = node + elif node.getCurveType() == PCTNONE: + if (self.xyzNurbsCurve == None): + self.xyzNurbsCurve = node + else: + print 'Mopath: got a PCT_NONE curve and an XYZ Curve!' + elif (node.getCurveType() == PCTT): + self.tNurbsCurve = node else: # Iterate over children if any for child in nodePath.getChildrenAsList(): self.__extractCurves(child) def getFinalState(self): - """ getFinalState() - """ - pos = Point3(0) - if (self.xyzNurbsCurve != None): - self.xyzNurbsCurve.getPoint(self.maxT, pos) - hpr = Point3(0) - if (self.hprNurbsCurve != None): - self.hprNurbsCurve.getPoint(self.maxT, hpr) - return (pos, hpr) + """ getFinalState() + """ + pos = Point3(0) + if (self.xyzNurbsCurve != None): + self.xyzNurbsCurve.getPoint(self.maxT, pos) + hpr = Point3(0) + if (self.hprNurbsCurve != None): + self.hprNurbsCurve.getPoint(self.maxT, hpr) + return (pos, hpr) def goTo(self, node, time): - if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None): - print 'Mopath: Mopath has no curves' - return - self.playbackTime = CLAMP(time, 0.0, self.maxT) - if (self.xyzNurbsCurve != None): - pos = Point3(0) - self.xyzNurbsCurve.getPoint(self.playbackTime, pos) - node.setPos(pos) - if (self.hprNurbsCurve != None): - hpr = Point3(0) - self.hprNurbsCurve.getPoint(self.playbackTime, hpr) - node.setHpr(hpr) + if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None): + print 'Mopath: Mopath has no curves' + return + self.playbackTime = CLAMP(time, 0.0, self.maxT) + if (self.xyzNurbsCurve != None): + pos = Point3(0) + self.xyzNurbsCurve.getPoint(self.playbackTime, pos) + node.setPos(pos) + if (self.hprNurbsCurve != None): + hpr = Point3(0) + self.hprNurbsCurve.getPoint(self.playbackTime, hpr) + node.setHpr(hpr) def play(self, node, time = 0.0, loop = 0): - if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None): - print 'Mopath: Mopath has no curves' - return - self.node = node - self.loop = loop - self.stop() - t = taskMgr.spawnMethodNamed(self.__playTask, self.name + '-play') - t.currentTime = time - t.lastTime = globalClock.getFrameTime() + if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None): + print 'Mopath: Mopath has no curves' + return + self.node = node + self.loop = loop + self.stop() + t = taskMgr.spawnMethodNamed(self.__playTask, self.name + '-play') + t.currentTime = time + t.lastTime = globalClock.getFrameTime() def stop(self): - taskMgr.removeTasksNamed(self.name + '-play') + taskMgr.removeTasksNamed(self.name + '-play') def __playTask(self, state): - time = globalClock.getFrameTime() - dTime = time - state.lastTime - state.lastTime = time - if (self.loop): - cTime = (state.currentTime + dTime) % self.maxT - else: - cTime = state.currentTime + dTime - if ((self.loop == 0) and (cTime > self.maxT)): - self.stop() - messenger.send(self.name + '-done') - self.node = None - return Task.done - self.goTo(self.node, cTime) - state.currentTime = cTime - return Task.cont + time = globalClock.getFrameTime() + dTime = time - state.lastTime + state.lastTime = time + if (self.loop): + cTime = (state.currentTime + dTime) % self.maxT + else: + cTime = state.currentTime + dTime + if ((self.loop == 0) and (cTime > self.maxT)): + self.stop() + messenger.send(self.name + '-done') + self.node = None + return Task.done + self.goTo(self.node, cTime) + state.currentTime = cTime + return Task.cont diff --git a/direct/src/distributed/ClientDistClass.py b/direct/src/distributed/ClientDistClass.py index 05bac0aa45..7f00a58ad7 100644 --- a/direct/src/distributed/ClientDistClass.py +++ b/direct/src/distributed/ClientDistClass.py @@ -5,7 +5,7 @@ import DirectNotifyGlobal import ClientDistUpdate class ClientDistClass: - + def __init__(self, dcClass): self.number = dcClass.getNumber() self.name = dcClass.getName() diff --git a/direct/src/distributed/ClientRepository.py b/direct/src/distributed/ClientRepository.py index bd97ae1fdf..97c2048a2f 100644 --- a/direct/src/distributed/ClientRepository.py +++ b/direct/src/distributed/ClientRepository.py @@ -177,7 +177,7 @@ class ClientRepository(DirectObject.DirectObject): if self.doId2do.has_key(doId): # If so, just update it. distObj = self.doId2do[doId] - distObj.generate() + distObj.generate() distObj.updateRequiredFields(cdc, di) distObj.announceGenerate() @@ -190,7 +190,7 @@ class ClientRepository(DirectObject.DirectObject): self.doId2do[doId] = distObj self.doId2cdc[doId] = cdc # and update it. - distObj.generate() + distObj.generate() distObj.updateRequiredFields(cdc, di) distObj.announceGenerate() @@ -205,7 +205,7 @@ class ClientRepository(DirectObject.DirectObject): self.doId2cdc[doId] = cdc # Update the required fields distObj.generateInit() # Only called when constructed - distObj.generate() + distObj.generate() distObj.updateRequiredFields(cdc, di) distObj.announceGenerate() @@ -216,7 +216,7 @@ class ClientRepository(DirectObject.DirectObject): if self.doId2do.has_key(doId): # If so, just update it. distObj = self.doId2do[doId] - distObj.generate() + distObj.generate() distObj.updateRequiredOtherFields(cdc, di) distObj.announceGenerate() @@ -229,7 +229,7 @@ class ClientRepository(DirectObject.DirectObject): self.doId2do[doId] = distObj self.doId2cdc[doId] = cdc # and update it. - distObj.generate() + distObj.generate() distObj.updateRequiredOtherFields(cdc, di) distObj.announceGenerate() @@ -244,7 +244,7 @@ class ClientRepository(DirectObject.DirectObject): self.doId2cdc[doId] = cdc # Update the required fields distObj.generateInit() # Only called when constructed - distObj.generate() + distObj.generate() distObj.updateRequiredOtherFields(cdc, di) distObj.announceGenerate() diff --git a/direct/src/distributed/MsgTypes.py b/direct/src/distributed/MsgTypes.py index a20e93d34d..1633e99c6c 100644 --- a/direct/src/distributed/MsgTypes.py +++ b/direct/src/distributed/MsgTypes.py @@ -1,6 +1,6 @@ """MsgTypes module: contains distributed object message types""" -CLIENT_OBJECT_UPDATE_FIELD = 24 +CLIENT_OBJECT_UPDATE_FIELD = 24 CLIENT_OBJECT_UPDATE_FIELD_RESP = 24 CLIENT_OBJECT_DISABLE_RESP = 25 CLIENT_OBJECT_DELETE_RESP = 27 diff --git a/direct/src/ffi/FFIOverload.py b/direct/src/ffi/FFIOverload.py index 57e195bb5e..cebfeebe3c 100644 --- a/direct/src/ffi/FFIOverload.py +++ b/direct/src/ffi/FFIOverload.py @@ -175,7 +175,7 @@ def subclass(type1, type2): """ # If the types are the same, return 0 if type1 == type2: - return 0 + return 0 # If you have no args, sort you first elif (type1 == 0): return 1 @@ -183,7 +183,7 @@ def subclass(type1, type2): return -1 # If class1 inherits from class2 return 1 elif inheritsFrom(type1, type2): - return 1 + return 1 # If class2 inherits from class1 return -1 elif inheritsFrom(type2, type1): return -1 diff --git a/direct/src/fsm/FSM.py b/direct/src/fsm/FSM.py index ab6f085ea3..9ce8655405 100644 --- a/direct/src/fsm/FSM.py +++ b/direct/src/fsm/FSM.py @@ -86,8 +86,8 @@ class FSM(DirectObject): self.__states = states def addState(self, state): - """addState(state)""" - self.__states.append(state) + """addState(state)""" + self.__states.append(state) def getInitialState(self): """getInitialState(self)""" diff --git a/direct/src/fsm/StateData.py b/direct/src/fsm/StateData.py index 6232e5e7f0..3a99767ae4 100644 --- a/direct/src/fsm/StateData.py +++ b/direct/src/fsm/StateData.py @@ -14,63 +14,63 @@ class StateData(DirectObject): def __init__(self, doneEvent): """__init__(self, Event) """ - self.doneEvent = doneEvent - self.doneStatus = None - self.isLoaded = 0 - self.isEntered = 0 - return None + self.doneEvent = doneEvent + self.doneStatus = None + self.isLoaded = 0 + self.isEntered = 0 + return None def cleanup(self): - """cleanup(self) - """ - self.unload() - return None + """cleanup(self) + """ + self.unload() + return None def enter(self): """enter(self) - """ - # Use isEntered to avoid redundant entry work - if self.isEntered == 1: - return None - self.isEntered = 1 - # Use isLoaded to avoid redundant loading - if self.isLoaded == 0: - self.load() - self.notify.debug('enter()') - return None + """ + # Use isEntered to avoid redundant entry work + if self.isEntered == 1: + return None + self.isEntered = 1 + # Use isLoaded to avoid redundant loading + if self.isLoaded == 0: + self.load() + self.notify.debug('enter()') + return None def exit(self): - """exit(self) - """ - if self.isEntered == 0: - return None - self.isEntered = 0 - self.notify.debug('exit()') - return None + """exit(self) + """ + if self.isEntered == 0: + return None + self.isEntered = 0 + self.notify.debug('exit()') + return None def load(self): - """load(self) - """ - if self.isLoaded == 1: - return None - self.isLoaded = 1 - self.notify.debug('load()') - return None - + """load(self) + """ + if self.isLoaded == 1: + return None + self.isLoaded = 1 + self.notify.debug('load()') + return None + def unload(self): - """unload(self) - """ - if self.isLoaded == 0: - return None - self.isLoaded = 0 - self.exit() - self.notify.debug('unload()') - return None + """unload(self) + """ + if self.isLoaded == 0: + return None + self.isLoaded = 0 + self.exit() + self.notify.debug('unload()') + return None def getDoneStatus(self): - """getDoneStatus(self) - """ - return self.doneStatus + """getDoneStatus(self) + """ + return self.doneStatus diff --git a/direct/src/gui/Background.py b/direct/src/gui/Background.py index d1dda4c045..3da79ac80c 100644 --- a/direct/src/gui/Background.py +++ b/direct/src/gui/Background.py @@ -12,15 +12,15 @@ class Background(DirectObject): self.background = GuiBackground.GuiBackground(name, self.item, self.label) self.managed = 0 - return None + return None def cleanup(self): - """cleanup(self) - """ + """cleanup(self) + """ if (self.managed): self.unmanage() self.background = None - return None + return None def __str__(self): return "Background: %s behind %s" % (self.name, self.item ) diff --git a/direct/src/gui/Collection.py b/direct/src/gui/Collection.py index 12d7fbe1b8..b1382f9b93 100644 --- a/direct/src/gui/Collection.py +++ b/direct/src/gui/Collection.py @@ -11,15 +11,15 @@ class Collection(DirectObject): self.collection = GuiCollection.GuiCollection(self.name) self.items= [] self.managed = 0 - return None + return None def cleanup(self): - """cleanup(self) - """ + """cleanup(self) + """ if (self.managed): self.unmanage() self.collection = None - return None + return None def __str__(self): return "Collection: %s = %s" % (self.name, self.items) diff --git a/direct/src/gui/DialogBox.py b/direct/src/gui/DialogBox.py index bdcb013e87..34dfc997ce 100644 --- a/direct/src/gui/DialogBox.py +++ b/direct/src/gui/DialogBox.py @@ -25,7 +25,7 @@ class DialogBox(OnscreenPanel.OnscreenPanel): def __init__(self, message = "", doneEvent = None, style = NoButtons, font = getDefaultFont(), wordwrap = 12, okButtonText = "OK", cancelButtonText = "Cancel"): - """___init___(self, Event, string="", int, model, int=12)""" + """___init___(self, Event, string="", int, model, int=12)""" # Sanity check if (doneEvent == None) and (style != NoButtons): @@ -48,8 +48,8 @@ class DialogBox(OnscreenPanel.OnscreenPanel): drawOrder = 32000, font = self.font, bg = (0.8, 0.8, 0.8, 1.0)) - # create a message - self.makeText(self.message, wordwrap = self.wordwrap, scale = 0.08, + # create a message + self.makeText(self.message, wordwrap = self.wordwrap, scale = 0.08, pos = (0.0, 0.25)) if (self.style == TwoChoice): @@ -75,39 +75,39 @@ class DialogBox(OnscreenPanel.OnscreenPanel): "Sanity check" self.notify.error("No such style as: " + str(self.style)) - return None + return None def show(self): - """show(self) - """ + """show(self) + """ base.transitions.fadeScreen() OnscreenPanel.OnscreenPanel.show(self) - return None + return None def hide(self): - """hide(self) - """ + """hide(self) + """ base.transitions.noTransitions() OnscreenPanel.OnscreenPanel.hide(self) - return None - + return None + def cleanup(self): - """unload(self) - """ - self.hide() + """unload(self) + """ + self.hide() OnscreenPanel.OnscreenPanel.cleanup(self) - return None + return None # def handleRollover(self): - # return None + # return None def handleOk(self, okButton, item): assert(self.style != NoButtons) if (okButton == item): - self.doneStatus = "ok" + self.doneStatus = "ok" messenger.send(self.__doneEvent) def handleCancel(self, cancelButton, item): diff --git a/direct/src/gui/DirectGuiBase.py b/direct/src/gui/DirectGuiBase.py index 65ece30e73..4e8ca29034 100644 --- a/direct/src/gui/DirectGuiBase.py +++ b/direct/src/gui/DirectGuiBase.py @@ -97,48 +97,48 @@ class DirectGuiBase(PandaObject.PandaObject): self._hookDict = {} # To avoid doing things redundantly during initialisation self.fInit = 1 - # Mapping from each megawidget option to a list of information - # about the option - # - default value - # - current value - # - function to call when the option is initialised in the - # call to initialiseoptions() in the constructor or - # modified via configure(). If this is INITOPT, the - # option is an initialisation option (an option that can - # be set by the call to the constructor but can not be - # used with configure). - # This mapping is not initialised here, but in the call to - # defineoptions() which precedes construction of this base class. - # - # self._optionInfo = {} + # Mapping from each megawidget option to a list of information + # about the option + # - default value + # - current value + # - function to call when the option is initialised in the + # call to initialiseoptions() in the constructor or + # modified via configure(). If this is INITOPT, the + # option is an initialisation option (an option that can + # be set by the call to the constructor but can not be + # used with configure). + # This mapping is not initialised here, but in the call to + # defineoptions() which precedes construction of this base class. + # + # self._optionInfo = {} - # Mapping from each component name to a tuple of information - # about the component. - # - component widget instance - # - configure function of widget instance - # - the class of the widget (Frame, EntryField, etc) - # - cget function of widget instance - # - the name of the component group of this component, if any - self.__componentInfo = {} + # Mapping from each component name to a tuple of information + # about the component. + # - component widget instance + # - configure function of widget instance + # - the class of the widget (Frame, EntryField, etc) + # - cget function of widget instance + # - the name of the component group of this component, if any + self.__componentInfo = {} - # Mapping from alias names to the names of components or - # sub-components. - self.__componentAliases = {} + # Mapping from alias names to the names of components or + # sub-components. + self.__componentAliases = {} - # Contains information about the keywords provided to the - # constructor. It is a mapping from the keyword to a tuple - # containing: - # - value of keyword - # - a boolean indicating if the keyword has been used. - # A keyword is used if, during the construction of a megawidget, - # - it is defined in a call to defineoptions() or addoptions(), or - # - it references, by name, a component of the megawidget, or - # - it references, by group, at least one component - # At the end of megawidget construction, a call is made to - # initialiseoptions() which reports an error if there are - # unused options given to the constructor. - # - # self._constructorKeywords = {} + # Contains information about the keywords provided to the + # constructor. It is a mapping from the keyword to a tuple + # containing: + # - value of keyword + # - a boolean indicating if the keyword has been used. + # A keyword is used if, during the construction of a megawidget, + # - it is defined in a call to defineoptions() or addoptions(), or + # - it references, by name, a component of the megawidget, or + # - it references, by group, at least one component + # At the end of megawidget construction, a call is made to + # initialiseoptions() which reports an error if there are + # unused options given to the constructor. + # + # self._constructorKeywords = {} # List of dynamic component groups. If a group is included in # this list, then it not an error if a keyword argument for @@ -153,10 +153,10 @@ class DirectGuiBase(PandaObject.PandaObject): def defineoptions(self, keywords, optionDefs, dynamicGroups = ()): """ defineoptions(keywords, optionDefs, dynamicGroups = {}) """ - # Create options, providing the default value and the method - # to call when the value is changed. If any option created by - # base classes has the same name as one in , the - # base class's value and function will be overriden. + # Create options, providing the default value and the method + # to call when the value is changed. If any option created by + # base classes has the same name as one in , the + # base class's value and function will be overriden. # keywords is a dictionary of keyword/value pairs from the constructor # optionDefs is a dictionary of default options for the widget @@ -164,15 +164,15 @@ class DirectGuiBase(PandaObject.PandaObject): # specify options even though no components of this group have # been created - # This should be called before the constructor of the base - # class, so that default values defined in the derived class - # override those in the base class. - if not hasattr(self, '_constructorKeywords'): - tmp = {} - for option, value in keywords.items(): - tmp[option] = [value, 0] + # This should be called before the constructor of the base + # class, so that default values defined in the derived class + # override those in the base class. + if not hasattr(self, '_constructorKeywords'): + tmp = {} + for option, value in keywords.items(): + tmp[option] = [value, 0] self._constructorKeywords = tmp - self._optionInfo = {} + self._optionInfo = {} # Initialize dictionary of dynamic groups if not hasattr(self, '_dynamicGroups'): self._dynamicGroups = () @@ -182,19 +182,19 @@ class DirectGuiBase(PandaObject.PandaObject): def addoptions(self, optionDefs): """ addoptions(optionDefs) - add option def to option info """ - # Add additional options, providing the default value and the - # method to call when the value is changed. See - # "defineoptions" for more details + # Add additional options, providing the default value and the + # method to call when the value is changed. See + # "defineoptions" for more details - # optimisations: - optionInfo = self._optionInfo - optionInfo_has_key = optionInfo.has_key - keywords = self._constructorKeywords - keywords_has_key = keywords.has_key - FUNCTION = _OPT_FUNCTION + # optimisations: + optionInfo = self._optionInfo + optionInfo_has_key = optionInfo.has_key + keywords = self._constructorKeywords + keywords_has_key = keywords.has_key + FUNCTION = _OPT_FUNCTION - for name, default, function in optionDefs: - if '_' not in name: + for name, default, function in optionDefs: + if '_' not in name: # The option will already exist if it has been defined # in a derived class. In this case, do not override the # default value of the option or the callback function @@ -212,13 +212,13 @@ class DirectGuiBase(PandaObject.PandaObject): elif optionInfo[name][FUNCTION] is None: # Only override function if not defined by derived class optionInfo[name][FUNCTION] = function - else: - # This option is of the form "component_option". If this is - # not already defined in self._constructorKeywords add it. - # This allows a derived class to override the default value - # of an option of a component of a base class. - if not keywords_has_key(name): - keywords[name] = [default, 0] + else: + # This option is of the form "component_option". If this is + # not already defined in self._constructorKeywords add it. + # This allows a derived class to override the default value + # of an option of a component of a base class. + if not keywords_has_key(name): + keywords[name] = [default, 0] def initialiseoptions(self, myClass): """ @@ -227,36 +227,36 @@ class DirectGuiBase(PandaObject.PandaObject): """ # This is to make sure this method class is only called by # the most specific class in the class hierarchy - if self.__class__ is myClass: - # Call the configuration callback function for every option. - FUNCTION = _OPT_FUNCTION + if self.__class__ is myClass: + # Call the configuration callback function for every option. + FUNCTION = _OPT_FUNCTION self.fInit = 1 - for info in self._optionInfo.values(): - func = info[FUNCTION] - if func is not None and func is not INITOPT: - func() + for info in self._optionInfo.values(): + func = info[FUNCTION] + if func is not None and func is not INITOPT: + func() self.fInit = 0 # Now check if anything is left over - unusedOptions = [] - keywords = self._constructorKeywords - for name in keywords.keys(): - used = keywords[name][1] - if not used: + unusedOptions = [] + keywords = self._constructorKeywords + for name in keywords.keys(): + used = keywords[name][1] + if not used: # This keyword argument has not been used. If it # does not refer to a dynamic group, mark it as # unused. index = string.find(name, '_') if index < 0 or name[:index] not in self._dynamicGroups: unusedOptions.append(name) - self._constructorKeywords = {} - if len(unusedOptions) > 0: - if len(unusedOptions) == 1: - text = 'Unknown option "' - else: - text = 'Unknown options "' - raise KeyError, text + string.join(unusedOptions, ', ') + \ - '" for ' + myClass.__name__ + self._constructorKeywords = {} + if len(unusedOptions) > 0: + if len(unusedOptions) == 1: + text = 'Unknown option "' + else: + text = 'Unknown options "' + raise KeyError, text + string.join(unusedOptions, ', ') + \ + '" for ' + myClass.__name__ # Can now call post init func self.postInitialiseFunc() @@ -268,7 +268,7 @@ class DirectGuiBase(PandaObject.PandaObject): isinitoption(option) Is this opition one that can only be specified at construction? """ - return self._optionInfo[option][_OPT_FUNCTION] is INITOPT + return self._optionInfo[option][_OPT_FUNCTION] is INITOPT def options(self): """ @@ -276,155 +276,155 @@ class DirectGuiBase(PandaObject.PandaObject): Print out a list of available widget options. Does not include subcomponent options. """ - options = [] - if hasattr(self, '_optionInfo'): - for option, info in self._optionInfo.items(): - isinit = info[_OPT_FUNCTION] is INITOPT - default = info[_OPT_DEFAULT] - options.append((option, default, isinit)) - options.sort() - return options + options = [] + if hasattr(self, '_optionInfo'): + for option, info in self._optionInfo.items(): + isinit = info[_OPT_FUNCTION] is INITOPT + default = info[_OPT_DEFAULT] + options.append((option, default, isinit)) + options.sort() + return options def configure(self, option=None, **kw): """ configure(option = None) - Query or configure the megawidget options. + Query or configure the megawidget options. """ - # - # If not empty, *kw* is a dictionary giving new - # values for some of the options of this gui item - # For options defined for this widget, set - # the value of the option to the new value and call the - # configuration callback function, if any. - # - # If *option* is None, return all gui item configuration - # options and settings. Options are returned as standard 3 - # element tuples - # - # If *option* is a string, return the 3 element tuple for the - # given configuration option. + # + # If not empty, *kw* is a dictionary giving new + # values for some of the options of this gui item + # For options defined for this widget, set + # the value of the option to the new value and call the + # configuration callback function, if any. + # + # If *option* is None, return all gui item configuration + # options and settings. Options are returned as standard 3 + # element tuples + # + # If *option* is a string, return the 3 element tuple for the + # given configuration option. - # First, deal with the option queries. - if len(kw) == 0: - # This configure call is querying the values of one or all options. - # Return 3-tuples: - # (optionName, default, value) - if option is None: - rtn = {} - for option, config in self._optionInfo.items(): - rtn[option] = (option, + # First, deal with the option queries. + if len(kw) == 0: + # This configure call is querying the values of one or all options. + # Return 3-tuples: + # (optionName, default, value) + if option is None: + rtn = {} + for option, config in self._optionInfo.items(): + rtn[option] = (option, config[_OPT_DEFAULT], config[_OPT_VALUE]) - return rtn - else: - config = self._optionInfo[option] - return (option, config[_OPT_DEFAULT], config[_OPT_VALUE]) + return rtn + else: + config = self._optionInfo[option] + return (option, config[_OPT_DEFAULT], config[_OPT_VALUE]) - # optimizations: - optionInfo = self._optionInfo - optionInfo_has_key = optionInfo.has_key - componentInfo = self.__componentInfo - componentInfo_has_key = componentInfo.has_key - componentAliases = self.__componentAliases - componentAliases_has_key = componentAliases.has_key - VALUE = _OPT_VALUE - FUNCTION = _OPT_FUNCTION + # optimizations: + optionInfo = self._optionInfo + optionInfo_has_key = optionInfo.has_key + componentInfo = self.__componentInfo + componentInfo_has_key = componentInfo.has_key + componentAliases = self.__componentAliases + componentAliases_has_key = componentAliases.has_key + VALUE = _OPT_VALUE + FUNCTION = _OPT_FUNCTION - # This will contain a list of options in *kw* which - # are known to this gui item. - directOptions = [] + # This will contain a list of options in *kw* which + # are known to this gui item. + directOptions = [] - # This will contain information about the options in - # *kw* of the form _