2008-07-15 07:34:46 +00:00
|
|
|
#!BPY
|
|
|
|
"""
|
2008-08-10 16:07:14 +00:00
|
|
|
Name: 'Member Suggest | .'
|
2008-07-15 07:34:46 +00:00
|
|
|
Blender: 246
|
|
|
|
Group: 'TextPlugin'
|
|
|
|
Shortcut: 'Period'
|
2008-07-18 11:00:34 +00:00
|
|
|
Tooltip: 'Lists members of the object preceding the cursor in the current text space'
|
2008-07-15 07:34:46 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Only run if we have the required modules
|
|
|
|
try:
|
|
|
|
import bpy
|
|
|
|
from BPyTextPlugin import *
|
2008-07-15 12:55:20 +00:00
|
|
|
except ImportError:
|
2008-07-15 07:34:46 +00:00
|
|
|
OK = False
|
2008-07-26 20:02:10 +00:00
|
|
|
else:
|
|
|
|
OK = True
|
2008-07-15 07:34:46 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
txt = bpy.data.texts.active
|
2008-07-16 12:56:23 +00:00
|
|
|
if not txt:
|
|
|
|
return
|
|
|
|
|
2008-07-15 07:34:46 +00:00
|
|
|
(line, c) = current_line(txt)
|
|
|
|
|
|
|
|
# Check we are in a normal context
|
2008-07-21 00:38:42 +00:00
|
|
|
if get_context(txt) != CTX_NORMAL:
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
targets = get_targets(line, c)
|
2008-07-15 07:34:46 +00:00
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
if targets[0] == '': # Check if we are looking at a constant [] {} '' etc.
|
|
|
|
i = c - len('.'.join(targets)) - 1
|
2008-07-26 20:02:10 +00:00
|
|
|
if i >= 0:
|
|
|
|
if line[i] == '"' or line[i] == "'":
|
2008-08-15 23:14:22 +00:00
|
|
|
targets[0] = 'str'
|
2008-07-26 20:02:10 +00:00
|
|
|
elif line[i] == '}':
|
2008-08-15 23:14:22 +00:00
|
|
|
targets[0] = 'dict'
|
2008-07-26 20:02:10 +00:00
|
|
|
elif line[i] == ']': # Could be array elem x[y] or list [y]
|
|
|
|
i = line.rfind('[', 0, i) - 1
|
|
|
|
while i >= 0:
|
|
|
|
if line[i].isalnum() or line[i] == '_':
|
|
|
|
break
|
|
|
|
elif line[i] != ' ' and line[i] != '\t':
|
|
|
|
i = -1
|
|
|
|
break
|
|
|
|
i -= 1
|
|
|
|
if i < 0:
|
2008-08-15 23:14:22 +00:00
|
|
|
targets[0] = 'list'
|
2008-07-21 00:38:42 +00:00
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
obj = resolve_targets(txt, targets[:-1])
|
2008-07-21 00:38:42 +00:00
|
|
|
if not obj:
|
2008-07-15 07:34:46 +00:00
|
|
|
return
|
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
items = []
|
2008-07-15 07:34:46 +00:00
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
if isinstance(obj, VarDesc):
|
|
|
|
obj = obj.type
|
|
|
|
|
|
|
|
if isinstance(obj, Definition): # Locally defined
|
|
|
|
if hasattr(obj, 'classes'):
|
|
|
|
items.extend([(s, 'f') for s in obj.classes.keys()])
|
|
|
|
if hasattr(obj, 'defs'):
|
|
|
|
items.extend([(s, 'f') for s in obj.defs.keys()])
|
|
|
|
if hasattr(obj, 'vars'):
|
|
|
|
items.extend([(s, 'v') for s in obj.vars.keys()])
|
2008-07-15 07:34:46 +00:00
|
|
|
|
2008-08-15 23:14:22 +00:00
|
|
|
else: # Otherwise we have an imported or builtin object
|
2008-07-15 12:55:20 +00:00
|
|
|
try:
|
2008-08-15 23:14:22 +00:00
|
|
|
attr = obj.__dict__.keys()
|
|
|
|
except AttributeError:
|
|
|
|
attr = dir(obj)
|
2008-07-26 20:02:10 +00:00
|
|
|
else:
|
2008-08-15 23:14:22 +00:00
|
|
|
if not attr: attr = dir(obj)
|
|
|
|
|
|
|
|
for k in attr:
|
|
|
|
try:
|
|
|
|
v = getattr(obj, k)
|
|
|
|
except (AttributeError, TypeError): # Some attributes are not readable
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
items.append((k, type_char(v)))
|
2008-07-15 07:34:46 +00:00
|
|
|
|
2008-07-26 20:02:10 +00:00
|
|
|
if items != []:
|
|
|
|
items.sort(cmp = suggest_cmp)
|
2008-08-15 23:14:22 +00:00
|
|
|
txt.suggest(items, targets[-1])
|
2008-07-15 07:34:46 +00:00
|
|
|
|
2008-07-16 10:33:48 +00:00
|
|
|
# Check we are running as a script and not imported as a module
|
|
|
|
if __name__ == "__main__" and OK:
|
2008-07-15 07:34:46 +00:00
|
|
|
main()
|