예제 #1
0
def complete(context):
    from console import intellisense
    from console_python import get_console

    sc = context.space_data
    text = sc.text

    region = context.region
    for area in context.screen.areas:
        if area.type == "CONSOLE":
            region = area.regions[1]
            break

    console = get_console(hash(region))[0]

    line = text.current_line.body
    cursor = text.current_character

    result = intellisense.expand(line, cursor, console.locals, bpy.app.debug)

    return result
예제 #2
0
def complete(context):
	from console import intellisense
	from console_python import get_console
	
	sc = context.space_data
	text = sc.text
	
	region = context.region
	for area in context.screen.areas:
		if area.type=="CONSOLE":
			region = area.regions[1]
			break
	
	console = get_console(hash(region))[0]

	line = text.current_line.body
	cursor = text.current_character
	
	result  = intellisense.expand(line, cursor, console.locals, bpy.app.debug)
	
	return result
예제 #3
0
def autocomplete(context):
    from console import intellisense

    sc = context.space_data

    console = get_console(hash(context.region))[0]

    if not console:
        return {'CANCELLED'}

    # don't allow the stdin to be used, can lock blender.
    # note: unlikely stdin would be used for autocomplete. but its possible.
    stdin_backup = sys.stdin
    sys.stdin = None

    scrollback = ""
    scrollback_error = ""

    if _BPY_MAIN_OWN:
        main_mod_back = sys.modules["__main__"]
        sys.modules["__main__"] = console._bpy_main_mod

    try:
        current_line = sc.history[-1]
        line = current_line.body

        # This function isn't aware of the text editor or being an operator
        # just does the autocomplete then copy its results back
        result = intellisense.expand(
                line=line,
                cursor=current_line.current_character,
                namespace=console.locals,
                private=bpy.app.debug_python)

        line_new = result[0]
        current_line.body, current_line.current_character, scrollback = result
        del result

        # update selection. setting body should really do this!
        ofs = len(line_new) - len(line)
        sc.select_start += ofs
        sc.select_end += ofs
    except:
        # unlikely, but this can happen with unicode errors for example.
        # or if the api attribute access its self causes an error.
        import traceback
        scrollback_error = traceback.format_exc()

    if _BPY_MAIN_OWN:
        sys.modules["__main__"] = main_mod_back

    # Separate autocomplete output by command prompts
    if scrollback != '':
        bpy.ops.console.scrollback_append(text=sc.prompt + current_line.body,
                                          type='INPUT')

    # Now we need to copy back the line from blender back into the
    # text editor. This will change when we don't use the text editor
    # anymore
    if scrollback:
        add_scrollback(scrollback, 'INFO')

    if scrollback_error:
        add_scrollback(scrollback_error, 'ERROR')

    # restore the stdin
    sys.stdin = stdin_backup

    context.area.tag_redraw()

    return {'FINISHED'}