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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!BPY
"""
Name: 'Suggest All | Ctrl Space'
Blender: 246
Group: 'TextPlugin'
Shortcut: 'Ctrl+Space'
Tooltip: 'Performs suggestions based on the context of the cursor'
"""
# Only run if we have the required modules
try:
import bpy
from BPyTextPlugin import *
except ImportError:
OK = False
else:
OK = True
def check_membersuggest(line, c):
pos = line.rfind('.', 0, c)
if pos == -1:
return False
for s in line[pos+1:c]:
if not s.isalnum() and s != '_':
return False
return True
def check_imports(line, c):
pos = line.rfind('import ', 0, c)
if pos > -1:
for s in line[pos+7:c]:
if not s.isalnum() and s != '_':
return False
return True
pos = line.rfind('from ', 0, c)
if pos > -1:
for s in line[pos+5:c]:
if not s.isalnum() and s != '_':
return False
return True
return 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) != CTX_NORMAL:
return
# Check the character preceding the cursor and execute the corresponding script
if check_membersuggest(line, c):
import textplugin_membersuggest
textplugin_membersuggest.main()
return
elif check_imports(line, c):
import textplugin_imports
textplugin_imports.main()
return
# Otherwise we suggest globals, keywords, etc.
list = []
targets = get_targets(line, c)
desc = get_cached_descriptor(txt)
for k in KEYWORDS:
list.append((k, 'k'))
for k, v in get_builtins().items():
list.append((k, type_char(v)))
for k, v in desc.imports.items():
list.append((k, type_char(v)))
for k, v in desc.classes.items():
list.append((k, 'f'))
for k, v in desc.defs.items():
list.append((k, 'f'))
for k, v in desc.vars.items():
list.append((k, 'v'))
list.sort(cmp = suggest_cmp)
txt.suggest(list, targets[-1])
# Check we are running as a script and not imported as a module
if __name__ == "__main__" and OK:
main()
|