Browse Source

handling of new FFI and new style classes

Joe Shochet 20 years ago
parent
commit
f91315ca95
1 changed files with 12 additions and 4 deletions
  1. 12 4
      direct/src/showbase/Finder.py

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

@@ -1,6 +1,7 @@
 
 
 import types
 import types
 import os
 import os
+import new
 
 
 def findClassInModule(module, className, visited):
 def findClassInModule(module, className, visited):
     # Make sure you have not already visited this module
     # Make sure you have not already visited this module
@@ -13,7 +14,8 @@ def findClassInModule(module, className, visited):
 
 
     # First see if we are in the dict at this level
     # First see if we are in the dict at this level
     classObj = module.__dict__.get(className)
     classObj = module.__dict__.get(className)
-    if classObj and (type(classObj) == types.ClassType):
+    if classObj and ((type(classObj) == types.ClassType) or
+                     (type(classObj) == types.TypeType)):
         return [classObj, module.__dict__]
         return [classObj, module.__dict__]
 
 
     # Now filter out all the modules and iterate through them
     # Now filter out all the modules and iterate through them
@@ -33,14 +35,17 @@ def findClass(namespace, className):
 
 
     # First see if we are in the namespace
     # First see if we are in the namespace
     classObj = namespace.get(className)
     classObj = namespace.get(className)
-    if classObj and (type(classObj) == types.ClassType):
+    # print classObj, type(classObj)
+    if classObj and ((type(classObj) == types.ClassType) or
+                     (type(classObj) == types.TypeType)):
         return [classObj, namespace]
         return [classObj, namespace]
     
     
     for key in namespace.keys():
     for key in namespace.keys():
         value = namespace[key]
         value = namespace[key]
         # If we found a class, see if it matches classname
         # If we found a class, see if it matches classname
         # Make sure we do not match "_"
         # Make sure we do not match "_"
-        if ((key != "_") and (type(value) == types.ClassType)):
+        if ((key != "_") and ((type(value) == types.ClassType) or
+                              (type(value) == types.TypeType))):
             if value.__name__ == className:
             if value.__name__ == className:
                 # It does, that was easy!
                 # It does, that was easy!
                 return [value, namespace]
                 return [value, namespace]
@@ -125,7 +130,10 @@ def copyFuncs(fromClass, toClass):
                 replaceTaskMgrFunc(oldFunc, newFunc)
                 replaceTaskMgrFunc(oldFunc, newFunc)
                 replaceStateFunc(oldFunc, newFunc)
                 replaceStateFunc(oldFunc, newFunc)
                 replaceTcrFunc(oldFunc, newFunc)
                 replaceTcrFunc(oldFunc, newFunc)
-            toClass.__dict__[key] = newFunc
+            # You cannot assign directly to the dict with new style classes
+            # toClass.__dict__[key] = newFunc
+            # Instead we will use setattr
+            setattr(toClass, key, newFunc)
 
 
 def replaceMessengerFunc(oldFunc, newFunc):
 def replaceMessengerFunc(oldFunc, newFunc):
     try:
     try: