diff options
Diffstat (limited to 'release/scripts/op/console_python.py')
-rw-r--r--[-rwxr-xr-x] | release/scripts/op/console_python.py | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/release/scripts/op/console_python.py b/release/scripts/op/console_python.py index 81046322967..dc2a0a7713c 100755..100644 --- a/release/scripts/op/console_python.py +++ b/release/scripts/op/console_python.py @@ -26,6 +26,7 @@ language_id = 'python' # but python expects this in some places _BPY_MAIN_OWN = True + def add_scrollback(text, text_type): for l in text.split('\n'): bpy.ops.console.scrollback_append(text=l.replace('\t', ' '), @@ -77,13 +78,16 @@ def get_console(console_id): namespace = bpy_main_mod.__dict__ else: namespace = {} - + namespace["__builtins__"] = sys.modules["builtins"] namespace["bpy"] = bpy namespace["C"] = bpy.context console = InteractiveConsole(locals=namespace, filename="<blender_console>") - + + console.push("from mathutils import *") + console.push("from math import *") + if _BPY_MAIN_OWN: console._bpy_main_mod = bpy_main_mod @@ -109,9 +113,6 @@ def execute(context): except: return {'CANCELLED'} - if sc.console_type != 'PYTHON': - return {'CANCELLED'} - console, stdout, stderr = get_console(hash(context.region)) # redirect output @@ -127,7 +128,7 @@ def execute(context): sys.modules["__main__"] = console._bpy_main_mod # incase exception happens - line = "" # incase of encodingf error + line = "" # incase of encodingf error is_multiline = False try: @@ -160,6 +161,10 @@ def execute(context): stdout.truncate(0) stderr.truncate(0) + # special exception. its possible the command loaded a new user interface + if hash(sc) != hash(context.space_data): + return + bpy.ops.console.scrollback_append(text=sc.prompt + line, type='INPUT') if is_multiline: @@ -182,8 +187,14 @@ def execute(context): # restore the stdin sys.stdin = stdin_backup + # execute any hooks + for func, args in execute.hooks: + func(*args) + return {'FINISHED'} +execute.hooks = [] + def autocomplete(context): from console import intellisense @@ -195,9 +206,6 @@ def autocomplete(context): if not console: return {'CANCELLED'} - if sc.console_type != 'PYTHON': - return {'CANCELLED'} - # dont allow the stdin to be used, can lock blender. # note: unlikely stdin would be used for autocomp. but its possible. stdin_backup = sys.stdin @@ -256,14 +264,16 @@ def banner(context): sc = context.space_data version_string = sys.version.strip().replace('\n', ' ') - add_scrollback(" * Python Interactive Console %s *" % version_string, 'OUTPUT') - add_scrollback("Command History: Up/Down Arrow", 'OUTPUT') - add_scrollback("Cursor: Left/Right Home/End", 'OUTPUT') - add_scrollback("Remove: Backspace/Delete", 'OUTPUT') - add_scrollback("Execute: Enter", 'OUTPUT') - add_scrollback("Autocomplete: Ctrl+Space", 'OUTPUT') - add_scrollback("Ctrl +/- Wheel: Zoom", 'OUTPUT') - add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bgl, blf, mathutils, geometry", 'OUTPUT') + add_scrollback("PYTHON INTERACTIVE CONSOLE %s" % version_string, 'OUTPUT') + add_scrollback("", 'OUTPUT') + add_scrollback("Command History: Up/Down Arrow", 'OUTPUT') + add_scrollback("Cursor: Left/Right Home/End", 'OUTPUT') + add_scrollback("Remove: Backspace/Delete", 'OUTPUT') + add_scrollback("Execute: Enter", 'OUTPUT') + add_scrollback("Autocomplete: Ctrl+Space", 'OUTPUT') + add_scrollback("Ctrl +/- Wheel: Zoom", 'OUTPUT') + add_scrollback("Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bgl, blf, mathutils", 'OUTPUT') + add_scrollback("Convenience Imports: from mathutils import *; from math import *", 'OUTPUT') add_scrollback("", 'OUTPUT') add_scrollback(" WARNING!!! Blender 2.5 API is subject to change, see API reference for more info.", 'ERROR') add_scrollback("", 'OUTPUT') |