Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Thompson <quornian@googlemail.com>2008-07-15 11:04:31 +0400
committerIan Thompson <quornian@googlemail.com>2008-07-15 11:04:31 +0400
commitdbb61988fdaa6085912dee6ab8f5569e63ef88fb (patch)
tree2b1334417dbe2536851bed215777f89e416b6007 /release
parent14c1ed08108df6178a55f6d7f818f19a926ae1df (diff)
Any script can now register a unique key combination as part of its bpy header. For a supported space type, the user may press this shortcut to invoke the script.
Space types that are to support shortcuts like this should call BPY_menu_do_shortcut(...) from the event queue read method (See winqreadtextspace in drawtext.c for example)
Diffstat (limited to 'release')
-rw-r--r--release/scripts/textplugin_suggest.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/release/scripts/textplugin_suggest.py b/release/scripts/textplugin_suggest.py
index 6bb703faa83..c4fce9ad7a9 100644
--- a/release/scripts/textplugin_suggest.py
+++ b/release/scripts/textplugin_suggest.py
@@ -3,6 +3,7 @@
Name: 'Suggest'
Blender: 243
Group: 'TextPlugin'
+Shortcut: 'Ctrl+Space'
Tooltip: 'Suggests completions for the word at the cursor in a python script'
"""
@@ -72,6 +73,70 @@ def getCompletionSymbols(txt):
return line[c-a:c].split('.')
+def getImports(txt):
+ imports = []
+
+ # Unfortunately, tokenize may fail if the script leaves brackets or strings
+ # open. For now we return an empty list until I have a better idea. Maybe
+ # parse manually.
+ try:
+ tokens = getTokens(txt)
+ except:
+ return []
+
+ for i in range(1, len(tokens)):
+
+ # Handle all import statements
+ if tokens[i-1][TK_TOKEN] == 'import':
+
+ # Find 'from' if it exists
+ fr = -1
+ for a in range(1, i):
+ if tokens[i-a][TK_TYPE] == token.NEWLINE: break
+ if tokens[i-a][TK_TOKEN] == 'from':
+ fr = i-a
+ break
+
+ # Handle: import ___[.___][,___[.___]]
+ if fr<0:
+ parent = ''
+
+ # Handle: from ___[.___] import ___[,___]
+ else: # fr>=0:
+ parent = ''.join([t[TK_TOKEN] for t in tokens[fr+1:i-1]])
+
+ module = ''
+ while i < len(tokens)-1:
+ if tokens[i][TK_TYPE] == token.NAME:
+
+ # Get the module name
+ module = module + tokens[i][TK_TOKEN]
+
+ if tokens[i+1][TK_TOKEN] == '.':
+ module += '.'
+ i += 1
+ else:
+ # Add the module name and parent to the dict
+ imports.append((module, parent))
+ module = ''
+
+ elif tokens[i][TK_TOKEN]!=',':
+ break
+
+ i += 1
+
+ # Process imports for: from ___ import *
+ for imp,frm in imports:
+ print imp, frm
+ if frm == '':
+ try: __import__(imp)
+ except: print '^ERR^'
+ else:
+ try: __import__(frm, globals(), locals(), [imp])
+ except: print '^ERR^'
+
+
+
# Returns a list of tuples of symbol names and their types (name, type) where
# type is one of:
# m (module/class) Has its own members (includes classes)