ShowBase: None comparison cleanup

This commit is contained in:
rdb 2020-07-25 12:49:58 +02:00
parent 43b5345588
commit 52127f6805

View File

@ -629,7 +629,7 @@ class ShowBase(DirectObject.DirectObject):
Creates the default GraphicsPipe, which will be used to make Creates the default GraphicsPipe, which will be used to make
windows unless otherwise specified. windows unless otherwise specified.
""" """
assert self.pipe == None assert self.pipe is None
if printPipeTypes is None: if printPipeTypes is None:
# When the user didn't specify an explicit setting, take the value # When the user didn't specify an explicit setting, take the value
@ -672,7 +672,7 @@ class ShowBase(DirectObject.DirectObject):
selection.loadAuxModules() selection.loadAuxModules()
# First, we should make sure the default pipe exists. # First, we should make sure the default pipe exists.
if self.pipe == None: if self.pipe is None:
self.makeDefaultPipe() self.makeDefaultPipe()
# Now go through the list of known pipes, and make each one if # Now go through the list of known pipes, and make each one if
@ -765,33 +765,33 @@ class ShowBase(DirectObject.DirectObject):
# Give the window a chance to truly open. # Give the window a chance to truly open.
self.graphicsEngine.openWindows() self.graphicsEngine.openWindows()
if win != None and not win.isValid(): if win is not None and not win.isValid():
self.notify.info("Window did not open, removing.") self.notify.info("Window did not open, removing.")
self.closeWindow(win) self.closeWindow(win)
win = None win = None
if win == None and pipe == None: if win is None and pipe is None:
# Try a little harder if the window wouldn't open. # Try a little harder if the window wouldn't open.
self.makeAllPipes() self.makeAllPipes()
try: try:
self.pipeList.remove(self.pipe) self.pipeList.remove(self.pipe)
except ValueError: except ValueError:
pass pass
while self.win == None and self.pipeList: while self.win is None and self.pipeList:
self.pipe = self.pipeList[0] self.pipe = self.pipeList[0]
self.notify.info("Trying pipe type %s (%s)" % ( self.notify.info("Trying pipe type %s (%s)" % (
self.pipe.getType(), self.pipe.getInterfaceName())) self.pipe.getType(), self.pipe.getInterfaceName()))
win = func() win = func()
self.graphicsEngine.openWindows() self.graphicsEngine.openWindows()
if win != None and not win.isValid(): if win is not None and not win.isValid():
self.notify.info("Window did not open, removing.") self.notify.info("Window did not open, removing.")
self.closeWindow(win) self.closeWindow(win)
win = None win = None
if win == None: if win is None:
self.pipeList.remove(self.pipe) self.pipeList.remove(self.pipe)
if win == None: if win is None:
self.notify.warning("Unable to open '%s' window." % (type)) self.notify.warning("Unable to open '%s' window." % (type))
if requireWindow: if requireWindow:
# Unless require-window is set to false, it is an # Unless require-window is set to false, it is an
@ -809,14 +809,14 @@ class ShowBase(DirectObject.DirectObject):
makeCamera = True, keepCamera = False, makeCamera = True, keepCamera = False,
scene = None, stereo = None, unexposedDraw = None, scene = None, stereo = None, unexposedDraw = None,
callbackWindowDict = None): callbackWindowDict = None):
if pipe == None: if pipe is None:
pipe = self.pipe pipe = self.pipe
if pipe == None: if pipe is None:
self.makeDefaultPipe() self.makeDefaultPipe()
pipe = self.pipe pipe = self.pipe
if pipe == None: if pipe is None:
# We couldn't get a pipe. # We couldn't get a pipe.
return None return None
@ -834,22 +834,22 @@ class ShowBase(DirectObject.DirectObject):
if pipe.getType().getName().startswith('wdx'): if pipe.getType().getName().startswith('wdx'):
gsg = None gsg = None
if type == None: if type is None:
type = self.windowType type = self.windowType
if props == None: if props is None:
props = WindowProperties.getDefault() props = WindowProperties.getDefault()
if fbprops == None: if fbprops is None:
fbprops = FrameBufferProperties.getDefault() fbprops = FrameBufferProperties.getDefault()
if size != None: if size is not None:
# If we were given an explicit size, use it; otherwise, # If we were given an explicit size, use it; otherwise,
# the size from the properties is used. # the size from the properties is used.
props = WindowProperties(props) props = WindowProperties(props)
props.setSize(size[0], size[1]) props.setSize(size[0], size[1])
if name == None: if name is None:
name = 'window%s' % (self.nextWindowIndex) name = 'window%s' % (self.nextWindowIndex)
self.nextWindowIndex += 1 self.nextWindowIndex += 1
@ -875,7 +875,7 @@ class ShowBase(DirectObject.DirectObject):
win = self.graphicsEngine.makeOutput(pipe, name, 0, fbprops, win = self.graphicsEngine.makeOutput(pipe, name, 0, fbprops,
props, flags) props, flags)
if win == None: if win is None:
# Couldn't create a window! # Couldn't create a window!
return None return None
@ -1021,7 +1021,7 @@ class ShowBase(DirectObject.DirectObject):
if startDirect: if startDirect:
self.__doStartDirect() self.__doStartDirect()
return self.win != None return self.win is not None
def openMainWindow(self, *args, **kw): def openMainWindow(self, *args, **kw):
""" """
@ -1040,7 +1040,7 @@ class ShowBase(DirectObject.DirectObject):
oldWin = self.win oldWin = self.win
oldLens = self.camLens oldLens = self.camLens
oldClearColorActive = None oldClearColorActive = None
if self.win != None: if self.win is not None:
# Close the previous window. # Close the previous window.
oldClearColorActive = self.win.getClearColorActive() oldClearColorActive = self.win.getClearColorActive()
oldClearColor = VBase4(self.win.getClearColor()) oldClearColor = VBase4(self.win.getClearColor())
@ -1052,12 +1052,12 @@ class ShowBase(DirectObject.DirectObject):
# Open a new window. # Open a new window.
self.openWindow(*args, **kw) self.openWindow(*args, **kw)
if self.win == None: if self.win is None:
self.win = oldWin self.win = oldWin
self.winList.append(oldWin) self.winList.append(oldWin)
success = 0 success = 0
if self.win != None: if self.win is not None:
if isinstance(self.win, GraphicsWindow): if isinstance(self.win, GraphicsWindow):
self.setupMouse(self.win) self.setupMouse(self.win)
self.makeCamera2d(self.win) self.makeCamera2d(self.win)
@ -1065,12 +1065,12 @@ class ShowBase(DirectObject.DirectObject):
if self.wantRender2dp: if self.wantRender2dp:
self.makeCamera2dp(self.win) self.makeCamera2dp(self.win)
if oldLens != None: if oldLens is not None:
# Restore the previous lens properties. # Restore the previous lens properties.
self.camNode.setLens(oldLens) self.camNode.setLens(oldLens)
self.camLens = oldLens self.camLens = oldLens
if oldClearColorActive != None: if oldClearColorActive is not None:
# Restore the previous clear properties. # Restore the previous clear properties.
self.win.setClearColorActive(oldClearColorActive) self.win.setClearColorActive(oldClearColorActive)
self.win.setClearColor(oldClearColor) self.win.setClearColor(oldClearColor)
@ -1353,13 +1353,13 @@ class ShowBase(DirectObject.DirectObject):
aspectRatio = 1 aspectRatio = 1
if win == None: if win is None:
win = self.win win = self.win
if win != None and win.hasSize() and win.getSbsLeftYSize() != 0: if win is not None and win.hasSize() and win.getSbsLeftYSize() != 0:
aspectRatio = float(win.getSbsLeftXSize()) / float(win.getSbsLeftYSize()) aspectRatio = float(win.getSbsLeftXSize()) / float(win.getSbsLeftYSize())
else: else:
if win == None or not hasattr(win, "getRequestedProperties"): if win is None or not hasattr(win, "getRequestedProperties"):
props = WindowProperties.getDefault() props = WindowProperties.getDefault()
else: else:
props = win.getRequestedProperties() props = win.getRequestedProperties()
@ -1380,13 +1380,13 @@ class ShowBase(DirectObject.DirectObject):
default size if there is not yet a main window. default size if there is not yet a main window.
""" """
if win == None: if win is None:
win = self.win win = self.win
if win != None and win.hasSize(): if win is not None and win.hasSize():
return win.getXSize(), win.getYSize() return win.getXSize(), win.getYSize()
else: else:
if win == None or not hasattr(win, "getRequestedProperties"): if win is None or not hasattr(win, "getRequestedProperties"):
props = WindowProperties.getDefault() props = WindowProperties.getDefault()
else: else:
props = win.getRequestedProperties() props = win.getRequestedProperties()
@ -1417,7 +1417,7 @@ class ShowBase(DirectObject.DirectObject):
""" """
# self.camera is the parent node of all cameras: a node that # self.camera is the parent node of all cameras: a node that
# we can move around to move all cameras as a group. # we can move around to move all cameras as a group.
if self.camera == None: if self.camera is None:
# We make it a ModelNode with the PTLocal flag, so that # We make it a ModelNode with the PTLocal flag, so that
# a wayward flatten operations won't attempt to mangle the # a wayward flatten operations won't attempt to mangle the
# camera. # camera.
@ -1438,27 +1438,27 @@ class ShowBase(DirectObject.DirectObject):
else: else:
# Make a new Camera node. # Make a new Camera node.
camNode = Camera(camName) camNode = Camera(camName)
if lens == None: if lens is None:
lens = PerspectiveLens() lens = PerspectiveLens()
if aspectRatio == None: if aspectRatio is None:
aspectRatio = self.getAspectRatio(win) aspectRatio = self.getAspectRatio(win)
lens.setAspectRatio(aspectRatio) lens.setAspectRatio(aspectRatio)
cam = self.camera.attachNewNode(camNode) cam = self.camera.attachNewNode(camNode)
if lens != None: if lens is not None:
camNode.setLens(lens) camNode.setLens(lens)
if scene != None: if scene is not None:
camNode.setScene(scene) camNode.setScene(scene)
if mask != None: if mask is not None:
if (isinstance(mask, int)): if (isinstance(mask, int)):
mask = BitMask32(mask) mask = BitMask32(mask)
camNode.setCameraMask(mask) camNode.setCameraMask(mask)
if self.cam == None: if self.cam is None:
self.cam = cam self.cam = cam
self.camNode = camNode self.camNode = camNode
self.camLens = lens self.camLens = lens
@ -1517,7 +1517,7 @@ class ShowBase(DirectObject.DirectObject):
else: else:
cam2dNode = Camera('cam2d') cam2dNode = Camera('cam2d')
if lens == None: if lens is None:
lens = OrthographicLens() lens = OrthographicLens()
lens.setFilmSize(right - left, top - bottom) lens.setFilmSize(right - left, top - bottom)
lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5) lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5)
@ -1526,13 +1526,13 @@ class ShowBase(DirectObject.DirectObject):
# self.camera2d is the analog of self.camera, although it's # self.camera2d is the analog of self.camera, although it's
# not as clear how useful it is. # not as clear how useful it is.
if self.camera2d == None: if self.camera2d is None:
self.camera2d = self.render2d.attachNewNode('camera2d') self.camera2d = self.render2d.attachNewNode('camera2d')
camera2d = self.camera2d.attachNewNode(cam2dNode) camera2d = self.camera2d.attachNewNode(cam2dNode)
dr.setCamera(camera2d) dr.setCamera(camera2d)
if self.cam2d == None: if self.cam2d is None:
self.cam2d = camera2d self.cam2d = camera2d
return camera2d return camera2d
@ -1563,7 +1563,7 @@ class ShowBase(DirectObject.DirectObject):
else: else:
cam2dNode = Camera('cam2dp') cam2dNode = Camera('cam2dp')
if lens == None: if lens is None:
lens = OrthographicLens() lens = OrthographicLens()
lens.setFilmSize(right - left, top - bottom) lens.setFilmSize(right - left, top - bottom)
lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5) lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5)
@ -1572,18 +1572,17 @@ class ShowBase(DirectObject.DirectObject):
# self.camera2d is the analog of self.camera, although it's # self.camera2d is the analog of self.camera, although it's
# not as clear how useful it is. # not as clear how useful it is.
if self.camera2dp == None: if self.camera2dp is None:
self.camera2dp = self.render2dp.attachNewNode('camera2dp') self.camera2dp = self.render2dp.attachNewNode('camera2dp')
camera2dp = self.camera2dp.attachNewNode(cam2dNode) camera2dp = self.camera2dp.attachNewNode(cam2dNode)
dr.setCamera(camera2dp) dr.setCamera(camera2dp)
if self.cam2dp == None: if self.cam2dp is None:
self.cam2dp = camera2dp self.cam2dp = camera2dp
return camera2dp return camera2dp
def setupDataGraph(self): def setupDataGraph(self):
""" """
Creates the data graph and populates it with the basic input Creates the data graph and populates it with the basic input
@ -1615,7 +1614,7 @@ class ShowBase(DirectObject.DirectObject):
:returns: The ButtonThrower NodePath created for this window. :returns: The ButtonThrower NodePath created for this window.
""" """
if not fMultiWin and self.buttonThrowers != None: if not fMultiWin and self.buttonThrowers is not None:
for bt in self.buttonThrowers: for bt in self.buttonThrowers:
mw = bt.getParent() mw = bt.getParent()
mk = mw.getParent() mk = mw.getParent()
@ -1958,8 +1957,8 @@ class ShowBase(DirectObject.DirectObject):
self.addSfxManager(sfxManager) self.addSfxManager(sfxManager)
self.musicManager = AudioManager.createAudioManager() self.musicManager = AudioManager.createAudioManager()
self.musicManagerIsValid=self.musicManager!=None \ self.musicManagerIsValid = self.musicManager is not None \
and self.musicManager.isValid() and self.musicManager.isValid()
if self.musicManagerIsValid: if self.musicManagerIsValid:
# ensure only 1 midi song is playing at a time: # ensure only 1 midi song is playing at a time:
self.musicManager.setConcurrentSoundLimit(1) self.musicManager.setConcurrentSoundLimit(1)
@ -2060,7 +2059,7 @@ class ShowBase(DirectObject.DirectObject):
def playMusic(self, music, looping = 0, interrupt = 1, volume = None, time = 0.0): def playMusic(self, music, looping = 0, interrupt = 1, volume = None, time = 0.0):
if music: if music:
if volume != None: if volume is not None:
music.setVolume(volume) music.setVolume(volume)
# if interrupt was set to 0, start over even if it's # if interrupt was set to 0, start over even if it's
@ -2122,7 +2121,7 @@ class ShowBase(DirectObject.DirectObject):
return Task.cont return Task.cont
def __audioLoop(self, state): def __audioLoop(self, state):
if (self.musicManager != None): if self.musicManager is not None:
self.musicManager.update() self.musicManager.update()
for x in self.sfxManagerList: for x in self.sfxManagerList:
x.update() x.update()
@ -2247,7 +2246,7 @@ class ShowBase(DirectObject.DirectObject):
# give the igLoop task a reasonably "late" sort, # give the igLoop task a reasonably "late" sort,
# so that it will get run after most tasks # so that it will get run after most tasks
self.cluster = cluster self.cluster = cluster
if (not clusterSync or (cluster == None)): if not clusterSync or cluster is None:
self.taskMgr.add(self.__igLoop, 'igLoop', sort = 50) self.taskMgr.add(self.__igLoop, 'igLoop', sort = 50)
else: else:
self.taskMgr.add(self.__igLoopSync, 'igLoop', sort = 50) self.taskMgr.add(self.__igLoopSync, 'igLoop', sort = 50)
@ -2275,7 +2274,7 @@ class ShowBase(DirectObject.DirectObject):
:rtype: panda3d.core.VBase4 :rtype: panda3d.core.VBase4
""" """
if win == None: if win is None:
win = self.win win = self.win
return VBase4(win.getClearColor()) return VBase4(win.getClearColor())
@ -2289,7 +2288,7 @@ class ShowBase(DirectObject.DirectObject):
The color may be either a VBase3 or a VBase4, or a 3-component The color may be either a VBase3 or a VBase4, or a 3-component
tuple, or the individual r, g, b parameters. tuple, or the individual r, g, b parameters.
""" """
if g != None: if g is not None:
color = VBase4(r, g, b, a) color = VBase4(r, g, b, a)
else: else:
arg = r arg = r
@ -2298,11 +2297,11 @@ class ShowBase(DirectObject.DirectObject):
else: else:
color = VBase4(arg[0], arg[1], arg[2], a) color = VBase4(arg[0], arg[1], arg[2], a)
if win == None: if win is None:
win = self.win win = self.win
if win: if win:
win.setClearColor(color) win.setClearColor(color)
def toggleBackface(self): def toggleBackface(self):
""" """
@ -2582,7 +2581,7 @@ class ShowBase(DirectObject.DirectObject):
if self.oobeMode: if self.oobeMode:
# Disable OOBE mode. # Disable OOBE mode.
if self.oobeCullFrustum != None: if self.oobeCullFrustum is not None:
# First, disable OOBE cull mode. # First, disable OOBE cull mode.
self.oobeCull(cam = cam) self.oobeCull(cam = cam)
@ -2668,7 +2667,7 @@ class ShowBase(DirectObject.DirectObject):
if not getattr(self, 'oobeMode', False): if not getattr(self, 'oobeMode', False):
self.oobe(cam = cam) self.oobe(cam = cam)
if self.oobeCullFrustum == None: if self.oobeCullFrustum is None:
# Enable OOBE culling. # Enable OOBE culling.
pnode = LensNode('oobeCull') pnode = LensNode('oobeCull')
pnode.setLens(self.camLens) pnode.setLens(self.camLens)
@ -2699,7 +2698,7 @@ class ShowBase(DirectObject.DirectObject):
# Create a visible representation of the frustum. # Create a visible representation of the frustum.
self.removeCameraFrustum() self.removeCameraFrustum()
geom = self.camLens.makeGeometry() geom = self.camLens.makeGeometry()
if geom != None: if geom is not None:
gn = GeomNode('frustum') gn = GeomNode('frustum')
gn.addGeom(geom) gn.addGeom(geom)
self.camFrustumVis = self.camera.attachNewNode(gn) self.camFrustumVis = self.camera.attachNewNode(gn)
@ -2735,7 +2734,7 @@ class ShowBase(DirectObject.DirectObject):
:returns: The filename if successful, or None if there is a problem. :returns: The filename if successful, or None if there is a problem.
""" """
if source == None: if source is None:
source = self.win source = self.win
if defaultFilename: if defaultFilename:
@ -2780,16 +2779,16 @@ class ShowBase(DirectObject.DirectObject):
:returns: The filename if successful, or None if there is a problem. :returns: The filename if successful, or None if there is a problem.
""" """
if source == None: if source is None:
source = self.win source = self.win
if camera == None: if camera is None:
if hasattr(source, "getCamera"): if hasattr(source, "getCamera"):
camera = source.getCamera() camera = source.getCamera()
if camera == None: if camera is None:
camera = self.camera camera = self.camera
if sourceLens == None: if sourceLens is None:
sourceLens = self.camLens sourceLens = self.camLens
if hasattr(source, "getWindow"): if hasattr(source, "getWindow"):
@ -2797,7 +2796,7 @@ class ShowBase(DirectObject.DirectObject):
rig = NodePath(namePrefix) rig = NodePath(namePrefix)
buffer = source.makeCubeMap(namePrefix, size, rig, cameraMask, 1) buffer = source.makeCubeMap(namePrefix, size, rig, cameraMask, 1)
if buffer == None: if buffer is None:
raise Exception("Could not make cube map.") raise Exception("Could not make cube map.")
# Set the near and far planes from the default lens. # Set the near and far planes from the default lens.
@ -2841,16 +2840,16 @@ class ShowBase(DirectObject.DirectObject):
:returns: The filename if successful, or None if there is a problem. :returns: The filename if successful, or None if there is a problem.
""" """
if source == None: if source is None:
source = self.win source = self.win
if camera == None: if camera is None:
if hasattr(source, "getCamera"): if hasattr(source, "getCamera"):
camera = source.getCamera() camera = source.getCamera()
if camera == None: if camera is None:
camera = self.camera camera = self.camera
if sourceLens == None: if sourceLens is None:
sourceLens = self.camLens sourceLens = self.camLens
if hasattr(source, "getWindow"): if hasattr(source, "getWindow"):
@ -2865,7 +2864,7 @@ class ShowBase(DirectObject.DirectObject):
# Now make the cube map buffer. # Now make the cube map buffer.
rig = NodePath(namePrefix) rig = NodePath(namePrefix)
buffer = toSphere.makeCubeMap(namePrefix, size, rig, cameraMask, 0) buffer = toSphere.makeCubeMap(namePrefix, size, rig, cameraMask, 0)
if buffer == None: if buffer is None:
self.graphicsEngine.removeWindow(toSphere) self.graphicsEngine.removeWindow(toSphere)
raise Exception("Could not make cube map.") raise Exception("Could not make cube map.")