direct: Fix assorted issues when using mypyc

This commit is contained in:
rdb 2023-10-10 12:52:26 +02:00
parent ef25b67ddb
commit f7718b466b
7 changed files with 26 additions and 17 deletions

View File

@ -256,7 +256,7 @@ class Notifier:
the function call (with parameters). the function call (with parameters).
""" """
#f.f_locals['self'].__init__.im_class.__name__ #f.f_locals['self'].__init__.im_class.__name__
if self.__debug: if __debug__ and self.__debug:
state = '' state = ''
doId = '' doId = ''
if obj is not None: if obj is not None:
@ -296,7 +296,7 @@ class Notifier:
call followed by the notifier category and call followed by the notifier category and
the function call (with parameters). the function call (with parameters).
""" """
if self.__debug: if __debug__ and self.__debug:
message = str(debugString) message = str(debugString)
string = ":%s:%s \"%s\" %s"%( string = ":%s:%s \"%s\" %s"%(
self.getOnlyTime(), self.getOnlyTime(),

View File

@ -28,7 +28,7 @@ class DirectEntry(DirectFrame):
to keyboard buttons to keyboard buttons
""" """
directWtext = ConfigVariableBool('direct-wtext', 1) directWtext = ConfigVariableBool('direct-wtext', True)
AllowCapNamePrefixes = ("Al", "Ap", "Ben", "De", "Del", "Della", "Delle", "Der", "Di", "Du", AllowCapNamePrefixes = ("Al", "Ap", "Ben", "De", "Del", "Della", "Delle", "Der", "Di", "Du",
"El", "Fitz", "La", "Las", "Le", "Les", "Lo", "Los", "El", "Fitz", "La", "Las", "Le", "Les", "Lo", "Los",

View File

@ -173,7 +173,7 @@ class OnscreenText(NodePath):
self.__wordwrap = wordwrap self.__wordwrap = wordwrap
if decal: if decal:
textNode.setCardDecal(1) textNode.setCardDecal(True)
if font is None: if font is None:
font = DGG.getDefaultFont() font = DGG.getDefaultFont()

View File

@ -123,6 +123,7 @@ import builtins
builtins.config = DConfig # type: ignore[attr-defined] builtins.config = DConfig # type: ignore[attr-defined]
from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify from direct.directnotify.DirectNotifyGlobal import directNotify, giveNotify
from direct.directnotify.Notifier import Notifier
from .MessengerGlobal import messenger from .MessengerGlobal import messenger
from .BulletinBoardGlobal import bulletinBoard from .BulletinBoardGlobal import bulletinBoard
from direct.task.TaskManagerGlobal import taskMgr from direct.task.TaskManagerGlobal import taskMgr
@ -140,6 +141,7 @@ import importlib
from direct.showbase import ExceptionVarDump from direct.showbase import ExceptionVarDump
from . import DirectObject from . import DirectObject
from . import SfxPlayer from . import SfxPlayer
from typing import ClassVar
if __debug__: if __debug__:
from direct.showbase import GarbageReport from direct.showbase import GarbageReport
from direct.directutil import DeltaProfiler from direct.directutil import DeltaProfiler
@ -160,8 +162,9 @@ def exitfunc():
class ShowBase(DirectObject.DirectObject): class ShowBase(DirectObject.DirectObject):
#: The deprecated `.DConfig` interface for accessing config variables. #: The deprecated `.DConfig` interface for accessing config variables.
config = DConfig config: ClassVar = DConfig
notify = directNotify.newCategory("ShowBase") notify: ClassVar[Notifier] = directNotify.newCategory("ShowBase")
guiItems: ClassVar[dict]
def __init__(self, fStartDirect=True, windowType=None): def __init__(self, fStartDirect=True, windowType=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
@ -337,10 +340,10 @@ class ShowBase(DirectObject.DirectObject):
self.tkRootCreated = False self.tkRootCreated = False
# This is used for syncing multiple PCs in a distributed cluster # This is used for syncing multiple PCs in a distributed cluster
try: if hasattr(builtins, 'clusterSyncFlag'):
# Has the cluster sync variable been set externally? # Has the cluster sync variable been set externally?
self.clusterSyncFlag = clusterSyncFlag self.clusterSyncFlag = builtins.clusterSyncFlag
except NameError: else:
# Has the clusterSyncFlag been set via a config variable # Has the clusterSyncFlag been set via a config variable
self.clusterSyncFlag = ConfigVariableBool('cluster-sync', False) self.clusterSyncFlag = ConfigVariableBool('cluster-sync', False)
@ -712,10 +715,9 @@ class ShowBase(DirectObject.DirectObject):
except Exception: except Exception:
pass pass
if hasattr(self, 'win'): self.win = None
del self.win self.winList.clear()
del self.winList self.pipe = None
del self.pipe
def makeDefaultPipe(self, printPipeTypes = None): def makeDefaultPipe(self, printPipeTypes = None):
""" """
@ -728,7 +730,7 @@ class ShowBase(DirectObject.DirectObject):
# When the user didn't specify an explicit setting, take the value # When the user didn't specify an explicit setting, take the value
# from the config variable. We could just omit the parameter, however # from the config variable. We could just omit the parameter, however
# this way we can keep backward compatibility. # this way we can keep backward compatibility.
printPipeTypes = ConfigVariableBool("print-pipe-types", True) printPipeTypes = ConfigVariableBool("print-pipe-types", True).value
selection = GraphicsPipeSelection.getGlobalPtr() selection = GraphicsPipeSelection.getGlobalPtr()
if printPipeTypes: if printPipeTypes:

View File

@ -21,7 +21,7 @@ from panda3d.core import NodePath, PGTop
from . import DConfig as config # pylint: disable=unused-import from . import DConfig as config # pylint: disable=unused-import
import warnings import warnings
__dev__ = ConfigVariableBool('want-dev', __debug__).value __dev__: bool = ConfigVariableBool('want-dev', __debug__).value
base: ShowBase base: ShowBase

View File

@ -18,7 +18,7 @@ class TexViewer(DirectObject):
# We'll put the full-resolution texture on the left. # We'll put the full-resolution texture on the left.
cm = CardMaker('left') cm = CardMaker('left')
l, r, b, t = (-1, -0.1, 0, 0.9) l, r, b, t = (-1.0, -0.1, 0.0, 0.9)
cm.setFrame(l, r, b, t) cm.setFrame(l, r, b, t)
left = cards.attachNewNode(cm.generate()) left = cards.attachNewNode(cm.generate())
left.setTexture(self.tex) left.setTexture(self.tex)

View File

@ -13,6 +13,7 @@ __all__ = ['Task', 'TaskManager',
from direct.directnotify.DirectNotifyGlobal import directNotify from direct.directnotify.DirectNotifyGlobal import directNotify
from direct.showbase.PythonUtil import Functor, ScratchPad from direct.showbase.PythonUtil import Functor, ScratchPad
from direct.showbase.MessengerGlobal import messenger from direct.showbase.MessengerGlobal import messenger
from typing import Any, Optional
import types import types
import random import random
import importlib import importlib
@ -20,6 +21,7 @@ import sys
# On Android, there's no use handling SIGINT, and in fact we can't, since we # On Android, there's no use handling SIGINT, and in fact we can't, since we
# run the application in a separate thread from the main thread. # run the application in a separate thread from the main thread.
signal: Optional[types.ModuleType]
if hasattr(sys, 'getandroidapilevel'): if hasattr(sys, 'getandroidapilevel'):
signal = None signal = None
else: else:
@ -140,6 +142,8 @@ class TaskManager:
MaxEpochSpeed = 1.0/30.0 MaxEpochSpeed = 1.0/30.0
__prevHandler: Any
def __init__(self): def __init__(self):
self.mgr = AsyncTaskManager.getGlobalPtr() self.mgr = AsyncTaskManager.getGlobalPtr()
@ -183,11 +187,14 @@ class TaskManager:
self._frameProfileQueue.clear() self._frameProfileQueue.clear()
self.mgr.cleanup() self.mgr.cleanup()
def __getClock(self):
return self.mgr.getClock()
def setClock(self, clockObject): def setClock(self, clockObject):
self.mgr.setClock(clockObject) self.mgr.setClock(clockObject)
self.globalClock = clockObject self.globalClock = clockObject
clock = property(lambda self: self.mgr.getClock(), setClock) clock = property(__getClock, setClock)
def invokeDefaultHandler(self, signalNumber, stackFrame): def invokeDefaultHandler(self, signalNumber, stackFrame):
print('*** allowing mid-frame keyboard interrupt.') print('*** allowing mid-frame keyboard interrupt.')