Browse Source

showbase: Annotate callback methods

WMOkiishi 11 months ago
parent
commit
b0e1e0c75a
1 changed files with 23 additions and 19 deletions
  1. 23 19
      direct/src/showbase/ShowBase.py

+ 23 - 19
direct/src/showbase/ShowBase.py

@@ -177,6 +177,8 @@ class ShowBase(DirectObject.DirectObject):
     aspect2d: NodePath
     aspect2d: NodePath
     pixel2d: NodePath
     pixel2d: NodePath
 
 
+    cluster: Any | None
+
     def __init__(self, fStartDirect: bool = True, windowType: str | None = None) -> None:
     def __init__(self, fStartDirect: bool = True, windowType: str | None = None) -> None:
         """Opens a window, sets up a 3-D and several 2-D scene graphs, and
         """Opens a window, sets up a 3-D and several 2-D scene graphs, and
         everything else needed to render the scene graph to the window.
         everything else needed to render the scene graph to the window.
@@ -1208,7 +1210,7 @@ class ShowBase(DirectObject.DirectObject):
             self.taskMgr.remove('clientSleep')
             self.taskMgr.remove('clientSleep')
             self.taskMgr.add(self.__sleepCycleTask, 'clientSleep', sort = 55)
             self.taskMgr.add(self.__sleepCycleTask, 'clientSleep', sort = 55)
 
 
-    def __sleepCycleTask(self, task):
+    def __sleepCycleTask(self, task: object) -> int:
         Thread.sleep(self.clientSleep)
         Thread.sleep(self.clientSleep)
         #time.sleep(self.clientSleep)
         #time.sleep(self.clientSleep)
         return Task.cont
         return Task.cont
@@ -1444,7 +1446,7 @@ class ShowBase(DirectObject.DirectObject):
         self.__configAspectRatio = aspectRatio
         self.__configAspectRatio = aspectRatio
         self.adjustWindowAspectRatio(self.getAspectRatio())
         self.adjustWindowAspectRatio(self.getAspectRatio())
 
 
-    def getAspectRatio(self, win = None):
+    def getAspectRatio(self, win: GraphicsOutput | None = None) -> float:
         # Returns the actual aspect ratio of the indicated (or main
         # Returns the actual aspect ratio of the indicated (or main
         # window), or the default aspect ratio if there is not yet a
         # window), or the default aspect ratio if there is not yet a
         # main window.
         # main window.
@@ -1453,7 +1455,7 @@ class ShowBase(DirectObject.DirectObject):
         if self.__configAspectRatio:
         if self.__configAspectRatio:
             return self.__configAspectRatio
             return self.__configAspectRatio
 
 
-        aspectRatio = 1
+        aspectRatio: float = 1
 
 
         if win is None:
         if win is None:
             win = self.win
             win = self.win
@@ -1476,7 +1478,7 @@ class ShowBase(DirectObject.DirectObject):
 
 
         return aspectRatio
         return aspectRatio
 
 
-    def getSize(self, win = None):
+    def getSize(self, win: GraphicsOutput | None = None) -> tuple[int, int]:
         """
         """
         Returns the actual size of the indicated (or main window), or the
         Returns the actual size of the indicated (or main window), or the
         default size if there is not yet a main window.
         default size if there is not yet a main window.
@@ -2176,7 +2178,7 @@ class ShowBase(DirectObject.DirectObject):
                 music.setLoop(looping)
                 music.setLoop(looping)
                 music.play()
                 music.play()
 
 
-    def __resetPrevTransform(self, state):
+    def __resetPrevTransform(self, state: object) -> int:
         # Clear out the previous velocity deltas now, after we have
         # Clear out the previous velocity deltas now, after we have
         # rendered (the previous frame).  We do this after the render,
         # rendered (the previous frame).  We do this after the render,
         # so that we have a chance to draw a representation of spheres
         # so that we have a chance to draw a representation of spheres
@@ -2187,7 +2189,7 @@ class ShowBase(DirectObject.DirectObject):
         PandaNode.resetAllPrevTransform()
         PandaNode.resetAllPrevTransform()
         return Task.cont
         return Task.cont
 
 
-    def __dataLoop(self, state):
+    def __dataLoop(self, state: object) -> int:
         # Check if there were newly connected devices.
         # Check if there were newly connected devices.
         self.devices.update()
         self.devices.update()
 
 
@@ -2197,7 +2199,7 @@ class ShowBase(DirectObject.DirectObject):
         self.dgTrav.traverse(self.dataRootNode)
         self.dgTrav.traverse(self.dataRootNode)
         return Task.cont
         return Task.cont
 
 
-    def __ivalLoop(self, state):
+    def __ivalLoop(self, state: object) -> int:
         # Execute all intervals in the global ivalMgr.
         # Execute all intervals in the global ivalMgr.
         IntervalManager.ivalMgr.step()
         IntervalManager.ivalMgr.step()
         return Task.cont
         return Task.cont
@@ -2215,7 +2217,7 @@ class ShowBase(DirectObject.DirectObject):
             self.shadowTrav.traverse(self.render)
             self.shadowTrav.traverse(self.render)
         return Task.cont
         return Task.cont
 
 
-    def __collisionLoop(self, state):
+    def __collisionLoop(self, state: object) -> int:
         # run the collision traversal if we have a
         # run the collision traversal if we have a
         # CollisionTraverser set.
         # CollisionTraverser set.
         if self.cTrav:
         if self.cTrav:
@@ -2227,14 +2229,14 @@ class ShowBase(DirectObject.DirectObject):
         messenger.send("collisionLoopFinished")
         messenger.send("collisionLoopFinished")
         return Task.cont
         return Task.cont
 
 
-    def __audioLoop(self, state):
+    def __audioLoop(self, state: object) -> int:
         if self.musicManager is not 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()
         return Task.cont
         return Task.cont
 
 
-    def __garbageCollectStates(self, state):
+    def __garbageCollectStates(self, state: object) -> int:
         """ This task is started only when we have
         """ This task is started only when we have
         garbage-collect-states set in the Config.prc file, in which
         garbage-collect-states set in the Config.prc file, in which
         case we're responsible for taking out Panda's garbage from
         case we're responsible for taking out Panda's garbage from
@@ -2245,7 +2247,7 @@ class ShowBase(DirectObject.DirectObject):
         RenderState.garbageCollect()
         RenderState.garbageCollect()
         return Task.cont
         return Task.cont
 
 
-    def __igLoop(self, state):
+    def __igLoop(self, state: object) -> int:
         if __debug__:
         if __debug__:
             # We render the watch variables for the onScreenDebug as soon
             # We render the watch variables for the onScreenDebug as soon
             # as we reasonably can before the renderFrame().
             # as we reasonably can before the renderFrame().
@@ -2285,7 +2287,7 @@ class ShowBase(DirectObject.DirectObject):
         throw_new_frame()
         throw_new_frame()
         return Task.cont
         return Task.cont
 
 
-    def __igLoopSync(self, state):
+    def __igLoopSync(self, state: object) -> int:
         if __debug__:
         if __debug__:
             # We render the watch variables for the onScreenDebug as soon
             # We render the watch variables for the onScreenDebug as soon
             # as we reasonably can before the renderFrame().
             # as we reasonably can before the renderFrame().
@@ -2294,6 +2296,7 @@ class ShowBase(DirectObject.DirectObject):
         if self.recorder:
         if self.recorder:
             self.recorder.recordFrame()
             self.recorder.recordFrame()
 
 
+        assert self.cluster is not None
         self.cluster.collectData()
         self.cluster.collectData()
 
 
         # Finally, render the frame.
         # Finally, render the frame.
