3 Name: 'Function Documentation | Ctrl I'
7 Tooltip: 'Attempts to display documentation about the function preceding the cursor.'
10 # Only run if we have the required modules
13 from BPyTextPlugin import *
20 txt = bpy.data.texts.active
24 (line, c) = current_line(txt)
26 # Check we are in a normal context
27 if get_context(txt) != CTX_NORMAL:
30 # Look backwards for first '(' without ')'
33 for i in range(c-1, -1, -1):
34 if line[i] == ')': b += 1
42 # Otherwise identify the name under the cursor
45 while c<llen and (line[c].isalnum() or line[c]=='_'):
48 pre = get_targets(line, c)
53 imports = get_imports(txt)
54 builtins = get_builtins()
56 # Identify the root (root.sub.sub.)
57 if imports.has_key(pre[0]):
59 elif builtins.has_key(pre[0]):
60 obj = builtins[pre[0]]
64 # Step through sub-attributes
67 obj = getattr(obj, name)
68 except AttributeError:
69 print "Attribute not found '%s' in '%s'" % (name, '.'.join(pre))
72 if hasattr(obj, '__doc__') and obj.__doc__:
73 txt.showDocs(obj.__doc__)
75 # Check we are running as a script and not imported as a module
76 if __name__ == "__main__" and OK: