diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-07-19 03:12:19 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-07-19 03:12:19 +0400 |
commit | 123407e0b4ec616aef40216ab76e559e0dee5711 (patch) | |
tree | 90e3ad4fc0084c6f2f3ba017a85e9770fd1bcf67 /release | |
parent | b205cf34b4586cd2ebd51a655ce30be4dcccc48c (diff) |
Added a documentation panel with primitive word-wrap functionality. It can be displayed by Text.showDoc(string) in python and has a text-plugin script for function docs which may be invoked with Ctrl+I inside its params list. Eg. type "dir(" <Ctrl+I>
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/textplugin_functiondocs.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/release/scripts/textplugin_functiondocs.py b/release/scripts/textplugin_functiondocs.py new file mode 100644 index 00000000000..2277b7e68b5 --- /dev/null +++ b/release/scripts/textplugin_functiondocs.py @@ -0,0 +1,68 @@ +#!BPY +""" +Name: 'Function Documentation' +Blender: 246 +Group: 'TextPlugin' +Shortcut: 'Ctrl+I' +Tooltip: 'Attempts to display documentation about the function preceding the cursor.' +""" + +# Only run if we have the required modules +try: + import bpy + from BPyTextPlugin import * + OK = True +except ImportError: + OK = False + +def main(): + txt = bpy.data.texts.active + if not txt: + return + + (line, c) = current_line(txt) + + # Check we are in a normal context + if get_context(txt) != NORMAL: + return + + # Look backwards for first '(' without ')' + b = 0 + for i in range(c-1, -1, -1): + if line[i] == ')': b += 1 + elif line[i] == '(': + b -= 1 + if b < 0: + c = i + break + + pre = get_targets(line, c) + + if len(pre) == 0: + return + + imports = get_imports(txt) + builtins = get_builtins() + + # Identify the root (root.sub.sub.) + if imports.has_key(pre[0]): + obj = imports[pre[0]] + elif builtins.has_key(pre[0]): + obj = builtins[pre[0]] + else: + return + + # Step through sub-attributes + try: + for name in pre[1:]: + obj = getattr(obj, name) + except AttributeError: + print "Attribute not found '%s' in '%s'" % (name, '.'.join(pre)) + return + + if hasattr(obj, '__doc__') and obj.__doc__: + txt.showDocs(obj.__doc__) + +# Check we are running as a script and not imported as a module +if __name__ == "__main__" and OK: + main() |