@@ -2323,6 +2326,7 @@ class ShowBase(DirectObject.DirectObject):
             time.sleep(0.1)
             time.sleep(0.1)
 
 
         self.graphicsEngine.readyFlip()
         self.graphicsEngine.readyFlip()
+        assert self.cluster is not None
         self.cluster.waitForFlipCommand()
         self.cluster.waitForFlipCommand()
         self.graphicsEngine.flipFrame()
         self.graphicsEngine.flipFrame()
 
 
@@ -2753,7 +2757,7 @@ class ShowBase(DirectObject.DirectObject):
                 self.oobeVis.reparentTo(self.camera)
                 self.oobeVis.reparentTo(self.camera)
             self.oobeMode = 1
             self.oobeMode = 1
 
 
-    def __oobeButton(self, suffix, button):
+    def __oobeButton(self, suffix: str, button: str) -> None:
         if button.startswith('mouse'):
         if button.startswith('mouse'):
             # Eat mouse buttons.
             # Eat mouse buttons.
             return
             return
@@ -3073,7 +3077,7 @@ class ShowBase(DirectObject.DirectObject):
         else:
         else:
             return Task.cont
             return Task.cont
 
 
-    def windowEvent(self, win):
+    def windowEvent(self, win: GraphicsOutput) -> None:
         if win != self.win:
         if win != self.win:
             # This event isn't about our window.
             # This event isn't about our window.
             return
             return
@@ -3092,9 +3096,9 @@ class ShowBase(DirectObject.DirectObject):
                 self.userExit()
                 self.userExit()
 
 
             if properties.getForeground() and not self.mainWinForeground:
             if properties.getForeground() and not self.mainWinForeground:
-                self.mainWinForeground = 1
+                self.mainWinForeground = True
             elif not properties.getForeground() and self.mainWinForeground:
             elif not properties.getForeground() and self.mainWinForeground:
-                self.mainWinForeground = 0
+                self.mainWinForeground = False
                 if __debug__:
                 if __debug__:
                     if self.__autoGarbageLogging:
                     if self.__autoGarbageLogging:
                         GarbageReport.b_checkForGarbageLeaks()
                         GarbageReport.b_checkForGarbageLeaks()
@@ -3102,12 +3106,12 @@ class ShowBase(DirectObject.DirectObject):
             if properties.getMinimized() and not self.mainWinMinimized:
             if properties.getMinimized() and not self.mainWinMinimized:
                 # If the main window is minimized, throw an event to
                 # If the main window is minimized, throw an event to
                 # stop the music.
                 # stop the music.
-                self.mainWinMinimized = 1
+                self.mainWinMinimized = True
                 messenger.send('PandaPaused')
                 messenger.send('PandaPaused')
             elif not properties.getMinimized() and self.mainWinMinimized:
             elif not properties.getMinimized() and self.mainWinMinimized:
                 # If the main window is restored, throw an event to
                 # If the main window is restored, throw an event to
                 # restart the music.
                 # restart the music.
-                self.mainWinMinimized = 0
+                self.mainWinMinimized = False
                 messenger.send('PandaRestarted')
                 messenger.send('PandaRestarted')
 
 
             # If we have not forced the aspect ratio, let's see if it has
             # If we have not forced the aspect ratio, let's see if it has
@@ -3125,7 +3129,7 @@ class ShowBase(DirectObject.DirectObject):
                     if self.wantRender2dp:
                     if self.wantRender2dp:
                         self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
                         self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
 
 
-    def adjustWindowAspectRatio(self, aspectRatio):
+    def adjustWindowAspectRatio(self, aspectRatio: float) -> None:
         """ This function is normally called internally by
         """ This function is normally called internally by
         `windowEvent()`, but it may also be called to explicitly adjust
         `windowEvent()`, but it may also be called to explicitly adjust
         the aspect ratio of the render/render2d DisplayRegion, by a
         the aspect ratio of the render/render2d DisplayRegion, by a