Browse Source

added traceParentCall; print fsm tre unfinished

Dave Schuyler 21 years ago
parent
commit
c85e84adc6
1 changed files with 20 additions and 1 deletions
  1. 20 1
      direct/src/showbase/PythonUtil.py

+ 20 - 1
direct/src/showbase/PythonUtil.py

@@ -31,6 +31,18 @@ def indent(stream, numIndents, str):
     stream.write('    ' * numIndents + str)
 
 
+
+def writeFsmTree(instance, indent = 0):
+    if hasattr(instance, 'parentFSM'):
+        writeFsmTree(instance.parentFSM, indent-2)
+    elif hasattr(instance, 'fsm'):
+        name = ''
+        if hasattr(instance.fsm, 'state'):
+            name = instance.fsm.state.name
+        print "%s: %s"%(instance.fsm.name, name)
+        
+
+
 
 def traceFunctionCall(frame):
     """
@@ -45,12 +57,16 @@ def traceFunctionCall(frame):
     if co.co_flags & 4: n = n+1
     if co.co_flags & 8: n = n+1
     r=f.f_code.co_name+'('
+    comma=0 # formatting, whether we should type a comma.
     for i in range(n):
         name = co.co_varnames[i]
         if name=='self':
             continue
-        if i:
+        if comma:
             r+=', '
+        else:
+            # ok, we skipped the first one, the rest get commas:
+            comma=1
         r+=name
         r+='='
         if dict.has_key(name):
@@ -62,6 +78,9 @@ def traceFunctionCall(frame):
         else: r+="*** undefined ***"
     return r+')'
 
+def traceParentCall():
+    return traceFunctionCall(sys._getframe(2))
+
 def printThisCall():
     print traceFunctionCall(sys._getframe(1))
     return 1 # to allow "assert printThisCall()"