File: textplugin_functiondocs.py

package info (click to toggle)
blender 2.49.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 89,664 kB
  • ctags: 113,718
  • sloc: ansic: 738,048; cpp: 231,960; python: 104,955; asm: 33,960; sh: 16,233; ml: 12,962; makefile: 4,477; perl: 3,474; fortran: 108; java: 8
file content (64 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!BPY
"""
Name: 'Function Documentation | Ctrl I'
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 *
except ImportError:
	OK = False
else:
	OK = True

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) != CTX_NORMAL:
		return
	
	# Identify the name under the cursor
	llen = len(line)
	while c<llen and (line[c].isalnum() or line[c]=='_'):
		c += 1
	
	targets = get_targets(line, c)
	
	# If no name under cursor, look backward to see if we're in function parens
	if len(targets) == 0 or targets[0] == '':
		# Look backwards for first '(' without ')'
		b = 0
		found = False
		for i in range(c-1, -1, -1):
			if line[i] == ')': b += 1
			elif line[i] == '(':
				b -= 1
				if b < 0:
					found = True
					c = i
					break
		if found: targets = get_targets(line, c)
		if len(targets) == 0 or targets[0] == '':
			return
	
	obj = resolve_targets(txt, targets)
	if not obj: return
	
	if isinstance(obj, Definition): # Local definition
		txt.showDocs(obj.doc)
	elif 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()