2008-07-15 07:34:46 +00:00
|
|
|
#!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
|
2008-07-15 12:55:20 +00:00
|
|
|
except ImportError:
|
2008-07-15 07:34:46 +00:00
|
|
|
OK = False
|
|
|
|
|
|
|
|
def main():
|
|
|
|
txt = bpy.data.texts.active
|
|
|
|
(line, c) = current_line(txt)
|
|
|
|
|
|
|
|
# Check we are in a normal context
|
2008-07-15 12:55:20 +00:00
|
|
|
if get_context(txt) != NORMAL:
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
pre = get_targets(line, c)
|
|
|
|
|
|
|
|
if len(pre) <= 1:
|
|
|
|
return
|
|
|
|
|
|
|
|
list = []
|
|
|
|
|
|
|
|
imports = get_imports(txt)
|
|
|
|
|
|
|
|
# Identify the root (root.sub.sub.)
|
|
|
|
if imports.has_key(pre[0]):
|
|
|
|
obj = imports[pre[0]]
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Step through sub-attributes
|
|
|
|
try:
|
|
|
|
for name in pre[1:-1]:
|
|
|
|
obj = getattr(obj, name)
|
2008-07-15 12:55:20 +00:00
|
|
|
except AttributeError:
|
2008-07-15 07:34:46 +00:00
|
|
|
print "Attribute not found '%s' in '%s'" % (name, '.'.join(pre))
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
attr = obj.__dict__.keys()
|
2008-07-15 12:55:20 +00:00
|
|
|
except AttributeError:
|
2008-07-15 07:34:46 +00:00
|
|
|
attr = dir(obj)
|
|
|
|
|
|
|
|
for k in attr:
|
2008-07-15 12:55:20 +00:00
|
|
|
try:
|
|
|
|
v = getattr(obj, k)
|
|
|
|
if is_module(v): t = 'm'
|
|
|
|
elif callable(v): t = 'f'
|
|
|
|
else: t = 'v'
|
|
|
|
list.append((k, t))
|
|
|
|
except (AttributeError, TypeError): # Some attributes are not readable
|
|
|
|
pass
|
2008-07-15 07:34:46 +00:00
|
|
|
|
|
|
|
if list != []:
|
|
|
|
list.sort(cmp = suggest_cmp)
|
|
|
|
txt.suggest(list, pre[-1])
|
|
|
|
|
|
|
|
if OK:
|
|
|
|
main()
|