Browse Source

*** empty log message ***

Joe Shochet 25 years ago
parent
commit
db196d9d0a
2 changed files with 53 additions and 13 deletions
  1. 11 4
      direct/src/showbase/Finder.py
  2. 42 9
      direct/src/showbase/Messenger.py

+ 11 - 4
direct/src/showbase/Finder.py

@@ -52,7 +52,6 @@ def findClass(namespace, className):
 
 
 
 
 def rebindClass(builtins, filename):
 def rebindClass(builtins, filename):
-    tempClassName = 'py_temp_class'
     file = open(filename)
     file = open(filename)
     lines = file.readlines()
     lines = file.readlines()
     curLine = 0
     curLine = 0
@@ -96,7 +95,6 @@ def rebindClass(builtins, filename):
     # Make a temp file in the home directory to execfile from
     # Make a temp file in the home directory to execfile from
     tmpfilename = os.path.join(os.getenv('HOME'), 'tmp_py_file')
     tmpfilename = os.path.join(os.getenv('HOME'), 'tmp_py_file')
     tmpfile = open(tmpfilename, 'w')
     tmpfile = open(tmpfilename, 'w')
-#    newline = 'class ' + tempClassName + ':\012'
 
 
     # now write the class back to the file with the new class name
     # now write the class back to the file with the new class name
     for i in range(len(lines)):
     for i in range(len(lines)):
@@ -132,6 +130,15 @@ def copyFuncs(fromClass, toClass):
     for key in fromClass.__dict__.keys():
     for key in fromClass.__dict__.keys():
         value = fromClass.__dict__[key]
         value = fromClass.__dict__[key]
         if (type(value) == types.FunctionType):
         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__)
 
 
-    

+ 42 - 9
direct/src/showbase/Messenger.py

@@ -5,8 +5,8 @@ from DirectNotifyGlobal import *
 
 
 class Messenger:
 class Messenger:
 
 
-    notify = None
-    
+    notify = None    
+
     def __init__(self):
     def __init__(self):
         """ __init__(self)
         """ __init__(self)
         One dictionary does it all. It has the following structure:
         One dictionary does it all. It has the following structure:
@@ -113,6 +113,32 @@ class Messenger:
         """
         """
         self.dict.clear()
         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):
     def toggleVerbose(self):
         Messenger.notify.setDebug(1 - Messenger.notify.getDebug())
         Messenger.notify.setDebug(1 - Messenger.notify.getDebug())
 
 
@@ -149,18 +175,25 @@ class Messenger:
             acceptorDict = self.dict[event]
             acceptorDict = self.dict[event]
             str = str + 'Event: ' + event + '\n'
             str = str + 'Event: ' + event + '\n'
             for object in acceptorDict.keys():
             for object in acceptorDict.keys():
-                method, extraArgs, persistent = acceptorDict[object]
+                function, extraArgs, persistent = acceptorDict[object]
                 if (type(object) == types.InstanceType):
                 if (type(object) == types.InstanceType):
                     className = object.__class__.__name__
                     className = object.__class__.__name__
                 else:
                 else:
                     className = "Not a class"
                     className = "Not a class"
-                methodName = method.__name__
+                functionName = function.__name__
                 str = (str + '\t' +
                 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'
         str = str + '='*50 + '\n'
         return str
         return str