diff --git a/direct/src/actor/Actor.py b/direct/src/actor/Actor.py index 74cb07937f..29db4290bd 100644 --- a/direct/src/actor/Actor.py +++ b/direct/src/actor/Actor.py @@ -6,7 +6,7 @@ from panda3d.core import * from panda3d.core import Loader as PandaLoader from direct.showbase.DirectObject import DirectObject from direct.directnotify import DirectNotifyGlobal -import types + class Actor(DirectObject, NodePath): """ @@ -239,30 +239,30 @@ class Actor(DirectObject, NodePath): # models{}{}, anims{}{} = multi-part actor w/ LOD # # make sure we have models - if (models): + if models: # do we have a dictionary of models? - if (type(models)==type({})): + if type(models) == dict: # if this is a dictionary of dictionaries - if (type(models[models.keys()[0]]) == type({})): + if type(models[next(iter(models))]) == dict: # then it must be a multipart actor w/LOD self.setLODNode(node = lodNode) # preserve numerical order for lod's # this will make it easier to set ranges - sortedKeys = models.keys() + sortedKeys = list(models.keys()) sortedKeys.sort() for lodName in sortedKeys: # make a node under the LOD switch # for each lod (just because!) self.addLOD(str(lodName)) # iterate over both dicts - for modelName in models[lodName].keys(): + for modelName in models[lodName]: self.loadModel(models[lodName][modelName], modelName, lodName, copy = copy, okMissing = okMissing) # then if there is a dictionary of dictionaries of anims - elif (type(anims[anims.keys()[0]])==type({})): + elif type(anims[next(iter(anims))]) == dict: # then this is a multipart actor w/o LOD - for partName in models.keys(): + for partName in models: # pass in each part self.loadModel(models[partName], partName, copy = copy, okMissing = okMissing) @@ -270,7 +270,7 @@ class Actor(DirectObject, NodePath): # it is a single part actor w/LOD self.setLODNode(node = lodNode) # preserve order of LOD's - sortedKeys = models.keys() + sortedKeys = list(models.keys()) sortedKeys.sort() for lodName in sortedKeys: self.addLOD(str(lodName)) @@ -283,28 +283,28 @@ class Actor(DirectObject, NodePath): # load anims # make sure the actor has animations - if (anims): - if (len(anims) >= 1): + if anims: + if len(anims) >= 1: # if so, does it have a dictionary of dictionaries? - if (type(anims[anims.keys()[0]])==type({})): + if type(anims[next(iter(anims))]) == dict: # are the models a dict of dicts too? - if (type(models)==type({})): - if (type(models[models.keys()[0]]) == type({})): + if type(models) == dict: + if type(models[next(iter(models))]) == dict: # then we have a multi-part w/ LOD - sortedKeys = models.keys() + sortedKeys = list(models.keys()) sortedKeys.sort() for lodName in sortedKeys: # iterate over both dicts - for partName in anims.keys(): + for partName in anims: self.loadAnims( anims[partName], partName, lodName) else: # then it must be multi-part w/o LOD - for partName in anims.keys(): + for partName in anims: self.loadAnims(anims[partName], partName) - elif (type(models)==type({})): + elif type(models) == dict: # then we have single-part w/ LOD - sortedKeys = models.keys() + sortedKeys = list(models.keys()) sortedKeys.sort() for lodName in sortedKeys: self.loadAnims(anims, lodName=lodName) @@ -431,11 +431,10 @@ class Actor(DirectObject, NodePath): part.outputValue(lineStream) value = lineStream.getLine() - print ' ' * indentLevel, part.getName(), value + print(' '.join((' ' * indentLevel, part.getName(), value))) - for i in range(part.getNumChildren()): - self.__doListJoints(indentLevel + 2, part.getChild(i), - isIncluded, subset) + for child in part.getChildren(): + self.__doListJoints(indentLevel + 2, child, isIncluded, subset) def getActorInfo(self): @@ -449,14 +448,14 @@ class Actor(DirectObject, NodePath): lodName = self.__sortedLODNames[0] partInfo = [] - for partName in partDict.keys(): + for partName in partDict: subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName)) partBundleDict = self.__partBundleDict.get(lodName) partDef = partBundleDict.get(subpartDef.truePartName) partBundle = partDef.getBundle() animDict = partDict[partName] animInfo = [] - for animName in animDict.keys(): + for animName in animDict: file = animDict[animName].filename animControl = animDict[animName].animControl animInfo.append([animName, file, animControl]) @@ -478,17 +477,17 @@ class Actor(DirectObject, NodePath): Pretty print actor's details """ for lodName, lodInfo in self.getActorInfo(): - print 'LOD:', lodName + print('LOD: %s' % lodName) for partName, bundle, animInfo in lodInfo: - print ' Part:', partName - print ' Bundle:', repr(bundle) + print(' Part: %s' % partName) + print(' Bundle: %r' % bundle) for animName, file, animControl in animInfo: - print ' Anim:', animName - print ' File:', file + print(' Anim: %s' % animName) + print(' File: %s' % file) if animControl == None: - print ' (not loaded)' + print(' (not loaded)') else: - print (' NumFrames: %d PlayRate: %0.2f' % + print(' NumFrames: %d PlayRate: %0.2f' % (animControl.getNumFrames(), animControl.getPlayRate())) @@ -568,7 +567,7 @@ class Actor(DirectObject, NodePath): def __updateSortedLODNames(self): # Cache the sorted LOD names so we don't have to grab them # and sort them every time somebody asks for the list - self.__sortedLODNames = self.__partBundleDict.keys() + self.__sortedLODNames = list(self.__partBundleDict.keys()) # Reverse sort the doing a string->int def sortKey(x): if not str(x).isdigit(): @@ -604,8 +603,8 @@ class Actor(DirectObject, NodePath): """ partNames = [] if self.__partBundleDict: - partNames = self.__partBundleDict.values()[0].keys() - return partNames + self.__subpartDict.keys() + partNames = list(next(iter(self.__partBundleDict.values())).keys()) + return partNames + list(self.__subpartDict.keys()) def getGeomNode(self): """ @@ -646,33 +645,33 @@ class Actor(DirectObject, NodePath): """ # make sure we don't call this twice in a row # and pollute the the switches dictionary -## sortedKeys = self.switches.keys() +## sortedKeys = list(self.switches.keys()) ## sortedKeys.sort() child = self.__LODNode.find(str(lodName)) index = self.__LODNode.node().findChild(child.node()) self.__LODNode.node().forceSwitch(index) def printLOD(self): -## sortedKeys = self.switches.keys() +## sortedKeys = list(self.switches.keys()) ## sortedKeys.sort() sortedKeys = self.__sortedLODNames for eachLod in sortedKeys: - print "python switches for %s: in: %d, out %d" % (eachLod, + print("python switches for %s: in: %d, out %d" % (eachLod, self.switches[eachLod][0], - self.switches[eachLod][1]) + self.switches[eachLod][1])) switchNum = self.__LODNode.node().getNumSwitches() for eachSwitch in range(0, switchNum): - print "c++ switches for %d: in: %d, out: %d" % (eachSwitch, + print("c++ switches for %d: in: %d, out: %d" % (eachSwitch, self.__LODNode.node().getIn(eachSwitch), - self.__LODNode.node().getOut(eachSwitch)) + self.__LODNode.node().getOut(eachSwitch))) def resetLOD(self): """ Restore all switch distance info (usually after a useLOD call)""" self.__LODNode.node().clearForceSwitch() -## sortedKeys = self.switches.keys() +## sortedKeys = list(self.switches.keys()) ## sortedKeys.sort() ## for eachLod in sortedKeys: ## index = sortedKeys.index(eachLod) @@ -699,7 +698,7 @@ class Actor(DirectObject, NodePath): # save the switch distance info self.switches[lodName] = [inDist, outDist] # add the switch distance info -## sortedKeys = self.switches.keys() +## sortedKeys = list(self.switches.keys()) ## sortedKeys.sort() self.__LODNode.node().setSwitch(self.getLODIndex(lodName), inDist, outDist) @@ -798,7 +797,7 @@ class Actor(DirectObject, NodePath): lodName = lodNames[lod] if partName == None: partBundleDict = self.__partBundleDict[lodName] - partNames = partBundleDict.keys() + partNames = list(partBundleDict.keys()) else: partNames = [partName] @@ -822,7 +821,7 @@ class Actor(DirectObject, NodePath): If no part specified, return anim durations of first part. NOTE: returns info only for an arbitrary LOD """ - lodName = self.__animControlDict.keys()[0] + lodName = next(iter(self.__animControlDict)) controls = self.getAnimControls(animName, partName) if len(controls) == 0: return None @@ -834,7 +833,7 @@ class Actor(DirectObject, NodePath): Return frame rate of given anim name and given part, unmodified by any play rate in effect. """ - lodName = self.__animControlDict.keys()[0] + lodName = next(iter(self.__animControlDict)) controls = self.getAnimControls(animName, partName) if len(controls) == 0: return None @@ -850,7 +849,7 @@ class Actor(DirectObject, NodePath): """ if self.__animControlDict: # use the first lod - lodName = self.__animControlDict.keys()[0] + lodName = next(iter(self.__animControlDict)) controls = self.getAnimControls(animName, partName) if controls: return controls[0].getPlayRate() @@ -877,7 +876,7 @@ class Actor(DirectObject, NodePath): If no part specified, return anim duration of first part. NOTE: returns info for arbitrary LOD """ - lodName = self.__animControlDict.keys()[0] + lodName = next(iter(self.__animControlDict)) controls = self.getAnimControls(animName, partName) if len(controls) == 0: return None @@ -890,7 +889,7 @@ class Actor(DirectObject, NodePath): return ((toFrame+1)-fromFrame) / animControl.getFrameRate() def getNumFrames(self, animName=None, partName=None): - lodName = self.__animControlDict.keys()[0] + lodName = next(iter(self.__animControlDict)) controls = self.getAnimControls(animName, partName) if len(controls) == 0: return None @@ -908,12 +907,12 @@ class Actor(DirectObject, NodePath): specified return current anim of an arbitrary part in dictionary. NOTE: only returns info for an arbitrary LOD """ - if len(self.__animControlDict.items()) == 0: + if len(self.__animControlDict) == 0: return - lodName, animControlDict = self.__animControlDict.items()[0] + lodName, animControlDict = next(iter(self.__animControlDict.items())) if partName == None: - partName, animDict = animControlDict.items()[0] + partName, animDict = next(iter(animControlDict.items())) else: animDict = animControlDict.get(partName) if animDict == None: @@ -936,9 +935,9 @@ class Actor(DirectObject, NodePath): actor. If part not specified return current anim of first part in dictionary. NOTE: only returns info for an arbitrary LOD """ - lodName, animControlDict = self.__animControlDict.items()[0] + lodName, animControlDict = next(iter(self.__animControlDict.items())) if partName == None: - partName, animDict = animControlDict.items()[0] + partName, animDict = next(iter(animControlDict.items())) else: animDict = animControlDict.get(partName) if animDict == None: @@ -1420,17 +1419,15 @@ class Actor(DirectObject, NodePath): if mode > 0: # Use the 'fixed' bin instead of reordering the scene # graph. - numFrontParts = frontParts.getNumPaths() - for partNum in range(0, numFrontParts): - frontParts[partNum].setBin('fixed', mode) + for part in frontParts: + part.setBin('fixed', mode) return if mode == -2: # Turn off depth test/write on the frontParts. - numFrontParts = frontParts.getNumPaths() - for partNum in range(0, numFrontParts): - frontParts[partNum].setDepthWrite(0) - frontParts[partNum].setDepthTest(0) + for part in frontParts: + part.setDepthWrite(0) + part.setDepthTest(0) # Find the back part. backPart = root.find("**/" + backPartName) @@ -1457,12 +1454,8 @@ class Actor(DirectObject, NodePath): char = partData.partBundleNP char.node().update() geomNodes = char.findAllMatches("**/+GeomNode") - numGeomNodes = geomNodes.getNumPaths() - for nodeNum in xrange(numGeomNodes): - thisGeomNode = geomNodes.getPath(nodeNum) - numGeoms = thisGeomNode.node().getNumGeoms() - for geomNum in xrange(numGeoms): - thisGeom = thisGeomNode.node().getGeom(geomNum) + for thisGeomNode in geomNodes: + for thisGeom in thisGeomNode.node().getGeoms(): thisGeom.markBoundsStale() thisGeomNode.node().markInternalBoundsStale() else: @@ -1473,12 +1466,8 @@ class Actor(DirectObject, NodePath): char = partData.partBundleNP char.node().update() geomNodes = char.findAllMatches("**/+GeomNode") - numGeomNodes = geomNodes.getNumPaths() - for nodeNum in xrange(numGeomNodes): - thisGeomNode = geomNodes.getPath(nodeNum) - numGeoms = thisGeomNode.node().getNumGeoms() - for geomNum in xrange(numGeoms): - thisGeom = thisGeomNode.node().getGeom(geomNum) + for thisGeomNode in geomNodes: + for thisGeom in thisGeomNode.node().getGeoms(): thisGeom.markBoundsStale() thisGeomNode.node().markInternalBoundsStale() @@ -1494,19 +1483,14 @@ class Actor(DirectObject, NodePath): # update all characters first charNodes = part.findAllMatches("**/+Character") - numCharNodes = charNodes.getNumPaths() - for charNum in range(0, numCharNodes): - (charNodes.getPath(charNum)).node().update() + for charNode in charNodes: + charNode.node().update() # for each geomNode, iterate through all geoms and force update # of bounding spheres by marking current bounds as stale geomNodes = part.findAllMatches("**/+GeomNode") - numGeomNodes = geomNodes.getNumPaths() - for nodeNum in range(0, numGeomNodes): - thisGeomNode = geomNodes.getPath(nodeNum) - numGeoms = thisGeomNode.node().getNumGeoms() - for geomNum in range(0, numGeoms): - thisGeom = thisGeomNode.node().getGeom(geomNum) + for nodeNum, thisGeomNode in enumerate(geomNodes): + for geomNum, thisGeom in enumerate(thisGeomNode.node().getGeoms()): thisGeom.markBoundsStale() assert Actor.notify.debug("fixing bounds for node %s, geom %s" % \ (nodeNum, geomNum)) @@ -1517,20 +1501,18 @@ class Actor(DirectObject, NodePath): Show the bounds of all actor geoms """ geomNodes = self.__geomNode.findAllMatches("**/+GeomNode") - numGeomNodes = geomNodes.getNumPaths() - for nodeNum in range(0, numGeomNodes): - geomNodes.getPath(nodeNum).showBounds() + for node in geomNodes: + node.showBounds() def hideAllBounds(self): """ Hide the bounds of all actor geoms """ geomNodes = self.__geomNode.findAllMatches("**/+GeomNode") - numGeomNodes = geomNodes.getNumPaths() - for nodeNum in range(0, numGeomNodes): - geomNodes.getPath(nodeNum).hideBounds() + for node in geomNodes: + node.hideBounds() # actions @@ -1698,7 +1680,7 @@ class Actor(DirectObject, NodePath): if self.mergeLODBundles: lodName = 'common' elif self.switches: - lodName = str(self.switches.keys()[0]) + lodName = str(next(iter(self.switches))) else: lodName = 'lodRoot' @@ -1723,7 +1705,7 @@ class Actor(DirectObject, NodePath): lodName = 'common' elif not lodName: if self.switches: - lodName = str(self.switches.keys()[0]) + lodName = str(next(iter(self.switches))) else: lodName = 'lodRoot' @@ -1777,7 +1759,7 @@ class Actor(DirectObject, NodePath): # If we have the __subpartsComplete flag, and no partName # is specified, it really means to play the animation on # all subparts, not on the overall Actor. - partName = self.__subpartDict.keys() + partName = list(self.__subpartDict.keys()) controls = [] # build list of lodNames and corresponding animControlDicts @@ -1805,7 +1787,7 @@ class Actor(DirectObject, NodePath): else: # Get exactly the named part or parts. - if isinstance(partName, types.StringTypes): + if isinstance(partName, str): partNameList = [partName] else: partNameList = partName @@ -1835,7 +1817,7 @@ class Actor(DirectObject, NodePath): controls.append(anim.animControl) else: # get the named animation(s) only. - if isinstance(animName, types.StringTypes): + if isinstance(animName, str): # A single animName animNameList = [animName] else: @@ -2107,7 +2089,7 @@ class Actor(DirectObject, NodePath): if lodName: partNames = self.__partBundleDict[lodName].keys() else: - partNames = self.__partBundleDict.values()[0].keys() + partNames = next(iter(self.__partBundleDict.values())).keys() for partName in partNames: subJoints = set() @@ -2133,9 +2115,9 @@ class Actor(DirectObject, NodePath): lodNames = ['common'] elif lodName == 'all': reload = False - lodNames = self.switches.keys() + lodNames = list(self.switches.keys()) lodNames.sort() - for i in range(0,len(lodNames)): + for i in range(0, len(lodNames)): lodNames[i] = str(lodNames[i]) else: lodNames = [lodName] @@ -2256,20 +2238,20 @@ class Actor(DirectObject, NodePath): assert Actor.notify.debug("in unloadAnims: %s, part: %s, lod: %s" % (anims, partName, lodName)) - if lodName == None or self.mergeLODBundles: + if lodName is None or self.mergeLODBundles: lodNames = self.__animControlDict.keys() else: lodNames = [lodName] - if (partName == None): + if partName is None: if len(lodNames) > 0: - partNames = self.__animControlDict[lodNames[0]].keys() + partNames = self.__animControlDict[next(iter(lodNames))].keys() else: partNames = [] else: partNames = [partName] - if (anims==None): + if anims is None: for lodName in lodNames: for partName in partNames: for animDef in self.__animControlDict[lodName][partName].values(): @@ -2400,7 +2382,7 @@ class Actor(DirectObject, NodePath): Copy the part bundle dictionary from another actor as this instance's own. NOTE: this method does not actually copy geometry """ - for lodName in other.__partBundleDict.keys(): + for lodName in other.__partBundleDict: # find the lod Asad if lodName == 'lodRoot': partLod = self @@ -2445,11 +2427,11 @@ class Actor(DirectObject, NodePath): assert(other.mergeLODBundles == self.mergeLODBundles) - for lodName in other.__animControlDict.keys(): + for lodName in other.__animControlDict: self.__animControlDict[lodName] = {} - for partName in other.__animControlDict[lodName].keys(): + for partName in other.__animControlDict[lodName]: self.__animControlDict[lodName][partName] = {} - for animName in other.__animControlDict[lodName][partName].keys(): + for animName in other.__animControlDict[lodName][partName]: anim = other.__animControlDict[lodName][partName][animName] anim = anim.makeCopy() self.__animControlDict[lodName][partName][animName] = anim @@ -2512,13 +2494,13 @@ class Actor(DirectObject, NodePath): def printAnimBlends(self, animName=None, partName=None, lodName=None): for lodName, animList in self.getAnimBlends(animName, partName, lodName): - print 'LOD %s:' % (lodName) + print('LOD %s:' % (lodName)) for animName, blendList in animList: list = [] for partName, effect in blendList: list.append('%s:%.3f' % (partName, effect)) - print ' %s: %s' % (animName, ', '.join(list)) + print(' %s: %s' % (animName, ', '.join(list))) def osdAnimBlends(self, animName=None, partName=None, lodName=None): if not onScreenDebug.enabled: @@ -2565,5 +2547,5 @@ class Actor(DirectObject, NodePath): def renamePartBundles(self, partName, newBundleName): subpartDef = self.__subpartDict.get(partName, Actor.SubpartDef(partName)) for partBundleDict in self.__partBundleDict.values(): - partDef=partBundleDict.get(subpartDef.truePartName) + partDef = partBundleDict.get(subpartDef.truePartName) partDef.getBundle().setName(newBundleName) diff --git a/direct/src/actor/DistributedActor.py b/direct/src/actor/DistributedActor.py index 2e991d2043..c46a8863c4 100644 --- a/direct/src/actor/DistributedActor.py +++ b/direct/src/actor/DistributedActor.py @@ -4,7 +4,7 @@ __all__ = ['DistributedActor'] from direct.distributed import DistributedNode -import Actor +from . import Actor class DistributedActor(DistributedNode.DistributedNode, Actor.Actor): def __init__(self, cr): diff --git a/direct/src/cluster/ClusterClient.py b/direct/src/cluster/ClusterClient.py index f238aca91d..873b03d4ea 100644 --- a/direct/src/cluster/ClusterClient.py +++ b/direct/src/cluster/ClusterClient.py @@ -1,8 +1,8 @@ """ClusterClient: Master for mutli-piping or PC clusters. """ from panda3d.core import * -from ClusterMsgs import * -from ClusterConfig import * +from .ClusterMsgs import * +from .ClusterConfig import * from direct.directnotify import DirectNotifyGlobal from direct.showbase import DirectObject from direct.task import Task @@ -44,10 +44,10 @@ class ClusterClient(DirectObject.DirectObject): self.daemon.tellServer(serverConfig.serverName, serverConfig.serverDaemonPort, serverCommand) - print 'Begin waitForServers' + print('Begin waitForServers') if not self.daemon.waitForServers(len(configList)): - print 'Cluster Client, no response from servers' - print 'End waitForServers' + print('Cluster Client, no response from servers') + print('End waitForServers') self.qcm=QueuedConnectionManager() self.serverList = [] self.serverQueues = [] @@ -262,9 +262,8 @@ class ClusterClient(DirectObject.DirectObject): def getNodePathFindCmd(self, nodePath): - import string pathString = repr(nodePath) - index = string.find(pathString, '/') + index = pathString.find('/') if index != -1: rootName = pathString[:index] searchString = pathString[index+1:] @@ -273,9 +272,8 @@ class ClusterClient(DirectObject.DirectObject): return rootName def getNodePathName(self, nodePath): - import string pathString = repr(nodePath) - index = string.find(pathString, '/') + index = pathString.find('/') if index != -1: name = pathString[index+1:] return name @@ -409,7 +407,7 @@ class ClusterClientSync(ClusterClient): #I probably don't need this self.waitForSwap = 0 self.ready = 0 - print "creating synced client" + print("creating synced client") self.startSwapCoordinatorTask() def startSwapCoordinatorTask(self): diff --git a/direct/src/cluster/ClusterConfig.py b/direct/src/cluster/ClusterConfig.py index 6cf71dcaab..73e4ebf2b6 100644 --- a/direct/src/cluster/ClusterConfig.py +++ b/direct/src/cluster/ClusterConfig.py @@ -1,5 +1,5 @@ -from ClusterClient import * +from .ClusterClient import * # A dictionary of information for various cluster configurations. # Dictionary is keyed on cluster-config string diff --git a/direct/src/cluster/ClusterServer.py b/direct/src/cluster/ClusterServer.py index 4ec78b0841..511dc84cef 100644 --- a/direct/src/cluster/ClusterServer.py +++ b/direct/src/cluster/ClusterServer.py @@ -1,5 +1,5 @@ from panda3d.core import * -from ClusterMsgs import * +from .ClusterMsgs import * from direct.distributed.MsgTypes import * from direct.directnotify import DirectNotifyGlobal from direct.showbase import DirectObject @@ -246,7 +246,7 @@ class ClusterServer(DirectObject.DirectObject): if (type == CLUSTER_NONE): pass elif (type == CLUSTER_EXIT): - print 'GOT EXIT' + print('GOT EXIT') import sys sys.exit() elif (type == CLUSTER_CAM_OFFSET): diff --git a/direct/src/controls/BattleWalker.py b/direct/src/controls/BattleWalker.py index 8b6e634e25..a26beb4103 100755 --- a/direct/src/controls/BattleWalker.py +++ b/direct/src/controls/BattleWalker.py @@ -2,7 +2,7 @@ from direct.showbase.InputStateGlobal import inputState from direct.task.Task import Task from pandac.PandaModules import * -import GravityWalker +from . import GravityWalker BattleStrafe = 0 @@ -166,7 +166,7 @@ class BattleWalker(GravityWalker.GravityWalker): # Should fSlide be renamed slideButton? self.slideSpeed=.15*(turnLeft and -self.avatarControlForwardSpeed or turnRight and self.avatarControlForwardSpeed) - print 'slideSpeed: ', self.slideSpeed + print('slideSpeed: %s' % self.slideSpeed) self.rotationSpeed=0 self.speed=0 @@ -233,7 +233,7 @@ class BattleWalker(GravityWalker.GravityWalker): if self.moving: distance = dt * self.speed slideDistance = dt * self.slideSpeed - print 'slideDistance: ', slideDistance + print('slideDistance: %s' % slideDistance) rotation = dt * self.rotationSpeed # Take a step in the direction of our previous heading. diff --git a/direct/src/controls/GhostWalker.py b/direct/src/controls/GhostWalker.py index 8dd36f2450..4badbf7258 100755 --- a/direct/src/controls/GhostWalker.py +++ b/direct/src/controls/GhostWalker.py @@ -15,7 +15,7 @@ animations based on walker events. """ from direct.directnotify import DirectNotifyGlobal -import NonPhysicsWalker +from . import NonPhysicsWalker class GhostWalker(NonPhysicsWalker.NonPhysicsWalker): diff --git a/direct/src/controls/ObserverWalker.py b/direct/src/controls/ObserverWalker.py index efc9c4b0f9..f93e0e3325 100755 --- a/direct/src/controls/ObserverWalker.py +++ b/direct/src/controls/ObserverWalker.py @@ -16,7 +16,7 @@ animations based on walker events. from panda3d.core import * from direct.directnotify import DirectNotifyGlobal -import NonPhysicsWalker +from . import NonPhysicsWalker class ObserverWalker(NonPhysicsWalker.NonPhysicsWalker): notify = DirectNotifyGlobal.directNotify.newCategory("ObserverWalker") diff --git a/direct/src/controls/PhysicsWalker.py b/direct/src/controls/PhysicsWalker.py index b0a0cdfcb8..fc6fe1ca70 100755 --- a/direct/src/controls/PhysicsWalker.py +++ b/direct/src/controls/PhysicsWalker.py @@ -324,7 +324,7 @@ class PhysicsWalker(DirectObject.DirectObject): indicator.instanceTo(contactIndicatorNode) self.physContactIndicator=contactIndicatorNode else: - print "failed load of physics indicator" + print("failed load of physics indicator") def avatarPhysicsIndicator(self, task): #assert self.debugPrint("avatarPhysicsIndicator()") @@ -710,7 +710,7 @@ class PhysicsWalker(DirectObject.DirectObject): def setPriorParentVector(self): assert self.debugPrint("doDeltaPos()") - print "self.__oldDt", self.__oldDt, "self.__oldPosDelta", self.__oldPosDelta + print("self.__oldDt %s self.__oldPosDelta %s" % (self.__oldDt, self.__oldPosDelta)) if __debug__: onScreenDebug.add("__oldDt", "% 10.4f"%self.__oldDt) onScreenDebug.add("self.__oldPosDelta", diff --git a/direct/src/controls/TwoDWalker.py b/direct/src/controls/TwoDWalker.py index d80f90bf4d..b99f6db11b 100644 --- a/direct/src/controls/TwoDWalker.py +++ b/direct/src/controls/TwoDWalker.py @@ -2,7 +2,7 @@ TwoDWalker.py is for controling the avatars in a 2D Scroller game environment. """ -from GravityWalker import * +from .GravityWalker import * from panda3d.core import ConfigVariableBool diff --git a/direct/src/directbase/ThreeUpStart.py b/direct/src/directbase/ThreeUpStart.py index 3d1784408f..b0a78fcef9 100644 --- a/direct/src/directbase/ThreeUpStart.py +++ b/direct/src/directbase/ThreeUpStart.py @@ -1,5 +1,5 @@ -print 'ThreeUpStart: Starting up environment.' +print('ThreeUpStart: Starting up environment.') from pandac.PandaModules import * diff --git a/direct/src/directdevices/DirectFastrak.py b/direct/src/directdevices/DirectFastrak.py index 4f046329a0..c6e30bd8fc 100644 --- a/direct/src/directdevices/DirectFastrak.py +++ b/direct/src/directdevices/DirectFastrak.py @@ -1,7 +1,7 @@ """ Class used to create and control radamec device """ from math import * from direct.showbase.DirectObject import DirectObject -from DirectDeviceManager import * +from .DirectDeviceManager import * from direct.directnotify import DirectNotifyGlobal diff --git a/direct/src/directdevices/DirectJoybox.py b/direct/src/directdevices/DirectJoybox.py index 7376154947..60c4c4211b 100644 --- a/direct/src/directdevices/DirectJoybox.py +++ b/direct/src/directdevices/DirectJoybox.py @@ -1,6 +1,6 @@ """ Class used to create and control joybox device """ from direct.showbase.DirectObject import DirectObject -from DirectDeviceManager import * +from .DirectDeviceManager import * from direct.directtools.DirectUtil import * from direct.gui import OnscreenText from direct.task import Task diff --git a/direct/src/directdevices/DirectRadamec.py b/direct/src/directdevices/DirectRadamec.py index 2f9a2495f1..2aa7b1933c 100644 --- a/direct/src/directdevices/DirectRadamec.py +++ b/direct/src/directdevices/DirectRadamec.py @@ -1,7 +1,7 @@ """ Class used to create and control radamec device """ from math import * from direct.showbase.DirectObject import DirectObject -from DirectDeviceManager import * +from .DirectDeviceManager import * from direct.directnotify import DirectNotifyGlobal diff --git a/direct/src/directnotify/DirectNotify.py b/direct/src/directnotify/DirectNotify.py index 96f79f57a3..14a712bd40 100644 --- a/direct/src/directnotify/DirectNotify.py +++ b/direct/src/directnotify/DirectNotify.py @@ -2,8 +2,8 @@ DirectNotify module: this module contains the DirectNotify class """ -import Notifier -import Logger +from . import Notifier +from . import Logger class DirectNotify: """ @@ -35,7 +35,7 @@ class DirectNotify: """ Return list of category dictionary keys """ - return (self.__categories.keys()) + return list(self.__categories.keys()) def getCategory(self, categoryName): """getCategory(self, string) @@ -97,7 +97,7 @@ class DirectNotify: category.setInfo(1) category.setDebug(1) else: - print ("DirectNotify: unknown notify level: " + str(level) + print("DirectNotify: unknown notify level: " + str(level) + " for category: " + str(categoryName)) diff --git a/direct/src/directnotify/DirectNotifyGlobal.py b/direct/src/directnotify/DirectNotifyGlobal.py index 353b3d48f7..e25ddb11ad 100644 --- a/direct/src/directnotify/DirectNotifyGlobal.py +++ b/direct/src/directnotify/DirectNotifyGlobal.py @@ -2,7 +2,7 @@ __all__ = ['directNotify', 'giveNotify'] -import DirectNotify +from . import DirectNotify directNotify = DirectNotify.DirectNotify() giveNotify = directNotify.giveNotify diff --git a/direct/src/directnotify/LoggerGlobal.py b/direct/src/directnotify/LoggerGlobal.py index 87a89e446d..610a009a8f 100644 --- a/direct/src/directnotify/LoggerGlobal.py +++ b/direct/src/directnotify/LoggerGlobal.py @@ -1,5 +1,5 @@ """instantiate global Logger object""" -import Logger +from . import Logger defaultLogger = Logger.Logger() diff --git a/direct/src/directnotify/Notifier.py b/direct/src/directnotify/Notifier.py index a0dcc511ad..35a916f8b3 100644 --- a/direct/src/directnotify/Notifier.py +++ b/direct/src/directnotify/Notifier.py @@ -2,7 +2,7 @@ Notifier module: contains methods for handling information output for the programmer/user """ -from LoggerGlobal import defaultLogger +from .LoggerGlobal import defaultLogger from direct.showbase import PythonUtil from panda3d.core import ConfigVariableBool, NotifyCategory, StreamWriter, Notify import time @@ -237,7 +237,7 @@ class Notifier: if self.streamWriter: self.streamWriter.write(string + '\n') else: - print >> sys.stderr, string + sys.stderr.write(string + '\n') def debugStateCall(self, obj=None, fsmMemberName='fsm', secondaryFsm='secondaryFSM'): diff --git a/direct/src/directnotify/RotatingLog.py b/direct/src/directnotify/RotatingLog.py index caf7bbd527..e663da67ac 100755 --- a/direct/src/directnotify/RotatingLog.py +++ b/direct/src/directnotify/RotatingLog.py @@ -91,7 +91,7 @@ class RotatingLog: self.timeLimit=time.time()+self.timeInterval else: # We'll keep writing to the old file, if available. - print "RotatingLog error: Unable to open new log file \"%s\"."%(path,) + print("RotatingLog error: Unable to open new log file \"%s\"." % (path,)) def write(self, data): """ @@ -115,8 +115,9 @@ class RotatingLog: def isatty(self): return self.file.isatty() - def next(self): - return self.file.next() + def __next__(self): + return next(self.file) + next = __next__ def read(self, size): return self.file.read(size) diff --git a/direct/src/directscripts/eggcacher.py b/direct/src/directscripts/eggcacher.py index ea2f653876..ebef394890 100644 --- a/direct/src/directscripts/eggcacher.py +++ b/direct/src/directscripts/eggcacher.py @@ -19,8 +19,8 @@ class EggCacher: self.pandaloader = Loader() self.loaderopts = LoaderOptions(LoaderOptions.LF_no_ram_cache) if (self.bamcache.getActive() == 0): - print "The model cache is not currently active." - print "You must set a model-cache-dir in your config file." + print("The model cache is not currently active.") + print("You must set a model-cache-dir in your config file.") sys.exit(1) self.parseArgs(args) files = self.scanPaths(self.paths) @@ -39,13 +39,13 @@ class EggCacher: else: break if (len(args) < 1): - print "Usage: eggcacher options file-or-directory" + print("Usage: eggcacher options file-or-directory") sys.exit(1) self.paths = args def scanPath(self, eggs, path): if (os.path.exists(path)==0): - print "No such file or directory: "+path + print("No such file or directory: " + path) return if (os.path.isdir(path)): for f in os.listdir(path): @@ -78,7 +78,7 @@ class EggCacher: percent = (progress * 100) / total report = path if (self.concise): report = os.path.basename(report) - print "Preprocessing Models %2d%% %s" % (percent, report) + print("Preprocessing Models %2d%% %s" % (percent, report)) sys.stdout.flush() if (cached) and (cached.hasData()==0): self.pandaloader.loadSync(fn, self.loaderopts) diff --git a/direct/src/directscripts/extract_docs.py b/direct/src/directscripts/extract_docs.py index 8e291f95ae..b6ad69e946 100644 --- a/direct/src/directscripts/extract_docs.py +++ b/direct/src/directscripts/extract_docs.py @@ -5,6 +5,8 @@ You need to run this before invoking Doxyfile.python. It requires a valid makepanda installation with interrogatedb .in files in the lib/pandac/input directory. """ +from __future__ import print_function + __all__ = [] import os @@ -156,61 +158,61 @@ def translated_type_name(type, scoped=True): def processElement(handle, element): if interrogate_element_has_comment(element): - print >>handle, comment(interrogate_element_comment(element)) + print(comment(interrogate_element_comment(element)), file=handle) - print >>handle, translated_type_name(interrogate_element_type(element)), - print >>handle, interrogate_element_name(element) + ';' + print(translated_type_name(interrogate_element_type(element)), end=' ', file=handle) + print(interrogate_element_name(element) + ';', file=handle) def processFunction(handle, function, isConstructor = False): - for i_wrapper in xrange(interrogate_function_number_of_python_wrappers(function)): + for i_wrapper in range(interrogate_function_number_of_python_wrappers(function)): wrapper = interrogate_function_python_wrapper(function, i_wrapper) if interrogate_wrapper_has_comment(wrapper): - print >>handle, block_comment(interrogate_wrapper_comment(wrapper)) + print(block_comment(interrogate_wrapper_comment(wrapper)), file=handle) if not isConstructor: if interrogate_function_is_method(function): if not interrogate_wrapper_number_of_parameters(wrapper) > 0 or not interrogate_wrapper_parameter_is_this(wrapper, 0): - print >>handle, "static", + print("static", end=' ', file=handle) if interrogate_wrapper_has_return_value(wrapper): - print >>handle, translated_type_name(interrogate_wrapper_return_type(wrapper)), + print(translated_type_name(interrogate_wrapper_return_type(wrapper)), end=' ', file=handle) else: pass#print >>handle, "void", - print >>handle, translateFunctionName(interrogate_function_name(function)) + "(", + print(translateFunctionName(interrogate_function_name(function)) + "(", end=' ', file=handle) else: - print >>handle, "__init__(", + print("__init__(", end=' ', file=handle) first = True for i_param in range(interrogate_wrapper_number_of_parameters(wrapper)): if not interrogate_wrapper_parameter_is_this(wrapper, i_param): if not first: - print >>handle, ",", - print >>handle, translated_type_name(interrogate_wrapper_parameter_type(wrapper, i_param)), + print(",", end=' ', file=handle) + print(translated_type_name(interrogate_wrapper_parameter_type(wrapper, i_param)), end=' ', file=handle) if interrogate_wrapper_parameter_has_name(wrapper, i_param): - print >>handle, interrogate_wrapper_parameter_name(wrapper, i_param), + print(interrogate_wrapper_parameter_name(wrapper, i_param), end=' ', file=handle) first = False - print >>handle, ");" + print(");", file=handle) def processType(handle, type): typename = translated_type_name(type, scoped=False) derivations = [ translated_type_name(interrogate_type_get_derivation(type, n)) for n in range(interrogate_type_number_of_derivations(type)) ] if interrogate_type_has_comment(type): - print >>handle, block_comment(interrogate_type_comment(type)) + print(block_comment(interrogate_type_comment(type)), file=handle) if interrogate_type_is_enum(type): - print >>handle, "enum %s {" % typename + print("enum %s {" % typename, file=handle) for i_value in range(interrogate_type_number_of_enum_values(type)): docstring = comment(interrogate_type_enum_value_comment(type, i_value)) if docstring: - print >>handle, docstring - print >>handle, interrogate_type_enum_value_name(type, i_value), "=", interrogate_type_enum_value(type, i_value), "," + print(docstring, file=handle) + print(interrogate_type_enum_value_name(type, i_value), "=", interrogate_type_enum_value(type, i_value), ",", file=handle) elif interrogate_type_is_typedef(type): wrapped_type = translated_type_name(interrogate_type_wrapped_type(type)) - print >>handle, "typedef %s %s;" % (wrapped_type, typename) + print("typedef %s %s;" % (wrapped_type, typename), file=handle) return else: if interrogate_type_is_struct(type): @@ -220,39 +222,39 @@ def processType(handle, type): elif interrogate_type_is_union(type): classtype = "union" else: - print "I don't know what type %s is" % interrogate_type_true_name(type) + print("I don't know what type %s is" % interrogate_type_true_name(type)) return if len(derivations) > 0: - print >>handle, "%s %s : public %s {" % (classtype, typename, ", public ".join(derivations)) + print("%s %s : public %s {" % (classtype, typename, ", public ".join(derivations)), file=handle) else: - print >>handle, "%s %s {" % (classtype, typename) - print >>handle, "public:" + print("%s %s {" % (classtype, typename), file=handle) + print("public:", file=handle) - for i_ntype in xrange(interrogate_type_number_of_nested_types(type)): + for i_ntype in range(interrogate_type_number_of_nested_types(type)): processType(handle, interrogate_type_get_nested_type(type, i_ntype)) - for i_method in xrange(interrogate_type_number_of_constructors(type)): + for i_method in range(interrogate_type_number_of_constructors(type)): processFunction(handle, interrogate_type_get_constructor(type, i_method), True) - for i_method in xrange(interrogate_type_number_of_methods(type)): + for i_method in range(interrogate_type_number_of_methods(type)): processFunction(handle, interrogate_type_get_method(type, i_method)) - for i_method in xrange(interrogate_type_number_of_make_seqs(type)): - print >>handle, "list", translateFunctionName(interrogate_make_seq_seq_name(interrogate_type_get_make_seq(type, i_method))), "();" + for i_method in range(interrogate_type_number_of_make_seqs(type)): + print("list", translateFunctionName(interrogate_make_seq_seq_name(interrogate_type_get_make_seq(type, i_method))), "();", file=handle) - for i_element in xrange(interrogate_type_number_of_elements(type)): + for i_element in range(interrogate_type_number_of_elements(type)): processElement(handle, interrogate_type_get_element(type, i_element)) - print >>handle, "};" + print("};", file=handle) def processModule(handle, package): - print >>handle, "namespace %s {" % package + print("namespace %s {" % package, file=handle) if package != "core": - print >>handle, "using namespace core;" + print("using namespace core;", file=handle) - for i_type in xrange(interrogate_number_of_global_types()): + for i_type in range(interrogate_number_of_global_types()): type = interrogate_get_global_type(i_type) if interrogate_type_has_module_name(type): @@ -260,9 +262,9 @@ def processModule(handle, package): if "panda3d." + package == module_name: processType(handle, type) else: - print "Type %s has no module name" % typename + print("Type %s has no module name" % typename) - for i_func in xrange(interrogate_number_of_global_functions()): + for i_func in range(interrogate_number_of_global_functions()): func = interrogate_get_global_function(i_func) if interrogate_function_has_module_name(func): @@ -270,16 +272,16 @@ def processModule(handle, package): if "panda3d." + package == module_name: processFunction(handle, func) else: - print "Type %s has no module name" % typename + print("Type %s has no module name" % typename) - print >>handle, "}" + print("}", file=handle) if __name__ == "__main__": handle = open("pandadoc.hpp", "w") - print >>handle, comment("Panda3D modules that are implemented in C++.") - print >>handle, "namespace panda3d {" + print(comment("Panda3D modules that are implemented in C++."), file=handle) + print("namespace panda3d {", file=handle) # Determine the path to the interrogatedb files interrogate_add_search_directory(os.path.join(os.path.dirname(pandac.__file__), "..", "..", "etc")) @@ -295,5 +297,5 @@ if __name__ == "__main__": processModule(handle, module_name) - print >>handle, "}" + print("}", file=handle) handle.close() diff --git a/direct/src/directscripts/gendocs.py b/direct/src/directscripts/gendocs.py index 7770203de4..6bb83c9567 100644 --- a/direct/src/directscripts/gendocs.py +++ b/direct/src/directscripts/gendocs.py @@ -48,7 +48,7 @@ # ######################################################################## -import os, sys, parser, symbol, token, types, re +import os, sys, parser, symbol, token, re ######################################################################## # @@ -103,7 +103,7 @@ def writeFileLines(wfile, lines): sys.exit("Cannot write "+wfile) def findFiles(dirlist, ext, ign, list): - if isinstance(dirlist, types.StringTypes): + if isinstance(dirlist, str): dirlist = [dirlist] for dir in dirlist: for file in os.listdir(dir): @@ -195,8 +195,8 @@ class InterrogateTokenizer: neg = 1 self.pos += 1 if (self.data[self.pos].isdigit()==0): - print "File position "+str(self.pos) - print "Text: "+self.data[self.pos:self.pos+50] + print("File position " + str(self.pos)) + print("Text: " + self.data[self.pos:self.pos+50]) sys.exit("Syntax error in interrogate file format 0") value = 0 while (self.data[self.pos].isdigit()): @@ -340,20 +340,20 @@ class InterrogateDatabase: def printTree(tree, indent): spacing = " "[:indent] - if isinstance(tree, types.TupleType) and isinstance(tree[0], types.IntType): + if isinstance(tree, tuple) and isinstance(tree[0], int): if tree[0] in symbol.sym_name: for i in range(len(tree)): if (i==0): - print spacing + "(symbol." + symbol.sym_name[tree[0]] + "," + print(spacing + "(symbol." + symbol.sym_name[tree[0]] + ",") else: printTree(tree[i], indent+1) - print spacing + ")," + print(spacing + "),") elif tree[0] in token.tok_name: - print spacing + "(token." + token.tok_name[tree[0]] + ", '" + tree[1] + "')," + print(spacing + "(token." + token.tok_name[tree[0]] + ", '" + tree[1] + "'),") else: - print spacing + str(tree) + print(spacing + str(tree)) else: - print spacing + str(tree) + print(spacing + str(tree)) COMPOUND_STMT_PATTERN = ( @@ -447,7 +447,7 @@ class ParseTreeInfo: self.function_info = {} self.assign_info = {} self.derivs = {} - if isinstance(tree, types.StringType): + if isinstance(tree, str): try: tree = parser.suite(tree+"\n").totuple() if (tree): @@ -455,8 +455,8 @@ class ParseTreeInfo: if found: self.docstring = vars["docstring"] except: - print "CAUTION --- Parse failed: "+name - if isinstance(tree, types.TupleType): + print("CAUTION --- Parse failed: " + name) + if isinstance(tree, tuple): self.extract_info(tree) def match(self, pattern, data, vars=None): @@ -480,10 +480,10 @@ class ParseTreeInfo: """ if vars is None: vars = {} - if type(pattern) is types.ListType: # 'variables' are ['varname'] + if type(pattern) is list: # 'variables' are ['varname'] vars[pattern[0]] = data return 1, vars - if type(pattern) is not types.TupleType: + if type(pattern) is not tuple: return (pattern == data), vars if len(data) != len(pattern): return 0, vars @@ -534,7 +534,7 @@ class ParseTreeInfo: classinfo.derivs[vars["classname"]] = 1 def extract_tokens(self, str, tree): - if (isinstance(tree, types.TupleType)): + if (isinstance(tree, tuple)): if tree[0] in token.tok_name: str = str + tree[1] if (tree[1]==","): str=str+" " @@ -564,7 +564,7 @@ class CodeDatabase: self.varExports = {} self.globalfn = [] self.formattedprotos = {} - print "Reading C++ source files" + print("Reading C++ source files") for cxx in cxxlist: tokzr = InterrogateTokenizer(cxx) idb = InterrogateDatabase(tokzr) @@ -583,7 +583,7 @@ class CodeDatabase: self.funcExports.setdefault("pandac.PandaModules", []).append(func.pyname) else: self.funcs[type.scopedname+"."+func.pyname] = func - print "Reading Python sources files" + print("Reading Python sources files") for py in pylist: pyinf = ParseTreeInfo(readFile(py), py, py) mod = pathToModule(py) @@ -602,7 +602,7 @@ class CodeDatabase: self.varExports.setdefault(mod, []).append(var) def getClassList(self): - return self.goodtypes.keys() + return list(self.goodtypes.keys()) def getGlobalFunctionList(self): return self.globalfn @@ -625,7 +625,7 @@ class CodeDatabase: parents.append(basetype.scopedname) return parents elif (isinstance(type, ParseTreeInfo)): - return type.derivs.keys() + return list(type.derivs.keys()) else: return [] @@ -767,7 +767,7 @@ CLASS_RENAME_DICT = { ######################################################################## def makeCodeDatabase(indirlist, directdirlist): - if isinstance(directdirlist, types.StringTypes): + if isinstance(directdirlist, str): directdirlist = [directdirlist] ignore = {} ignore["__init__.py"] = 1 @@ -820,7 +820,7 @@ def generate(pversion, indirlist, directdirlist, docdir, header, footer, urlpref classes = code.getClassList()[:] classes.sort(None, str.lower) xclasses = classes[:] - print "Generating HTML pages" + print("Generating HTML pages") for type in classes: body = "

" + type + "

\n" comment = code.getClassComment(type) @@ -900,14 +900,14 @@ def generate(pversion, indirlist, directdirlist, docdir, header, footer, urlpref index = "

List of Methods - Panda " + pversion + "

\n" - prefixes = table.keys() + prefixes = list(table.keys()) prefixes.sort(None, str.lower) for prefix in prefixes: index = index + linkTo("#"+prefix, prefix) + " " index = index + "

" for prefix in prefixes: index = index + '' + "\n" - names = table[prefix].keys() + names = list(table[prefix].keys()) names.sort(None, str.lower) for name in names: line = '' + name + ":