Welcome to mirror list, hosted at ThFree Co, Russian Federation.

textplugin_membersuggest.py « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: daa361e31636bcaa603f8ef4c3a8f1d907db8378 (plain)
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
65
66
67
68
69
70
71
72
73
74
#!BPY
"""
Name: 'Member Suggest'
Blender: 246
Group: 'TextPlugin'
Shortcut: 'Period'
Tooltip: 'Lists members of the object preceding the cursor in the current text space'
"""

# 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
	
	pre = get_targets(line, c)
	
	if len(pre) <= 1:
		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:-1]:
			obj = getattr(obj, name)
	except AttributeError:
		print "Attribute not found '%s' in '%s'" % (name, '.'.join(pre))
		return
	
	try:
		attr = obj.__dict__.keys()
		if not attr:
			attr = dir(obj)
	except AttributeError:
		attr = dir(obj)
	
	list = []
	for k in attr:
		try:
			v = getattr(obj, k)
			list.append((k, type_char(v)))
		except (AttributeError, TypeError): # Some attributes are not readable
			pass
	
	if list != []:
		list.sort(cmp = suggest_cmp)
		txt.suggest(list, pre[-1])

# Check we are running as a script and not imported as a module
if __name__ == "__main__" and OK:
	main()