This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/release/scripts/textplugin_suggest.py
Ian Thompson 6352cd509e BPyTextPlugin now has descriptors for variables, functions and classes (and their variables/functions). Each descriptor also holds the line number of the definition allowing a simple outliner to be written.
Text.setCursorPos(row, col) now pops the text into view if it is in the active window space. The outliner uses this to jump to any definition in a script; it is invoked with Ctrl+T.
2008-07-21 00:38:42 +00:00

82 lines
1.6 KiB
Python

#!BPY
"""
Name: 'Suggest All'
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 *
OK = True
except ImportError:
OK = False
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 not s == '_':
return False
return True
def check_imports(line, c):
if c >= 7 and line.rfind('import ', 0, c) == c-7:
return True
if c >= 5 and line.rfind('from ', 0, c) == c-5:
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 = []
pre = get_targets(line, c)
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 get_imports(txt).items():
list.append((k, type_char(v)))
for k, v in get_defs(txt).items():
list.append((k, 'f'))
for k in get_vars(txt):
list.append((k, 'v'))
list.sort(cmp = suggest_cmp)
txt.suggest(list, pre[-1])
# Check we are running as a script and not imported as a module
if __name__ == "__main__" and OK:
main()