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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,7 @@ class TexViewer(DirectObject):
# We'll put the full-resolution texture on the 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)
left = cards.attachNewNode(cm.generate())
left.setTexture(self.tex)

View File

@ -13,6 +13,7 @@ __all__ = ['Task', 'TaskManager',
from direct.directnotify.DirectNotifyGlobal import directNotify
from direct.showbase.PythonUtil import Functor, ScratchPad
from direct.showbase.MessengerGlobal import messenger
from typing import Any, Optional
import types
import random
import importlib
@ -20,6 +21,7 @@ import sys
# 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.
signal: Optional[types.ModuleType]
if hasattr(sys, 'getandroidapilevel'):
signal = None
else:
@ -140,6 +142,8 @@ class TaskManager:
MaxEpochSpeed = 1.0/30.0
__prevHandler: Any
def __init__(self):
self.mgr = AsyncTaskManager.getGlobalPtr()
@ -183,11 +187,14 @@ class TaskManager:
self._frameProfileQueue.clear()
self.mgr.cleanup()
def __getClock(self):
return self.mgr.getClock()
def setClock(self, clockObject):
self.mgr.setClock(clockObject)
self.globalClock = clockObject
clock = property(lambda self: self.mgr.getClock(), setClock)
clock = property(__getClock, setClock)
def invokeDefaultHandler(self, signalNumber, stackFrame):
print('*** allowing mid-frame keyboard interrupt.')