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