3 Name: 'Member Suggest | .'
7 Tooltip: 'Lists members of the object preceding the cursor in the current text space'
10 # Only run if we have the required modules
13 from BPyTextPlugin import *
20 txt = bpy.data.texts.active
24 (line, c) = current_line(txt)
26 # Check we are in a normal context
27 if get_context(txt) != CTX_NORMAL:
30 pre = get_targets(line, c)
35 imports = get_imports(txt)
36 builtins = get_builtins()
38 # Identify the root (root.sub.sub.)
41 i = c - len('.'.join(pre)) - 1
43 if line[i] == '"' or line[i] == "'":
47 elif line[i] == ']': # Could be array elem x[y] or list [y]
48 i = line.rfind('[', 0, i) - 1
50 if line[i].isalnum() or line[i] == '_':
52 elif line[i] != ' ' and line[i] != '\t':
58 elif imports.has_key(pre[0]):
60 elif builtins.has_key(pre[0]):
61 obj = builtins[pre[0]]
63 desc = get_cached_descriptor(txt)
64 if desc.vars.has_key(pre[0]):
65 obj = desc.vars[pre[0]].type
70 # Step through sub-attributes
72 for name in pre[1:-1]:
73 obj = getattr(obj, name)
74 except AttributeError:
75 print "Attribute not found '%s' in '%s'" % (name, '.'.join(pre))
79 attr = obj.__dict__.keys()
80 except AttributeError:
90 except (AttributeError, TypeError): # Some attributes are not readable
93 items.append((k, type_char(v)))
96 items.sort(cmp = suggest_cmp)
97 txt.suggest(items, pre[-1])
99 # Check we are running as a script and not imported as a module
100 if __name__ == "__main__" and OK: