From 7ebeef4d096eb92b3c9911900049ae6ba3ec6c0c Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Mon, 2 Apr 2001 19:07:13 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/directnotify/DirectNotify.py | 65 ++++++++++++++++++------- direct/src/directnotify/Notifier.py | 23 ++++----- direct/src/ffi/FFIExternalObject.py | 2 +- direct/src/ffi/Sources.pp | 1 + direct/src/ffi/genPyCode | 29 +++++++++++ direct/src/ffi/generatePythonCode | 4 ++ direct/src/showbase/Loader.py | 2 +- direct/src/showbase/Messenger.py | 5 ++ direct/src/showbase/ShowBase.py | 12 ++--- direct/src/showbase/ShowBaseGlobal.py | 6 +++ direct/src/task/Task.py | 4 +- 11 files changed, 111 insertions(+), 42 deletions(-) create mode 100755 direct/src/ffi/genPyCode diff --git a/direct/src/directnotify/DirectNotify.py b/direct/src/directnotify/DirectNotify.py index 2c18c3dbba..58e3f36ac0 100644 --- a/direct/src/directnotify/DirectNotify.py +++ b/direct/src/directnotify/DirectNotify.py @@ -29,19 +29,7 @@ class DirectNotify: def getCategory(self, categoryName): """getCategory(self, string) Return the category with given name if present, None otherwise""" - return(self.__categories.get(categoryName, None)) - - def addCategory(self, categoryName, category): - """addCategory(self, Notifier) - Add a given Notifier with given name to the category dictionary - and return 0 if not present, else return 0. """ - if (self.__categories.has_key(categoryName)): - print "Warning: DirectNotify: category '%s' already exists" % \ - (categoryName) - return(0) - else: - self.__categories[categoryName] = category - return(1) + return (self.__categories.get(categoryName, None)) def newCategory(self, categoryName, logger=None): """newCategory(self, string) @@ -49,16 +37,57 @@ class DirectNotify: if no such category exists, else return existing category""" if (not self.__categories.has_key(categoryName)): self.__categories[categoryName] = Notifier.Notifier(categoryName, logger) + self.setDconfigLevel(categoryName) else: print "Warning: DirectNotify: category '%s' already exists" % \ (categoryName) - return(self.getCategory(categoryName)) + return (self.getCategory(categoryName)) - - -#global DirectNotify for public access -directNotify = DirectNotify() + def setDconfigLevel(self, categoryName): + """ + Check to see if this category has a dconfig variable + to set the notify severity and then set that level. You cannot + set these until base.config is set. + """ + # We cannot check dconfig variables until base.config has been + # set. Once base.config is set in ShowBase.py, it tries to set + # all the levels again in case some were created before base.config + # was created. + try: + base.config + except: + return 0 + + dconfigParam = ("notify-level-" + categoryName) + level = base.config.GetString(dconfigParam, "") + if level: + print ("Setting DirectNotify category: " + dconfigParam + + " to severity: " + level) + category = self.getCategory(categoryName) + if level == "error": + category.setWarning(0) + category.setInfo(0) + category.setDebug(0) + elif level == "warning": + category.setWarning(1) + category.setInfo(0) + category.setDebug(0) + elif level == "info": + category.setWarning(1) + category.setInfo(1) + category.setDebug(0) + elif level == "debug": + category.setWarning(1) + category.setInfo(1) + category.setDebug(1) + else: + print ("DirectNotify: unknown notify level: " + str(level) + + " for category: " + str(categoryName)) + + def setDconfigLevels(self): + for categoryName in self.getCategories(): + self.setDconfigLevel(categoryName) diff --git a/direct/src/directnotify/Notifier.py b/direct/src/directnotify/Notifier.py index 88a61c890c..58b37167f0 100644 --- a/direct/src/directnotify/Notifier.py +++ b/direct/src/directnotify/Notifier.py @@ -17,7 +17,8 @@ class Notifier: else: self.__logger = logger - self.__verbose = 0 + # Global default levels are initialized here + self.__info = 1 self.__warning = 1 self.__debug = 0 self.__logging = 0 @@ -25,8 +26,8 @@ class Notifier: def __str__(self): """__str__(self) Print handling routine""" - return "%s: verbose = %d, warning = %d, debug = %d, logging = %d" % \ - (self.__name, self.__verbose, self.__warning, self.__debug, self.__logging) + return "%s: info = %d, warning = %d, debug = %d, logging = %d" % \ + (self.__name, self.__info, self.__warning, self.__debug, self.__logging) # error funcs @@ -83,21 +84,21 @@ class Notifier: # info funcs def info(self, infoString): """info(self, string) - Print the given informational string, if verbose flag is on""" - if (self.__verbose): + Print the given informational string, if info flag is on""" + if (self.__info): str = ':' + self.__name + '(info): ' + infoString self.__log(str) print(str) - def getVerbose(self): - """getVerbose(self) + def getInfo(self): + """getInfo(self) Return whether the printing of info messages is on or off""" - return(self.__verbose) + return(self.__info) - def setVerbose(self, bool): - """setVerbose(self, int) + def setInfo(self, bool): + """setInfo(self, int) Enable/Disable informational message printing""" - self.__verbose = bool + self.__info = bool # log funcs diff --git a/direct/src/ffi/FFIExternalObject.py b/direct/src/ffi/FFIExternalObject.py index 26275599bf..b33b980863 100644 --- a/direct/src/ffi/FFIExternalObject.py +++ b/direct/src/ffi/FFIExternalObject.py @@ -7,7 +7,7 @@ WrapperClassMap = {} DowncastMap = {} # For testing, you can turn verbose and debug on -# FFIConstants.notify.setVerbose(1) +# FFIConstants.notify.setInfo(1) # FFIConstants.notify.setDebug(1) diff --git a/direct/src/ffi/Sources.pp b/direct/src/ffi/Sources.pp index 168982f1e9..f7beca67b1 100644 --- a/direct/src/ffi/Sources.pp +++ b/direct/src/ffi/Sources.pp @@ -1,2 +1,3 @@ #define INSTALL_SCRIPTS generatePythonCode +#define INSTALL_SCRIPTS genPyCode diff --git a/direct/src/ffi/genPyCode b/direct/src/ffi/genPyCode new file mode 100755 index 0000000000..4b41a6a870 --- /dev/null +++ b/direct/src/ffi/genPyCode @@ -0,0 +1,29 @@ +#! /bin/sh + +# This is just a helper script to generatePythonCode to cover +# the three or four cases we use all the time + +if [ "$1" = "linux" ]; then + cd $DIRECT/bin + exec ppython -d generatePythonCode -v -d $DIRECT/lib/py -e $DIRECT/src/extensions -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect libtoontown + exit 1 +fi + +if [ "$1" = "win-debug" ]; then + cd $DIRECT/bin + exec ppython -d generatePythonCode -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect libtoontown + exit 1 +fi + +if [ "$1" = "win-release" ]; then + cd $DIRECT/bin + exec ppython -i generatePythonCode -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect libtoontown + exit 1 +fi + +if [ "$1" = "win-publish" ]; then + # no assertions, no comments, no docstrings + cd $DIRECT/bin + exec ppython -OO generatePythonCode -O -v -d `cygpath -w $DIRECT/lib/py` -e `cygpath -w $DIRECT/src/extensions` -i libdtoolconfig libpandaexpress libpanda libpandaphysics libdirect libtoontown + exit 1 +fi diff --git a/direct/src/ffi/generatePythonCode b/direct/src/ffi/generatePythonCode index f529bcd8dd..781f1a82e2 100644 --- a/direct/src/ffi/generatePythonCode +++ b/direct/src/ffi/generatePythonCode @@ -33,6 +33,10 @@ Options: -e dir directory to pull extension code from -i lib interrogate library -O no C++ comments or assertion statements + linux + windows-debug + windows-release + windows-publish """ # Initialize variables diff --git a/direct/src/showbase/Loader.py b/direct/src/showbase/Loader.py index 4bc81d8a32..7e6421970a 100644 --- a/direct/src/showbase/Loader.py +++ b/direct/src/showbase/Loader.py @@ -8,7 +8,7 @@ class Loader: """Loader class: contains method to load models, sounds and code""" notify = directNotify.newCategory("Loader") - # notify.setVerbose(1) + # notify.setInfo(1) # special methods def __init__(self, base): diff --git a/direct/src/showbase/Messenger.py b/direct/src/showbase/Messenger.py index 0b2db3b88f..49dcc8a600 100644 --- a/direct/src/showbase/Messenger.py +++ b/direct/src/showbase/Messenger.py @@ -69,6 +69,7 @@ class Messenger: def ignoreAll(self, object): """ ignoreAll(self, DirectObject) Make this object no longer respond to any events it was accepting + Useful for cleanup """ Messenger.notify.debug(`object` + '\n now ignoring all events') @@ -139,6 +140,10 @@ class Messenger: def replaceMethod(self, oldMethod, newFunction): + """ + This is only used by Finder.py - the module that lets + you redefine functions with Control-c-Control-v + """ import new for entry in self.dict.items(): event, objectDict = entry diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 599a29df56..726806a4a0 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -12,16 +12,13 @@ import Task import EventManager import math import sys -import LinearEulerIntegrator -import AngularEulerIntegrator -import ClockObject import Transitions import Loader import time import FSM import State -globalClock = ClockObject.ClockObject.getGlobalClock() +globalClock = ClockObject.getGlobalClock() class ShowBase: @@ -40,9 +37,6 @@ class ShowBase: taskMgr.taskTimerVerbose = self.config.GetBool('task-timer-verbose', 0) - fsmDebug = self.config.GetBool('fsm-debug', 0) - FSM.FSM.notify.setDebug(fsmDebug) - fsmRedefine = self.config.GetBool('fsm-redefine', 0) State.FsmRedefine = fsmRedefine @@ -160,7 +154,7 @@ class ShowBase: # Physics manager self.physicsMgr = physicsMgr - integrator = LinearEulerIntegrator.LinearEulerIntegrator() + integrator = LinearEulerIntegrator() self.physicsMgr.attachLinearIntegrator(integrator) self.physicsMgrEnabled = 0 self.physicsMgrAngular = 0 @@ -178,7 +172,7 @@ class ShowBase: """addAngularIntegrator(self)""" if (self.physicsMgrAngular == 0): self.physicsMgrAngular = 1 - integrator = AngularEulerIntegrator.AngularEulerIntegrator() + integrator = AngularEulerIntegrator() self.physicsMgr.attachAngularIntegrator(integrator) def enableParticles(self): diff --git a/direct/src/showbase/ShowBaseGlobal.py b/direct/src/showbase/ShowBaseGlobal.py index 6fca3cc35b..04f0e33dec 100644 --- a/direct/src/showbase/ShowBaseGlobal.py +++ b/direct/src/showbase/ShowBaseGlobal.py @@ -19,3 +19,9 @@ __builtin__.taskMgr = base.taskMgr __builtin__.eventMgr = base.eventMgr __builtin__.messenger = base.messenger __builtin__.config = base.config +__builtin__.directNotify = directNotify + +# Set direct notify categories now that we have config +directNotify.setDconfigLevels() + + diff --git a/direct/src/task/Task.py b/direct/src/task/Task.py index 0f2fe7e59e..17f4d7c48c 100644 --- a/direct/src/task/Task.py +++ b/direct/src/task/Task.py @@ -1,5 +1,5 @@ from libpandaexpressModules import * -from DirectNotify import * +from DirectNotifyGlobal import * from PythonUtil import * import time import fnmatch @@ -348,7 +348,7 @@ class TaskManager: for task in self.taskList: task.setCurrentTimeFrame(self.currentTime, self.currentFrame) - if (self.taskTimerVerbose == 0): + if not self.taskTimerVerbose: # don't record timing info ret = task(task) else: