Integrated Freestyle to rendering pipeline
[blender.git] / release / scripts / textplugin_membersuggest.py
1 #!BPY
2 """
3 Name: 'Member Suggest | .'
4 Blender: 246
5 Group: 'TextPlugin'
6 Shortcut: 'Period'
7 Tooltip: 'Lists members of the object preceding the cursor in the current text space'
8 """
9
10 # Only run if we have the required modules
11 try:
12         import bpy
13         from BPyTextPlugin import *
14 except ImportError:
15         OK = False
16 else:
17         OK = True
18
19 def main():
20         txt = bpy.data.texts.active
21         if not txt:
22                 return
23         
24         (line, c) = current_line(txt)
25         
26         # Check we are in a normal context
27         if get_context(txt) != CTX_NORMAL:
28                 return
29         
30         targets = get_targets(line, c)
31         
32         if targets[0] == '': # Check if we are looking at a constant [] {} '' etc.
33                 i = c - len('.'.join(targets)) - 1
34                 if i >= 0:
35                         if line[i] == '"' or line[i] == "'":
36                                 targets[0] = 'str'
37                         elif line[i] == '}':
38                                 targets[0] = 'dict'
39                         elif line[i] == ']': # Could be array elem x[y] or list [y]
40                                 i = line.rfind('[', 0, i) - 1
41                                 while i >= 0:
42                                         if line[i].isalnum() or line[i] == '_':
43                                                 break
44                                         elif line[i] != ' ' and line[i] != '\t':
45                                                 i = -1
46                                                 break
47                                         i -= 1
48                                 if i < 0: 
49                                         targets[0] = 'list'
50         
51         obj = resolve_targets(txt, targets[:-1])
52         if not obj:
53                 return
54         
55         items = []
56         
57         if isinstance(obj, VarDesc):
58                 obj = obj.type
59                 
60         if isinstance(obj, Definition): # Locally defined
61                 if hasattr(obj, 'classes'):
62                         items.extend([(s, 'f') for s in obj.classes.keys()])
63                 if hasattr(obj, 'defs'):
64                         items.extend([(s, 'f') for s in obj.defs.keys()])
65                 if hasattr(obj, 'vars'):
66                         items.extend([(s, 'v') for s in obj.vars.keys()])
67         
68         else: # Otherwise we have an imported or builtin object
69                 try:
70                         attr = obj.__dict__.keys()
71                 except AttributeError:
72                         attr = dir(obj)
73                 else:
74                         if not attr: attr = dir(obj)
75                 
76                 for k in attr:
77                         try:
78                                 v = getattr(obj, k)
79                         except (AttributeError, TypeError): # Some attributes are not readable
80                                 pass
81                         else:
82                                 items.append((k, type_char(v)))
83         
84         if items != []:
85                 items.sort(cmp = suggest_cmp)
86                 txt.suggest(items, targets[-1])
87
88 # Check we are running as a script and not imported as a module
89 if __name__ == "__main__" and OK:
90         main()