~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to release/scripts/textplugin_functiondocs.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!BPY
2
 
"""
3
 
Name: 'Function Documentation | Ctrl I'
4
 
Blender: 246
5
 
Group: 'TextPlugin'
6
 
Shortcut: 'Ctrl+I'
7
 
Tooltip: 'Attempts to display documentation about the function preceding the cursor.'
8
 
"""
9
 
 
10
 
# Only run if we have the required modules
11
 
try:
12
 
        import bpy
13
 
        from BPyTextPlugin import *
14
 
except ImportError:
15
 
        OK = False
16
 
else:
17
 
        OK = True
18
 
 
19
 
def main():
20
 
        txt = bpy.data.texts.active
21
 
        if not txt:
22
 
                return
23
 
        
24
 
        (line, c) = current_line(txt)
25
 
        
26
 
        # Check we are in a normal context
27
 
        if get_context(txt) != CTX_NORMAL:
28
 
                return
29
 
        
30
 
        # Identify the name under the cursor
31
 
        llen = len(line)
32
 
        while c<llen and (line[c].isalnum() or line[c]=='_'):
33
 
                c += 1
34
 
        
35
 
        targets = get_targets(line, c)
36
 
        
37
 
        # If no name under cursor, look backward to see if we're in function parens
38
 
        if len(targets) == 0 or targets[0] == '':
39
 
                # Look backwards for first '(' without ')'
40
 
                b = 0
41
 
                found = False
42
 
                for i in range(c-1, -1, -1):
43
 
                        if line[i] == ')': b += 1
44
 
                        elif line[i] == '(':
45
 
                                b -= 1
46
 
                                if b < 0:
47
 
                                        found = True
48
 
                                        c = i
49
 
                                        break
50
 
                if found: targets = get_targets(line, c)
51
 
                if len(targets) == 0 or targets[0] == '':
52
 
                        return
53
 
        
54
 
        obj = resolve_targets(txt, targets)
55
 
        if not obj: return
56
 
        
57
 
        if isinstance(obj, Definition): # Local definition
58
 
                txt.showDocs(obj.doc)
59
 
        elif hasattr(obj, '__doc__') and obj.__doc__:
60
 
                txt.showDocs(obj.__doc__)
61
 
 
62
 
# Check we are running as a script and not imported as a module
63
 
if __name__ == "__main__" and OK:
64
 
        main()
 
1
#!BPY
 
2
"""
 
3
Name: 'Function Documentation | Ctrl I'
 
4
Blender: 246
 
5
Group: 'TextPlugin'
 
6
Shortcut: 'Ctrl+I'
 
7
Tooltip: 'Attempts to display documentation about the function preceding the cursor.'
 
8
"""
 
9
 
 
10
# Only run if we have the required modules
 
11
try:
 
12
        import bpy
 
13
        from BPyTextPlugin import *
 
14
except ImportError:
 
15
        OK = False
 
16
else:
 
17
        OK = True
 
18
 
 
19
def main():
 
20
        txt = bpy.data.texts.active
 
21
        if not txt:
 
22
                return
 
23
        
 
24
        (line, c) = current_line(txt)
 
25
        
 
26
        # Check we are in a normal context
 
27
        if get_context(txt) != CTX_NORMAL:
 
28
                return
 
29
        
 
30
        # Identify the name under the cursor
 
31
        llen = len(line)
 
32
        while c<llen and (line[c].isalnum() or line[c]=='_'):
 
33
                c += 1
 
34
        
 
35
        targets = get_targets(line, c)
 
36
        
 
37
        # If no name under cursor, look backward to see if we're in function parens
 
38
        if len(targets) == 0 or targets[0] == '':
 
39
                # Look backwards for first '(' without ')'
 
40
                b = 0
 
41
                found = False
 
42
                for i in range(c-1, -1, -1):
 
43
                        if line[i] == ')': b += 1
 
44
                        elif line[i] == '(':
 
45
                                b -= 1
 
46
                                if b < 0:
 
47
                                        found = True
 
48
                                        c = i
 
49
                                        break
 
50
                if found: targets = get_targets(line, c)
 
51
                if len(targets) == 0 or targets[0] == '':
 
52
                        return
 
53
        
 
54
        obj = resolve_targets(txt, targets)
 
55
        if not obj: return
 
56
        
 
57
        if isinstance(obj, Definition): # Local definition
 
58
                txt.showDocs(obj.doc)
 
59
        elif hasattr(obj, '__doc__') and obj.__doc__:
 
60
                txt.showDocs(obj.__doc__)
 
61
 
 
62
# Check we are running as a script and not imported as a module
 
63
if __name__ == "__main__" and OK:
 
64
        main()