mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
Fix various import issues in the direct tree
This commit is contained in:
parent
50d2e8324e
commit
32367fcbdc
@ -19,7 +19,7 @@ CollisionHandlerRayStart = 4000.0 # This is a hack, it may be better to use a li
|
||||
|
||||
class ControlManager:
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("ControlManager")
|
||||
wantWASD = ConfigVariableBool('want-WASD', True)
|
||||
wantWASD = ConfigVariableBool('want-WASD', False)
|
||||
|
||||
def __init__(self, enable=True, passMessagesThrough = False):
|
||||
assert self.notify.debug("init control manager %s" % (passMessagesThrough))
|
||||
|
@ -18,13 +18,14 @@ from direct.showbase.InputStateGlobal import inputState
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.showbase import DirectObject
|
||||
from direct.task.Task import Task
|
||||
from pandac.PandaModules import *
|
||||
from panda3d.core import *
|
||||
|
||||
|
||||
class DevWalker(DirectObject.DirectObject):
|
||||
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DevWalker")
|
||||
wantDebugIndicator = base.config.GetBool('want-avatar-physics-indicator', 0)
|
||||
runMultiplier = base.config.GetFloat('dev-run-multiplier', 4.0)
|
||||
wantDebugIndicator = ConfigVariableBool('want-avatar-physics-indicator', False)
|
||||
runMultiplier = ConfigVariableDouble('dev-run-multiplier', 4.0)
|
||||
|
||||
# Ghost mode overrides this:
|
||||
slideName = "slide-is-disabled"
|
||||
@ -109,7 +110,7 @@ class DevWalker(DirectObject.DirectObject):
|
||||
slideRight = inputState.isSet("slideRight")
|
||||
levitateUp = inputState.isSet("levitateUp")
|
||||
levitateDown = inputState.isSet("levitateDown")
|
||||
run = inputState.isSet("run") and self.runMultiplier or 1.0
|
||||
run = inputState.isSet("run") and self.runMultiplier.getValue() or 1.0
|
||||
|
||||
# Check for Auto-Run
|
||||
if base.localAvatar.getAutoRun():
|
||||
|
@ -14,8 +14,6 @@ although it does send messeges that allow a listener to play sounds or
|
||||
animations based on walker events.
|
||||
"""
|
||||
|
||||
from direct.showbase.ShowBaseGlobal import *
|
||||
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
import NonPhysicsWalker
|
||||
|
||||
|
@ -23,7 +23,7 @@ from pandac.PandaModules import *
|
||||
|
||||
class NonPhysicsWalker(DirectObject.DirectObject):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("NonPhysicsWalker")
|
||||
wantDebugIndicator = base.config.GetBool('want-avatar-physics-indicator', 0)
|
||||
wantDebugIndicator = ConfigVariableBool('want-avatar-physics-indicator', False)
|
||||
|
||||
# Ghost mode overrides this:
|
||||
slideName = "slide-is-disabled"
|
||||
|
@ -14,8 +14,7 @@ although it does send messeges that allow a listener to play sounds or
|
||||
animations based on walker events.
|
||||
"""
|
||||
|
||||
from direct.showbase.ShowBaseGlobal import *
|
||||
from pandac.PandaModules import *
|
||||
from panda3d.core import *
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
import NonPhysicsWalker
|
||||
|
||||
|
@ -3,6 +3,8 @@ TwoDWalker.py is for controling the avatars in a 2D Scroller game environment.
|
||||
"""
|
||||
|
||||
from GravityWalker import *
|
||||
from panda3d.core import ConfigVariableBool
|
||||
|
||||
|
||||
class TwoDWalker(GravityWalker):
|
||||
"""
|
||||
@ -14,9 +16,9 @@ class TwoDWalker(GravityWalker):
|
||||
customizable input list.
|
||||
"""
|
||||
notify = directNotify.newCategory("TwoDWalker")
|
||||
wantDebugIndicator = base.config.GetBool('want-avatar-physics-indicator', 0)
|
||||
wantFloorSphere = base.config.GetBool('want-floor-sphere', 0)
|
||||
earlyEventSphere = base.config.GetBool('early-event-sphere', 0)
|
||||
wantDebugIndicator = ConfigVariableBool('want-avatar-physics-indicator', False)
|
||||
wantFloorSphere = ConfigVariableBool('want-floor-sphere', False)
|
||||
earlyEventSphere = ConfigVariableBool('early-event-sphere', False)
|
||||
|
||||
# special methods
|
||||
def __init__(self, gravity = -32.1740, standableGround=0.707,
|
||||
@ -55,4 +57,4 @@ class TwoDWalker(GravityWalker):
|
||||
self.lifter.addVelocity(self.avatarControlJumpForce)
|
||||
messenger.send("jumpStart")
|
||||
self.isAirborne = 1
|
||||
assert self.debugPrint("isAirborne 1 due to jump")
|
||||
assert self.debugPrint("isAirborne 1 due to jump")
|
||||
|
@ -23,7 +23,7 @@ class DirectDeviceManager(VrpnClient, DirectObject):
|
||||
self.server = server
|
||||
else:
|
||||
# Check config file, if that fails, use default
|
||||
self.server = myBase.config.GetString('vrpn-server', 'spacedyne')
|
||||
self.server = ConfigVariableString('vrpn-server', 'spacedyne').getValue()
|
||||
|
||||
# Create a vrpn client
|
||||
VrpnClient.__init__(self, self.server)
|
||||
|
@ -18,7 +18,10 @@ class DirectLight(NodePath):
|
||||
return self.light
|
||||
|
||||
class DirectLights(NodePath):
|
||||
def __init__(self, parent = render):
|
||||
def __init__(self, parent = None):
|
||||
if parent is None:
|
||||
parent = base.render
|
||||
|
||||
# Initialize the superclass
|
||||
NodePath.__init__(self)
|
||||
# Create a node for the lights
|
||||
|
@ -907,8 +907,11 @@ class DirectSession(DirectObject):
|
||||
def removeAllSelected(self):
|
||||
self.selected.removeAll()
|
||||
|
||||
def showAllDescendants(self, nodePath = render):
|
||||
def showAllDescendants(self, nodePath = None):
|
||||
""" Show the level and its descendants """
|
||||
if nodePath is None:
|
||||
nodePath = base.render
|
||||
|
||||
if not isinstance(nodePath, CollisionNode):
|
||||
nodePath.show()
|
||||
|
||||
|
@ -1,16 +1,17 @@
|
||||
from otp.ai.AIBaseGlobal import *
|
||||
#from otp.ai.AIBaseGlobal import *
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
from ConnectionRepository import *
|
||||
from panda3d.core import ConfigVariableDouble, ConfigVariableInt, ConfigVariableBool
|
||||
|
||||
ASYNC_REQUEST_DEFAULT_TIMEOUT_IN_SECONDS = 8.0
|
||||
ASYNC_REQUEST_INFINITE_RETRIES = -1
|
||||
ASYNC_REQUEST_DEFAULT_NUM_RETRIES = 0
|
||||
|
||||
if __debug__:
|
||||
_overrideTimeoutTimeForAllAsyncRequests = config.GetFloat("async-request-timeout", -1.0)
|
||||
_overrideNumRetriesForAllAsyncRequests = config.GetInt("async-request-num-retries", -1)
|
||||
_breakOnTimeout = config.GetBool("async-request-break-on-timeout", False)
|
||||
_overrideTimeoutTimeForAllAsyncRequests = ConfigVariableDouble("async-request-timeout", -1.0)
|
||||
_overrideNumRetriesForAllAsyncRequests = ConfigVariableInt("async-request-num-retries", -1)
|
||||
_breakOnTimeout = ConfigVariableBool("async-request-break-on-timeout", False)
|
||||
|
||||
class AsyncRequest(DirectObject):
|
||||
"""
|
||||
@ -51,10 +52,10 @@ class AsyncRequest(DirectObject):
|
||||
"""
|
||||
assert AsyncRequest.notify.debugCall()
|
||||
if __debug__:
|
||||
if _overrideTimeoutTimeForAllAsyncRequests >= 0.0:
|
||||
timeoutTime = _overrideTimeoutTimeForAllAsyncRequests
|
||||
if _overrideNumRetriesForAllAsyncRequests >= 0:
|
||||
numRetries = _overrideNumRetriesForAllAsyncRequests
|
||||
if _overrideTimeoutTimeForAllAsyncRequests.getValue() >= 0.0:
|
||||
timeoutTime = _overrideTimeoutTimeForAllAsyncRequests.getValue()
|
||||
if _overrideNumRetriesForAllAsyncRequests.getValue() >= 0:
|
||||
numRetries = _overrideNumRetriesForAllAsyncRequests.getValue()
|
||||
AsyncRequest._asyncRequests[id(self)] = self
|
||||
self.deletingMessage = "AsyncRequest-deleting-%s"%(id(self,))
|
||||
self.air = air
|
||||
|
@ -122,7 +122,7 @@ class CRCache:
|
||||
def checkCache(self):
|
||||
# For debugging; this verifies that the cache is sensible and
|
||||
# returns true if so.
|
||||
from pandac.PandaModules import NodePath
|
||||
from panda3d.core import NodePath
|
||||
for obj in self.dict.values():
|
||||
if isinstance(obj, NodePath):
|
||||
assert not obj.isEmpty() and obj.getTopNode() != render.node()
|
||||
|
@ -1,4 +1,6 @@
|
||||
from direct.distributed.CachedDOData import CachedDOData
|
||||
from panda3d.core import ConfigVariableInt
|
||||
|
||||
|
||||
class CRDataCache:
|
||||
# Stores cached data for DistributedObjects between instantiations on the client
|
||||
@ -6,7 +8,7 @@ class CRDataCache:
|
||||
def __init__(self):
|
||||
self._doId2name2data = {}
|
||||
# maximum # of objects we will cache data for
|
||||
self._size = config.GetInt('crdatacache-size', 10)
|
||||
self._size = ConfigVariableInt('crdatacache-size', 10).getValue()
|
||||
assert self._size > 0
|
||||
# used to preserve the cache size
|
||||
self._junkIndex = 0
|
||||
|
@ -5,7 +5,7 @@ from direct.directnotify import DirectNotifyGlobal
|
||||
from MsgTypesCMU import *
|
||||
from PyDatagram import PyDatagram
|
||||
from PyDatagramIterator import PyDatagramIterator
|
||||
from pandac.PandaModules import UniqueIdAllocator
|
||||
from panda3d.core import UniqueIdAllocator
|
||||
import types
|
||||
|
||||
class ClientRepository(ClientRepositoryBase):
|
||||
|
@ -1,6 +1,6 @@
|
||||
from pandac.PandaModules import *
|
||||
from direct.task import Task
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
from direct.distributed.DoInterestManager import DoInterestManager
|
||||
from direct.distributed.DoCollectionManager import DoCollectionManager
|
||||
from direct.showbase import GarbageReport
|
||||
@ -20,7 +20,7 @@ class ConnectionRepository(
|
||||
connection (and exchange datagrams) with a gameserver. This
|
||||
includes ClientRepository and AIRepository.
|
||||
"""
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("ConnectionRepository")
|
||||
notify = directNotify.newCategory("ConnectionRepository")
|
||||
taskPriority = -30
|
||||
taskChain = None
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
from pandac.PandaModules import *
|
||||
from direct.interval.IntervalGlobal import *
|
||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
|
||||
from direct.distributed.DistributedNode import DistributedNode
|
||||
from direct.task import Task
|
||||
@ -24,7 +25,7 @@ class DistributedCartesianGrid(DistributedNode, CartesianGridBase):
|
||||
notify = directNotify.newCategory("DistributedCartesianGrid")
|
||||
notify.setDebug(0)
|
||||
|
||||
VisualizeGrid = config.GetBool("visualize-cartesian-grid", 0)
|
||||
VisualizeGrid = ConfigVariableBool("visualize-cartesian-grid", False)
|
||||
|
||||
RuleSeparator = ":"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
from pandac.PandaModules import *
|
||||
|
||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
from direct.task import Task
|
||||
from DistributedNodeAI import DistributedNodeAI
|
||||
from CartesianGridBase import CartesianGridBase
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""DistributedNode module: contains the DistributedNode class"""
|
||||
|
||||
from pandac.PandaModules import NodePath
|
||||
from direct.showbase.ShowBaseGlobal import *
|
||||
from panda3d.core import NodePath
|
||||
from direct.task import Task
|
||||
import GridParent
|
||||
import DistributedObject
|
||||
|
@ -1,4 +1,4 @@
|
||||
from otp.ai.AIBaseGlobal import *
|
||||
#from otp.ai.AIBaseGlobal import *
|
||||
from DistributedObjectUD import DistributedObjectUD
|
||||
|
||||
class DistributedNodeUD(DistributedObjectUD):
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
#from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
|
||||
class DistributedObjectBase(DirectObject):
|
||||
"""
|
||||
|
@ -78,12 +78,7 @@ class DoInterestManager(DirectObject.DirectObject):
|
||||
Top level Interest Manager
|
||||
"""
|
||||
notify = directNotify.newCategory("DoInterestManager")
|
||||
try:
|
||||
tempbase = base
|
||||
except:
|
||||
tempbase = simbase
|
||||
InterestDebug = tempbase.config.GetBool('interest-debug', False)
|
||||
del tempbase
|
||||
InterestDebug = ConfigVariableBool('interest-debug', False)
|
||||
|
||||
# 'handle' is a number that represents a single interest set that the
|
||||
# client has requested; the interest set may be modified
|
||||
|
@ -21,29 +21,29 @@ class TimeManager(DistributedObject.DistributedObject):
|
||||
# The number of seconds to wait between automatic
|
||||
# synchronizations. Set to 0 to disable auto sync after
|
||||
# startup.
|
||||
updateFreq = base.config.GetFloat('time-manager-freq', 1800)
|
||||
updateFreq = ConfigVariableDouble('time-manager-freq', 1800).getValue()
|
||||
|
||||
# The minimum number of seconds to wait between two unrelated
|
||||
# synchronization attempts. Increasing this number cuts down
|
||||
# on frivolous synchronizations.
|
||||
minWait = base.config.GetFloat('time-manager-min-wait', 10)
|
||||
minWait = ConfigVariableDouble('time-manager-min-wait', 10).getValue()
|
||||
|
||||
# The maximum number of seconds of uncertainty to tolerate in
|
||||
# the clock delta without trying again.
|
||||
maxUncertainty = base.config.GetFloat('time-manager-max-uncertainty', 1)
|
||||
maxUncertainty = ConfigVariableDouble('time-manager-max-uncertainty', 1).getValue()
|
||||
|
||||
# The maximum number of attempts to try to get a low-latency
|
||||
# time measurement before giving up and accepting whatever we
|
||||
# get.
|
||||
maxAttempts = base.config.GetInt('time-manager-max-attempts', 5)
|
||||
maxAttempts = ConfigVariableInt('time-manager-max-attempts', 5).getValue()
|
||||
|
||||
# A simulated clock skew for debugging, in seconds.
|
||||
extraSkew = base.config.GetInt('time-manager-extra-skew', 0)
|
||||
extraSkew = ConfigVariableInt('time-manager-extra-skew', 0).getValue()
|
||||
|
||||
if extraSkew != 0:
|
||||
notify.info("Simulating clock skew of %0.3f s" % extraSkew)
|
||||
|
||||
reportFrameRateInterval = base.config.GetDouble('report-frame-rate-interval', 300.0)
|
||||
reportFrameRateInterval = ConfigVariableDouble('report-frame-rate-interval', 300.0).getValue()
|
||||
|
||||
def __init__(self, cr):
|
||||
DistributedObject.DistributedObject.__init__(self, cr)
|
||||
|
@ -382,24 +382,6 @@ class EventPulse(Pulse, DirectObject):
|
||||
self.ignoreAll()
|
||||
Pulse.destroy(self)
|
||||
|
||||
if __debug__:
|
||||
l = []
|
||||
def handler(value, l=l):
|
||||
l.append(value)
|
||||
ep = EventPulse('testEvent')
|
||||
fc = FunctionCall(handler, ep)
|
||||
assert l == []
|
||||
messenger.send('testEvent')
|
||||
assert l == [True, False, ]
|
||||
messenger.send('testEvent')
|
||||
assert l == [True, False, True, False, ]
|
||||
fc.destroy()
|
||||
ep.destroy()
|
||||
del fc
|
||||
del ep
|
||||
del l
|
||||
del handler
|
||||
|
||||
class EventArgument(PushesStateChanges, DirectObject):
|
||||
# tracks a particular argument to a particular messenger event
|
||||
def __init__(self, event, index=0):
|
||||
@ -415,25 +397,6 @@ class EventArgument(PushesStateChanges, DirectObject):
|
||||
def _handleEvent(self, *args):
|
||||
self._handlePotentialStateChange(args[self._index])
|
||||
|
||||
if __debug__:
|
||||
l = []
|
||||
def handler(value, l=l):
|
||||
l.append(value)
|
||||
ea = EventArgument('testEvent', index=1)
|
||||
fc = FunctionCall(handler, ea)
|
||||
assert l == []
|
||||
fc.pushCurrentState()
|
||||
assert l == [None, ]
|
||||
messenger.send('testEvent', ['a', 'b'])
|
||||
assert l == [None, 'b', ]
|
||||
messenger.send('testEvent', [1, 2, 3, ])
|
||||
assert l == [None, 'b', 2, ]
|
||||
fc.destroy()
|
||||
ea.destroy()
|
||||
del fc
|
||||
del ea
|
||||
del l
|
||||
|
||||
class AttrSetter(StateChangeNode):
|
||||
def __init__(self, source, object, attrName):
|
||||
self._object = object
|
||||
|
@ -5,6 +5,7 @@ __all__ = []
|
||||
|
||||
if __name__ == "__main__":
|
||||
from direct.showbase.ShowBase import ShowBase
|
||||
import DirectGuiGlobals
|
||||
from DirectGui import *
|
||||
#from whrandom import *
|
||||
from random import *
|
||||
@ -46,7 +47,7 @@ if __name__ == "__main__":
|
||||
db.component('geom0').setScale(db.component('geom2').getScale()[0])
|
||||
db.component('geom1').setScale(db.component('geom2').getScale()[0])
|
||||
db['text2_text'] = 'Ouch!'
|
||||
db['geom2_color'] = Vec4(1, 0, 0, 1)
|
||||
db['geom2_color'] = (1, 0, 0, 1)
|
||||
newX = -1.0 + random() * 2.0
|
||||
newZ = -1.0 + random() * 2.0
|
||||
db.lerpPos(Point3(newX, 0, newZ), 1.0, task = 'runAway',
|
||||
@ -66,7 +67,7 @@ if __name__ == "__main__":
|
||||
text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
|
||||
scale = .15, relief = 'raised',
|
||||
# Here we set an option for a component of the button
|
||||
geom1_color = Vec4(1, 0, 0, 1),
|
||||
geom1_color = (1, 0, 0, 1),
|
||||
# Here is an example of a component group option
|
||||
text_pos = (.6, -.8),
|
||||
# Set audio characteristics
|
||||
@ -140,4 +141,4 @@ if __name__ == "__main__":
|
||||
print 'HEIGHT:', de1.getHeight()
|
||||
print 'CENTER:', de1.getCenter()
|
||||
|
||||
run()
|
||||
base.run()
|
||||
|
@ -1,7 +1,8 @@
|
||||
import LevelEditor
|
||||
|
||||
base.le = LevelEditor.LevelEditor()
|
||||
# You should define LevelEditor instance as
|
||||
# base.le so it can be reached in global scope
|
||||
if __name__ == '__main__':
|
||||
base.le = LevelEditor.LevelEditor()
|
||||
# You should define LevelEditor instance as
|
||||
# base.le so it can be reached in global scope
|
||||
|
||||
run()
|
||||
base.run()
|
||||
|
@ -30,4 +30,4 @@ if __name__ == "__main__":
|
||||
# Particle Panel
|
||||
pp = ParticlePanel.ParticlePanel(pe)
|
||||
|
||||
run()
|
||||
base.run()
|
||||
|
@ -1,3 +1,5 @@
|
||||
from panda3d.core import NodePath
|
||||
from panda3d.physics import *
|
||||
|
||||
class FallTest(NodePath):
|
||||
def __init__(self):
|
||||
@ -79,7 +81,7 @@ class FallTest(NodePath):
|
||||
if __name__ == "__main__":
|
||||
from direct.directbase.ThreeUpStart import *
|
||||
test=FallTest()
|
||||
test.reparentTo(render)
|
||||
test.reparentTo(base.render)
|
||||
test.setup()
|
||||
camera.setY(-10.0)
|
||||
run()
|
||||
base.camera.setY(-10.0)
|
||||
base.run()
|
||||
|
@ -1,3 +1,5 @@
|
||||
from panda3d.core import NodePath
|
||||
from panda3d.physics import *
|
||||
|
||||
class RotationTest(NodePath):
|
||||
def __init__(self):
|
||||
@ -89,7 +91,7 @@ class RotationTest(NodePath):
|
||||
if __name__ == "__main__":
|
||||
from direct.directbase.ThreeUpStart import *
|
||||
test=RotationTest()
|
||||
test.reparentTo(render)
|
||||
test.reparentTo(base.render)
|
||||
test.setup()
|
||||
camera.setY(-10.0)
|
||||
run()
|
||||
base.camera.setY(-10.0)
|
||||
base.run()
|
||||
|
@ -1,4 +1,5 @@
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
from direct.directnotify.DirectNotifyGlobal import directNotify
|
||||
from panda3d.core import *
|
||||
from PhasedObject import PhasedObject
|
||||
|
||||
|
@ -1,66 +0,0 @@
|
||||
"""Undocumented Module"""
|
||||
|
||||
__all__ = ['ExcelHandler']
|
||||
|
||||
"""
|
||||
A simple XML parser for Excel XML data. Built on top of xml.sax
|
||||
|
||||
Example use:
|
||||
e=ExcelHandler()
|
||||
parse('myData.xml', e)
|
||||
print e.tables
|
||||
|
||||
"""
|
||||
|
||||
from xml.sax import saxutils
|
||||
|
||||
class ExcelHandler(saxutils.DefaultHandler):
|
||||
def __init__(self):
|
||||
self.chars=[]
|
||||
self.isNumber = 0
|
||||
self.cells=[]
|
||||
self.rows=[]
|
||||
self.tables=[]
|
||||
|
||||
def characters(self, content):
|
||||
self.chars.append(content)
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
if name=="Data":
|
||||
if attrs.get('ss:Type') == "Number":
|
||||
self.isNumber = 1
|
||||
else:
|
||||
self.isNumber = 0
|
||||
elif name=="Cell":
|
||||
self.chars=[]
|
||||
elif name=="Row":
|
||||
self.cells=[]
|
||||
elif name=="Table":
|
||||
self.rows=[]
|
||||
|
||||
def endElement(self, name):
|
||||
if name=="Data":
|
||||
pass
|
||||
elif name=="Cell":
|
||||
s = ''.join(self.chars)
|
||||
if s:
|
||||
if self.isNumber:
|
||||
# Determine if it is an int or float and use
|
||||
# return the best fit
|
||||
floatVersion = float(s)
|
||||
intVersion = int(floatVersion)
|
||||
if floatVersion == intVersion:
|
||||
# If the float is equal to the int, it must be an int
|
||||
s = intVersion
|
||||
else:
|
||||
# Keep the precision and return a float
|
||||
s = floatVersion
|
||||
# Convert the string "None" to the python object None
|
||||
elif s == "None":
|
||||
s = None
|
||||
self.cells.append(s)
|
||||
elif name=="Row":
|
||||
self.rows.append(self.cells)
|
||||
elif name=="Table":
|
||||
self.tables.append(self.rows)
|
||||
|
@ -1,201 +0,0 @@
|
||||
from itertools import tee
|
||||
|
||||
def itersorted(iterable, cmp = cmp, key = lambda x: x, reverse = False):
|
||||
"""
|
||||
This function returns a generator object that yields sorted items from
|
||||
'iterable'.
|
||||
|
||||
It implements a form of lazy sorting that's most useful in two cases:
|
||||
1) When you only need the first few values in the sorted data.
|
||||
2) When you want to amortize the cost of the sort over the time
|
||||
you use the data.
|
||||
|
||||
It is to be considered a 'stable sort', where values with equivalent
|
||||
sorting criteria maintain their relative order as it is in the input
|
||||
data set.
|
||||
|
||||
'cmp' MUST return values in [-1,0,1]. Otherwise, behavior is
|
||||
undefined, and will most likely be very incorrect.
|
||||
"""
|
||||
|
||||
# Notes:
|
||||
# Understanding the concepts of 'left' and 'right' here is important.
|
||||
# 'left' values are those that are yielded earlier in the sort. So
|
||||
# each subsequent value yielded is 'to the right' of the previous one.
|
||||
# A stack is used to maintain sets of values who share the same key
|
||||
# value. Each layer corresponds to one key. During the traversals of
|
||||
# the input data, values are added to each layer in such a way that
|
||||
# they maintain their relative position (to others in the same layer)
|
||||
# from the original data. This ensures a 'stable sort'.
|
||||
|
||||
# Create our working structures
|
||||
stack = [] # holds a stack of 'layers'.
|
||||
# 'left' value layers are above 'right' ones.
|
||||
layer = () # A 3-tuple of the form:
|
||||
# (key, data iterator, [values])
|
||||
init = True # Is set to true for the first pass through
|
||||
# the data.
|
||||
if reverse: # Use this to easily switch the direction of the sort.
|
||||
rev = -1
|
||||
else:
|
||||
rev = 1
|
||||
|
||||
# Create the base iterator that will track our
|
||||
# main progress through the data.
|
||||
a = ((key(x),x) for x in iterable)
|
||||
|
||||
# Begin the main loop
|
||||
while 1:
|
||||
# If the stack is empty, we must now seed it.
|
||||
# Advance the base iterator until we find a value 'to the right' of
|
||||
# anything we've yielded so far. (All values 'to the left' have
|
||||
# already been yielded)
|
||||
if not stack:
|
||||
# pull next value off the base iterator
|
||||
k,val = a.next()
|
||||
|
||||
# If init, get the first value and stop.
|
||||
# Otherwise, find the first value 'to the right'
|
||||
# of the most recently yielded value.
|
||||
while (not init) and (cmp(k,lLimit) != rev):
|
||||
k,val = a.next()
|
||||
pass
|
||||
|
||||
# Place the found value as the initial stack value
|
||||
# (and store its iteration progress as well).
|
||||
a,b = tee(a)
|
||||
stack.append([k, b, [val]])
|
||||
pass
|
||||
|
||||
|
||||
# We now iterate through the data, starting where the value
|
||||
# at the top of the stack left off.
|
||||
layer = stack[-1]
|
||||
b = layer[1]
|
||||
for k,val in b:
|
||||
# If the next data element is 'to the left' of (or equal to)
|
||||
# the top off the stack and 'to the right' of the last element
|
||||
# yielded, add it to the stack.
|
||||
if cmp(k,layer[0]) != rev and (init or cmp(k,lLimit) == rev):
|
||||
# If it's 'to the left' of the current stack value,
|
||||
# make a new layer and add it to the top of the stack.
|
||||
# Otherwise, it's equivalent so we'll just append it
|
||||
# to the values in the top layer of the stack.
|
||||
if cmp(k,layer[0]) == -rev:
|
||||
b,layer[1] = tee(b)
|
||||
stack.append([k, b, []])
|
||||
layer = stack[-1]
|
||||
pass
|
||||
layer[2].append(val)
|
||||
pass
|
||||
pass
|
||||
# Remove the initialization condition to enable lLimit checking.
|
||||
init = False
|
||||
|
||||
# Whatever values that are on the top stack at this point are
|
||||
# the 'left-most' we've found that we haven't yet yielded. Yield
|
||||
# them in the order that we discovered them in the source data.
|
||||
# Define lLimit as the right-most limit for values that have not
|
||||
# yet been yielded. This will allow us to ignore these values
|
||||
# on future iterations.
|
||||
lLimit, b, vals = stack.pop()
|
||||
for val in vals:
|
||||
yield val
|
||||
pass
|
||||
|
||||
if __debug__:
|
||||
def P(i):
|
||||
for x in reversed(i):
|
||||
print x
|
||||
|
||||
def test():
|
||||
from itertools import islice
|
||||
|
||||
control = sorted(data, key = lambda x: x[0])
|
||||
variable = itersorted(data, key = lambda x: x[0])
|
||||
|
||||
print control[:10] == [x for x in islice(variable,10)]
|
||||
print data
|
||||
print control
|
||||
|
||||
variable = itersorted(data, key = lambda x: x[0])
|
||||
print [x for x in islice(variable,10)]
|
||||
|
||||
from unittest import TestCase, main
|
||||
from random import shuffle
|
||||
from itertools import islice
|
||||
|
||||
class LazySortTest(TestCase):
|
||||
"""
|
||||
Run these tests with:
|
||||
> python LazySort.py
|
||||
"""
|
||||
|
||||
TESTLEN = 10
|
||||
RANGELEN = max(TESTLEN, 10)
|
||||
|
||||
a = range(RANGELEN/2)*2
|
||||
b = range(RANGELEN/2)*2
|
||||
shuffle(a)
|
||||
shuffle(b)
|
||||
DATA = zip(a,b)
|
||||
shuffle(DATA)
|
||||
del a
|
||||
del b
|
||||
|
||||
def testRange(self):
|
||||
control = sorted(self.DATA)
|
||||
variable = itersorted(self.DATA)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeCompare(self):
|
||||
control = sorted(self.DATA, cmp = lambda a,b: -cmp(a,b))
|
||||
variable = itersorted(self.DATA, cmp = lambda a,b: -cmp(a,b))
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeKey(self):
|
||||
control = sorted(self.DATA, key = lambda x: x[0])
|
||||
variable = itersorted(self.DATA, key = lambda x: x[0])
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeReverse(self):
|
||||
control = sorted(self.DATA, reverse = True)
|
||||
variable = itersorted(self.DATA, reverse = True)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeCompareKey(self):
|
||||
control = sorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
key = lambda x: x[0])
|
||||
variable = itersorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
key = lambda x: x[0])
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeCompareReverse(self):
|
||||
control = sorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
reverse = True)
|
||||
variable = itersorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
reverse = True)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeKeyReverse(self):
|
||||
control = sorted(self.DATA, key = lambda x: x[0], reverse = True)
|
||||
variable = itersorted(self.DATA, key = lambda x: x[0], reverse = True)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
control = sorted(self.DATA, key = lambda x: x[1], reverse = True)
|
||||
variable = itersorted(self.DATA, key = lambda x: x[1], reverse = True)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
def testRangeCompareKeyReverse(self):
|
||||
control = sorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
key = lambda x: x[0],
|
||||
reverse = True)
|
||||
variable = itersorted(self.DATA, cmp = lambda a,b: -cmp(a,b),
|
||||
key = lambda x: x[0],
|
||||
reverse = True)
|
||||
self.assertEqual(control[:10], [x for x in islice(variable, self.TESTLEN)])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main() # unittest.main
|
||||
|
@ -1303,7 +1303,7 @@ class Enum:
|
||||
_checkValidIdentifier = staticmethod(_checkValidIdentifier)
|
||||
|
||||
def __init__(self, items, start=0):
|
||||
if type(items) == types.StringType:
|
||||
if isinstance(items, str):
|
||||
items = items.split(',')
|
||||
|
||||
self._stringTable = {}
|
||||
|
@ -1641,6 +1641,7 @@ class ShowBase(DirectObject.DirectObject):
|
||||
|
||||
def addAngularIntegrator(self):
|
||||
if not self.physicsMgrAngular:
|
||||
from panda3d.physics import AngularEulerIntegrator
|
||||
self.physicsMgrAngular = 1
|
||||
integrator = AngularEulerIntegrator()
|
||||
self.physicsMgr.attachAngularIntegrator(integrator)
|
||||
|
@ -9,9 +9,11 @@ class ThreeUpShow(ShowBase.ShowBase):
|
||||
def __init__(self):
|
||||
ShowBase.ShowBase.__init__(self)
|
||||
|
||||
def makeCamera(self, win, chan = None, layer = None, layerSort = 0,
|
||||
scene = None,
|
||||
displayRegion = (0, 1, 0, 1), aspectRatio = None):
|
||||
def makeCamera(self, win, sort = 0, scene = None,
|
||||
displayRegion = (0, 1, 0, 1), stereo = None,
|
||||
aspectRatio = None, clearDepth = 0, clearColor = None,
|
||||
lens = None, camName = 'cam', mask = None,
|
||||
useCamera = None):
|
||||
self.camRS=ShowBase.ShowBase.makeCamera(
|
||||
self, win, displayRegion = (.5, 1, 0, 1), aspectRatio=.67, camName='camRS')
|
||||
self.camLL=ShowBase.ShowBase.makeCamera(
|
||||
|
@ -3,7 +3,7 @@
|
||||
__all__ = []
|
||||
|
||||
from direct.task.TaskManagerGlobal import *
|
||||
import direct.task.Task
|
||||
from direct.task import Task
|
||||
import random
|
||||
|
||||
numTasks = 10000
|
||||
|
@ -11,11 +11,12 @@ from direct.tkwidgets import Dial
|
||||
from direct.tkwidgets import Floater
|
||||
from direct.tkwidgets import Slider
|
||||
from direct.tkwidgets import VectorWidgets
|
||||
from direct.tkpanels import Placer
|
||||
from direct.particles import ForceGroup
|
||||
from direct.particles import Particles
|
||||
from direct.particles import ParticleEffect
|
||||
from Tkinter import *
|
||||
import Pmw, os,Placer
|
||||
import Pmw, os
|
||||
|
||||
from panda3d.core import *
|
||||
from panda3d.physics import *
|
||||
@ -2789,4 +2790,4 @@ if __name__ == '__main__':
|
||||
base.pp=pp
|
||||
#ve = VectorEntry(Toplevel(), relief = GROOVE)
|
||||
#ve.pack()
|
||||
run()
|
||||
base.run()
|
||||
|
@ -15,7 +15,10 @@ class MemoryExplorer(Pmw.MegaWidget, DirectObject):
|
||||
#--------------------------------------------------------------------------
|
||||
# Init
|
||||
#--------------------------------------------------------------------------
|
||||
def __init__(self, parent = None, nodePath = render, **kw):
|
||||
def __init__(self, parent = None, nodePath = None, **kw):
|
||||
if nodePath is None:
|
||||
nodePath = render
|
||||
|
||||
optiondefs = (('menuItems', [], Pmw.INITOPT),)
|
||||
self.defineoptions(kw, optiondefs)
|
||||
Pmw.MegaWidget.__init__(self, parent)
|
||||
|
@ -27,7 +27,10 @@ DEFAULT_MENU_ITEMS = [
|
||||
|
||||
class SceneGraphExplorer(Pmw.MegaWidget, DirectObject):
|
||||
"Graphical display of a scene graph"
|
||||
def __init__(self, parent = None, nodePath = render, isItemEditable = True, **kw):
|
||||
def __init__(self, parent = None, nodePath = None, isItemEditable = True, **kw):
|
||||
if nodePath is None:
|
||||
nodePath = base.render
|
||||
|
||||
# Define the megawidget options.
|
||||
optiondefs = (
|
||||
('menuItems', [], Pmw.INITOPT),
|
||||
@ -188,7 +191,10 @@ class SceneGraphExplorerItem(TreeItem):
|
||||
messenger.send('SGE_' + command, [self.nodePath])
|
||||
|
||||
|
||||
def explore(nodePath = render):
|
||||
def explore(nodePath = None):
|
||||
if nodePath is None:
|
||||
nodePath = base.render
|
||||
|
||||
tl = Toplevel()
|
||||
tl.title('Explore: ' + nodePath.getName())
|
||||
sge = SceneGraphExplorer(parent = tl, nodePath = nodePath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user