From db196d9d0a1012b15149bdfd6ea82c2354491254 Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Mon, 5 Feb 2001 23:36:37 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/showbase/Finder.py | 15 +++++++--- direct/src/showbase/Messenger.py | 51 ++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/direct/src/showbase/Finder.py b/direct/src/showbase/Finder.py index 485ced0cec..e999a4ad55 100644 --- a/direct/src/showbase/Finder.py +++ b/direct/src/showbase/Finder.py @@ -52,7 +52,6 @@ def findClass(namespace, className): def rebindClass(builtins, filename): - tempClassName = 'py_temp_class' file = open(filename) lines = file.readlines() curLine = 0 @@ -96,7 +95,6 @@ def rebindClass(builtins, filename): # Make a temp file in the home directory to execfile from tmpfilename = os.path.join(os.getenv('HOME'), 'tmp_py_file') tmpfile = open(tmpfilename, 'w') -# newline = 'class ' + tempClassName + ':\012' # now write the class back to the file with the new class name for i in range(len(lines)): @@ -132,6 +130,15 @@ def copyFuncs(fromClass, toClass): for key in fromClass.__dict__.keys(): value = fromClass.__dict__[key] if (type(value) == types.FunctionType): - toClass.__dict__[key] = value + oldFunc = toClass.__dict__[key] + newFunc = value + # Look in the messenger to see if this old function pointer + # is stored, and update it to the new function pointer + replaceMessengerFunc(oldFunc, newFunc) + toClass.__dict__[key] = newFunc + +def replaceMessengerFunc(oldFunc, newFunc): + res = messenger.replaceMethod(oldFunc, newFunc) + if res: + print ('messenger replaced function: ' + newFunc.__name__) - diff --git a/direct/src/showbase/Messenger.py b/direct/src/showbase/Messenger.py index 778db7450a..9ff9281bfa 100644 --- a/direct/src/showbase/Messenger.py +++ b/direct/src/showbase/Messenger.py @@ -5,8 +5,8 @@ from DirectNotifyGlobal import * class Messenger: - notify = None - + notify = None + def __init__(self): """ __init__(self) One dictionary does it all. It has the following structure: @@ -113,6 +113,32 @@ class Messenger: """ self.dict.clear() + + def replaceMethod(self, oldMethod, newFunction): + import new + for entry in self.dict.items(): + event, objectDict = entry + for objectEntry in objectDict.items(): + object, params = objectEntry + method = params[0] + if (type(method) == types.MethodType): + function = method.im_func + else: + function = method + #print ('function: ' + `function` + '\n' + + # 'method: ' + `method` + '\n' + + # 'oldMethod: ' + `oldMethod` + '\n' + + # 'newFunction: ' + `newFunction` + '\n') + if (function == oldMethod): + newMethod = new.instancemethod(newFunction, + method.im_self, + method.im_class) + params[0] = newMethod + # Found it retrun true + return 1 + # didnt find that method, return false + return 0 + def toggleVerbose(self): Messenger.notify.setDebug(1 - Messenger.notify.getDebug()) @@ -149,18 +175,25 @@ class Messenger: acceptorDict = self.dict[event] str = str + 'Event: ' + event + '\n' for object in acceptorDict.keys(): - method, extraArgs, persistent = acceptorDict[object] + function, extraArgs, persistent = acceptorDict[object] if (type(object) == types.InstanceType): className = object.__class__.__name__ else: className = "Not a class" - methodName = method.__name__ + functionName = function.__name__ str = (str + '\t' + - 'Acceptor: ' + className + ' instance' + '\n\t' + - 'Method: ' + methodName + '\n\t' + - 'Extra Args: ' + `extraArgs` + '\n\t' + - 'Persistent: ' + `persistent` + '\n\n' - ) + 'Acceptor: ' + className + ' instance' + '\n\t' + + 'Function name:' + functionName + '\n\t' + + 'Extra Args: ' + `extraArgs` + '\n\t' + + 'Persistent: ' + `persistent` + '\n') + # If this is a class method, get its actual function + if (type(function) == types.MethodType): + str = (str + '\t' + + 'Method: ' + `function` + '\n\t' + + 'Function: ' + `function.im_func` + '\n') + else: + str = (str + '\t' + + 'Function: ' + `function` + '\n') str = str + '='*50 + '\n' return str