Beispiel #1
0
def console_namespace():
    import console_python
    for window in bpy.context.window_manager.windows:
        for area in window.screen.areas:
            if area.type == 'CONSOLE':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        console = console_python.get_console(hash(region))
                        if console:
                            return console[0].locals
    return {}
    def execute(self, context):
        # print("test line")

        # send_console(context, self.all)
        sc = context.space_data
        text = sc.text

        if not text:
            self.report({'WARNING'},
                        "No Text-Block active. Operation Cancelled")

            return {"CANCELLED"}

        line = text.current_line.body
        console = None

        for area in bpy.context.screen.areas:
            if area.type == "CONSOLE":
                from console_python import get_console

                console = get_console(hash(area.regions[1]))[0]

        if console is None:
            return {'FINISHED'}

        command = ""

        forindex = line.find("for ")
        if forindex > -1:

            var = line[forindex + 4: -1]
            var = var[0: var.find(" ")]
            state = line[line.rindex(" ") + 1: -1]

            command = var + " = " + state + "[0]"

        else:
            command = line

        # print(command)
        try:
            console.push(command)
        except:
            pass

        bpy.ops.text.line_break()

        return {'FINISHED'}
    def execute(self, context):
        # print("test line")

        # send_console(context, self.all)
        sc = context.space_data
        text = sc.text

        if not text:
            self.report({'WARNING'},
                        "No Text-Block active. Operation Cancelled")

            return {"CANCELLED"}

        line = text.current_line.body
        console = None

        for area in bpy.context.screen.areas:
            if area.type == "CONSOLE":
                from console_python import get_console

                console = get_console(hash(area.regions[1]))[0]

        if console is None:
            return {'FINISHED'}

        command = ""

        forindex = line.find("for ")
        if forindex > -1:

            var = line[forindex + 4:-1]
            var = var[0:var.find(" ")]
            state = line[line.rindex(" ") + 1:-1]

            command = var + " = " + state + "[0]"

        else:
            command = line

        # print(command)
        try:
            console.push(command)
        except:
            pass

        bpy.ops.text.line_break()

        return {'FINISHED'}
    def reload_script(self, context):
        """Reload this script while printing the output to blenders python console."""

        # Setup stdout and stderr.
        stdout = SplitIO(sys.stdout)
        stderr = SplitIO(sys.stderr)

        sys.stdout = stdout
        sys.stderr = stderr

        # Run the script.
        self._reload_script_module()

        # Go back to the begining so we can read the streams.
        stdout.seek(0)
        stderr.seek(0)

        # Don't use readlines because that leaves trailing new lines.
        output = stdout.read().split('\n')
        output_err = stderr.read().split('\n')

        for console in context.screen.sw_consoles:
            if console.active and isnum(
                    console.name):  # Make sure it's not some random string.

                console, _, _ = console_python.get_console(int(console.name))

                # Set the locals to the modules dict.
                console.locals = sys.modules[self.get_mod_name()[0]].__dict__

        if self.use_py_console:
            # Print the output to the consoles.
            for area in context.screen.areas:
                if area.type == "CONSOLE":
                    ctx = context.copy()
                    ctx.update({"area": area})

                    # Actually print the output.
                    if output:
                        add_scrollback(ctx, output, 'OUTPUT')

                    if output_err:
                        add_scrollback(ctx, output_err, 'ERROR')

        # Cleanup
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
    def reload_script(self, context):
        """Reload this script while printing the output to blenders python console."""

        # Setup stdout and stderr.
        stdout = SplitIO(sys.stdout)
        stderr = SplitIO(sys.stderr)

        sys.stdout = stdout
        sys.stderr = stderr

        # Run the script.
        self._reload_script_module()

        # Go back to the begining so we can read the streams.
        stdout.seek(0)
        stderr.seek(0)

        # Don't use readlines because that leaves trailing new lines.
        output = stdout.read().split('\n')
        output_err = stderr.read().split('\n')

        for console in context.screen.sw_consoles:
            if console.active and isnum(console.name):  # Make sure it's not some random string.

                console, _, _ = console_python.get_console(int(console.name))

                # Set the locals to the modules dict.
                console.locals = sys.modules[self.get_mod_name()[0]].__dict__

        if self.use_py_console:
            # Print the output to the consoles.
            for area in context.screen.areas:
                if area.type == "CONSOLE":
                    ctx = context.copy()
                    ctx.update({"area": area})

                    # Actually print the output.
                    if output:
                        add_scrollback(ctx, output, 'OUTPUT')

                    if output_err:
                        add_scrollback(ctx, output_err, 'ERROR')

        # Cleanup
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
def update_debug(self, context):
    console_id = get_console_id(context.area)

    console, _, _ = console_python.get_console(console_id)

    if self.active:
        console.globals = console.locals

        if context.scene.sw_settings.running:
            dir, mod = os.path.split(bpy.path.abspath(context.scene.sw_settings.filepath))

            # XXX This is almost the same as get_mod_name so it should become a global function.
            if mod == '__init__.py':
                mod = os.path.basename(dir)
            else:
                mod = os.path.splitext(mod)[0]

            console.locals = sys.modules[mod].__dict__

    else:
        console.locals = console.globals
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
Beispiel #8
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
def send_console(context, alls=0):

    sc = context.space_data
    text = sc.text

    console = None

    for area in bpy.context.screen.areas:
        if area.type == "CONSOLE":
            from console_python import get_console

            console = get_console(hash(area.regions[1]))[0]

    if console is None:
        return {'FINISHED'}

    if alls:
        for l in text.lines:
            console.push(l.body)
    else:
        # print(console.prompt)
        console.push(text.current_line.body)
def send_console(context, alls=0):

    sc = context.space_data
    text = sc.text

    console = None

    for area in bpy.context.screen.areas:
        if area.type == "CONSOLE":
            from console_python import get_console

            console = get_console(hash(area.regions[1]))[0]

    if console is None:
        return {'FINISHED'}

    if alls:
        for l in text.lines:
            console.push(l.body)
    else:
        # print(console.prompt)
        console.push(text.current_line.body)
def in_core_dev_commands(context, m):

    if m.endswith('??'):

        m = m[:-2]
        console, stdout, stderr = get_console(hash(context.region))

        if m in console.locals.keys():
            f = str(dir(console.locals[m]))
        else:
            try:
                f = str(eval('dir({0})'.format(m)))
            except:
                f = 'failed to find reference..'

        add_scrollback(f, 'OUTPUT')

    elif m.endswith('!'):
        '''copy current line to clipboard'''
        m = m[:-1]
        context.window_manager.clipboard = m
        add_scrollback('added to clipboard', 'OUTPUT')

    elif m == 'ico':
        try:
            bpy.ops.wm.addon_enable(module="development_icon_get")
            add_scrollback('added icons to TextEditor', 'OUTPUT')
        except:
            self.report({'INFO'}, "ico addon not present!")

    elif m == '-keys':
        write_keys_textfile()

    elif m == 'syntax':
        do_text_glam()

    elif m in {'syntax lt', 'syntax dk'}:
        do_text_glam()
        theme = m.split()[1]
        print('theme', theme)
        do_text_synthax(theme)

    elif m.startswith('-gist '):
        # will not upload duplicates of the same file, placed in Set first.

        if m == '-gist -o':
            # send all visible, unnamed.
            pass

        if m.startswith('-gist -o '):
            # like:  "-gist -o test_gist"
            # send all visible, try naming it.
            gname = m[9:].strip()
            gname = gname.replace(' ', '_')
            file_names = find_filenames()
            to_gist(file_names, project_name=gname, public_switch=True)

    elif m.startswith('-sel -t '):
        # starting2 not implemented yet
        # accepts:
        # '-sel -t CU CurveObj56'
        # '-sel -t CU CurveObj 56'
        # '-sel -t CURVE CurveObj 56'
        _type, *find_str = m[8:].split()
        select_starting2(' '.join(find_str), _type)

    elif m.startswith('-sel '):
        find_str = m[5:]
        select_starting(find_str)

    elif m == "-man":
        throw_manual()

    elif m == '-gh':
        import os
        import subprocess
        _root = os.path.dirname(__file__)
        f = [os.path.join(_root, 'tmp', 'github_start.bat')]
        subprocess.call(f)

    elif m == 'bl<':
        view_types_to_console()

    elif m.startswith("!"):
        ''' dispatch a threaded worker '''
        cmd_controller(m[1:])

    elif m.startswith('obj=') or m.startswith('n='):
        do_console_rewriter(context, m)

    elif m == 'git help':
        git_strings = (
            "git pull (--all)", "git push (--all)", "git add (--all)",
            "git add <specify file>  # do this from inside the right directory",
            "git commit -am \"commit message here\"",
            "git checkout -b <branch_name>  # new_branch_name_based_on_current_branch",
            "git branch -D <branch_name> # deletes branch locally (you must be on a different branch first)",
            "git branch", "   ", "-- be in master, or branch to merge into",
            "   git merge <branch_to_merge>", "   git push --all", "   ",
            "   ", "To reset unstaged things..:", "  git fetch origin",
            "  git reset --hard origin/master", "  git clean -f")
        for line in git_strings:
            add_scrollback(line, 'OUTPUT')

    else:
        return False

    return True
def in_core_dev_commands(context, m):

    if m.endswith("??"):

        m = m[:-2]
        console, stdout, stderr = get_console(hash(context.region))

        if m in console.locals.keys():
            f = str(dir(console.locals[m]))
        else:
            try:
                f = str(eval("dir({0})".format(m)))
            except:
                f = "failed to find reference.."

        add_scrollback(f, "OUTPUT")

    elif m.endswith("!"):
        """copy current line to clipboard"""
        m = m[:-1]
        context.window_manager.clipboard = m
        add_scrollback("added to clipboard", "OUTPUT")

    elif m == "ico":
        try:
            bpy.ops.wm.addon_enable(module="development_icon_get")
            add_scrollback("added icons to TextEditor", "OUTPUT")
        except:
            self.report({"INFO"}, "ico addon not present!")

    elif m == "-keys":
        write_keys_textfile()

    elif m == "syntax":
        do_text_glam()

    elif m in {"syntax lt", "syntax dk"}:
        do_text_glam()
        theme = m.split()[1]
        print("theme", theme)
        do_text_synthax(theme)

    elif m.startswith("-gist "):
        # will not upload duplicates of the same file, placed in Set first.

        if m == "-gist -o":
            # send all visible, unnamed.
            pass

        if m.startswith("-gist -o "):
            # like:  "-gist -o test_gist"
            # send all visible, try naming it.
            gname = m[9:].strip()
            gname = gname.replace(" ", "_")
            file_names = find_filenames()
            to_gist(file_names, project_name=gname, public_switch=True)

    elif m.startswith("-sel -t "):
        # starting2 not implemented yet
        # accepts:
        # '-sel -t CU CurveObj56'
        # '-sel -t CU CurveObj 56'
        # '-sel -t CURVE CurveObj 56'
        _type, *find_str = m[8:].split()
        select_starting2(" ".join(find_str), _type)

    elif m.startswith("-sel "):
        find_str = m[5:]
        select_starting(find_str)

    elif m == "-man":
        throw_manual()

    elif m == "-gh":
        import os
        import subprocess

        _root = os.path.dirname(__file__)
        f = [os.path.join(_root, "tmp", "github_start.bat")]
        subprocess.call(f)

    elif m == "bl<":
        view_types_to_console()

    elif m.startswith("!"):
        """ dispatch a threaded worker """
        cmd_controller(m[1:])

    elif m.startswith("obj=") or m.startswith("n="):
        do_console_rewriter(context, m)

    elif m == "git help":
        git_strings = (
            "git pull (--all)",
            "git push (--all)",
            "git add (--all)",
            "git add <specify file>  # do this from inside the right directory",
            'git commit -am "commit message here"',
            "git checkout -b <branch_name>  # new_branch_name_based_on_current_branch",
            "git branch -D <branch_name> # deletes branch locally (you must be on a different branch first)",
            "git branch",
            "   ",
            "-- be in master, or branch to merge into",
            "   git merge <branch_to_merge>",
            "   git push --all",
            "   ",
            "   ",
            "To reset unstaged things..:",
            "  git fetch origin",
            "  git reset --hard origin/master",
            "  git clean -f",
        )
        for line in git_strings:
            add_scrollback(line, "OUTPUT")

    else:
        return False

    return True
def in_core_dev_commands(context, m):

    if m.endswith('??'):

        m = m[:-2]
        console, stdout, stderr = get_console(hash(context.region))

        if m in console.locals.keys():
            f = str(dir(console.locals[m]))
        else:
            try:
                f = str(eval('dir({0})'.format(m)))
            except:
                f = 'failed to find reference..'

        add_scrollback(f, 'OUTPUT')

    elif m.endswith('!'):
        '''copy current line to clipboard'''
        m = m[:-1]
        context.window_manager.clipboard = m
        add_scrollback('added to clipboard', 'OUTPUT')

    elif m == 'ico':
        try:
            bpy.ops.wm.addon_enable(module="development_icon_get")
            add_scrollback('added icons to TextEditor', 'OUTPUT')
        except:
            self.report({'INFO'}, "ico addon not present!")

    elif m == '-keys':
        write_keys_textfile()

    elif m == 'syntax':
        do_text_glam()

    elif m in {'syntax lt', 'syntax dk'}:
        do_text_glam()
        theme = m.split()[1]
        print('theme', theme)
        do_text_synthax(theme)

    elif m.startswith('-gist '):
        # will not upload duplicates of the same file, placed in Set first.

        if m == '-gist -o':
            # send all visible, unnamed.
            pass

        if m.startswith('-gist -o '):
            # like:  "-gist -o test_gist"
            # send all visible, try naming it.
            gname = m[9:].strip()
            gname = gname.replace(' ', '_')
            file_names = find_filenames()
            to_gist(file_names, project_name=gname, public_switch=True)

    elif m.startswith('-sel -t '):
        # starting2 not implemented yet
        # accepts:
        # '-sel -t CU CurveObj56'
        # '-sel -t CU CurveObj 56'
        # '-sel -t CURVE CurveObj 56'
        _type, *find_str = m[8:].split()
        select_starting2(' '.join(find_str), _type)

    elif m.startswith('-sel '):
        find_str = m[5:]
        select_starting(find_str)

    elif m == "-man":
        throw_manual()

    elif m == '-gh':
        import os
        import subprocess
        _root = os.path.dirname(__file__)
        f = [os.path.join(_root, 'tmp', 'github_start.bat')]
        subprocess.call(f)

    elif m == 'bl<':
        view_types_to_console()

    elif m.startswith("!"):
        ''' dispatch a threaded worker '''
        cmd_controller(m[1:])

    else:
        return False

    return True
Beispiel #14
0
def get_bl_console():
    from console_python import get_console
    region_hash = hash(c_dict['region'])
    con, out, err = get_console(region_hash)
    return con
Beispiel #15
0
def in_core_dev_commands(context, m):

    if m.endswith('??'):

        m = m[:-2]
        console, stdout, stderr = get_console(hash(context.region))

        if m in console.locals.keys():
            f = str(dir(console.locals[m]))
        else:
            try:
                f = str(eval('dir({0})'.format(m)))
            except:
                f = 'failed to find reference..'

        add_scrollback(f, 'OUTPUT')

    elif m.endswith('!'):
        '''copy current line to clipboard'''
        m = m[:-1]
        context.window_manager.clipboard = m
        add_scrollback('added to clipboard', 'OUTPUT')

    elif m == 'ico':
        try:
            bpy.ops.wm.addon_enable(module="development_icon_get")
            add_scrollback('added icons to TextEditor', 'OUTPUT')
        except:
            self.report({'INFO'}, "ico addon not present!")

    elif m == '-keys':
        write_keys_textfile()

    elif m == 'syntax':
        do_text_glam()

    elif m in {'syntax lt', 'syntax dk'}:
        do_text_glam()
        theme = m.split()[1]
        print('theme', theme)
        do_text_synthax(theme)

    elif m.startswith('-gist '):
        # will not upload duplicates of the same file, placed in Set first.

        if m == '-gist -o':
            # send all visible, unnamed.
            pass

        if m.startswith('-gist -o '):
            # like:  "-gist -o test_gist"
            # send all visible, try naming it.
            gname = m[9:].strip()
            gname = gname.replace(' ', '_')
            file_names = find_filenames()
            to_gist(file_names, project_name=gname, public_switch=True)

    elif m.startswith('-sel -t '):
        # starting2 not implemented yet
        # accepts:
        # '-sel -t CU CurveObj56'
        # '-sel -t CU CurveObj 56'
        # '-sel -t CURVE CurveObj 56'
        _type, *find_str = m[8:].split()
        select_starting2(' '.join(find_str), _type)

    elif m.startswith('-sel '):
        find_str = m[5:]
        select_starting(find_str)

    elif m == "-man":
        throw_manual()

    elif m == '-gh':
        import os
        import subprocess
        _root = os.path.dirname(__file__)
        f = [os.path.join(_root, 'tmp', 'github_start.bat')]
        subprocess.call(f)

    elif m == 'bl<':
        view_types_to_console()

    elif m.startswith("!"):
        ''' dispatch a threaded worker '''
        cmd_controller(m[1:])

    else:
        return False

    return True