From f7718b466bbf1b06d0c2a042f91896153b14c5a5 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 10 Oct 2023 12:52:26 +0200 Subject: [PATCH] direct: Fix assorted issues when using mypyc --- direct/src/directnotify/Notifier.py | 4 ++-- direct/src/gui/DirectEntry.py | 2 +- direct/src/gui/OnscreenText.py | 2 +- direct/src/showbase/ShowBase.py | 22 ++++++++++++---------- direct/src/showbase/ShowBaseGlobal.py | 2 +- direct/src/showutil/TexViewer.py | 2 +- direct/src/task/Task.py | 9 ++++++++- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/direct/src/directnotify/Notifier.py b/direct/src/directnotify/Notifier.py index bf3f14779a..cff41aa908 100644 --- a/direct/src/directnotify/Notifier.py +++ b/direct/src/directnotify/Notifier.py @@ -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(), diff --git a/direct/src/gui/DirectEntry.py b/direct/src/gui/DirectEntry.py index f106e40aad..632ba35738 100644 --- a/direct/src/gui/DirectEntry.py +++ b/direct/src/gui/DirectEntry.py @@ -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", diff --git a/direct/src/gui/OnscreenText.py b/direct/src/gui/OnscreenText.py index e3a8912151..4050f725f8 100644 --- a/direct/src/gui/OnscreenText.py +++ b/direct/src/gui/OnscreenText.py @@ -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() diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 1eb2c9aa00..df2630c636 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -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: diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index b24fca18fc..58e7e69f58 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -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 diff --git a/direct/src/showutil/TexViewer.py b/direct/src/showutil/TexViewer.py index 32b181b22a..5ad823b19f 100644 --- a/direct/src/showutil/TexViewer.py +++ b/direct/src/showutil/TexViewer.py @@ -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) diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 12716a6707..b0aa610e40 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -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.')