copy as script operator for the console, so you can copy input from a console for use in a textblock.
This commit is contained in:
@@ -290,6 +290,40 @@ def autocomplete(context):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
def copy_as_script(context):
|
||||||
|
sc = context.space_data
|
||||||
|
lines = [
|
||||||
|
"import bpy",
|
||||||
|
"import bpy.context as C",
|
||||||
|
"import bpy.data as D",
|
||||||
|
"from mathutils import *",
|
||||||
|
"from math import *",
|
||||||
|
"",
|
||||||
|
]
|
||||||
|
|
||||||
|
for line in sc.scrollback:
|
||||||
|
text = line.body
|
||||||
|
type = line.type
|
||||||
|
|
||||||
|
if type == 'INFO': # ignore autocomp.
|
||||||
|
continue
|
||||||
|
if type == 'INPUT':
|
||||||
|
if text.startswith(PROMPT):
|
||||||
|
text = text[len(PROMPT):]
|
||||||
|
elif text.startswith(PROMPT_MULTI):
|
||||||
|
text = text[len(PROMPT_MULTI):]
|
||||||
|
elif type == 'OUTPUT':
|
||||||
|
text = "#~ " + text
|
||||||
|
elif type == 'ERROR':
|
||||||
|
text = "#! " + text
|
||||||
|
|
||||||
|
lines.append(text)
|
||||||
|
|
||||||
|
context.window_manager.clipboard = "\n".join(lines)
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
def banner(context):
|
def banner(context):
|
||||||
sc = context.space_data
|
sc = context.space_data
|
||||||
version_string = sys.version.strip().replace('\n', ' ')
|
version_string = sys.version.strip().replace('\n', ' ')
|
||||||
|
|||||||
@@ -67,6 +67,25 @@ class ConsoleAutocomplete(Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleCopyAsScript(Operator):
|
||||||
|
"""Copy the console contents for use in a script"""
|
||||||
|
bl_idname = "console.copy_as_script"
|
||||||
|
bl_label = "Copy to Clipboard (as script)"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
sc = context.space_data
|
||||||
|
|
||||||
|
module = _lang_module_get(sc)
|
||||||
|
copy_as_script = getattr(module, "copy_as_script", None)
|
||||||
|
|
||||||
|
if copy_as_script:
|
||||||
|
return copy_as_script(context)
|
||||||
|
else:
|
||||||
|
print("Error: copy_as_script - not found for %r" %
|
||||||
|
sc.language)
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
class ConsoleBanner(Operator):
|
class ConsoleBanner(Operator):
|
||||||
"""Print a message when the terminal initializes"""
|
"""Print a message when the terminal initializes"""
|
||||||
bl_idname = "console.banner"
|
bl_idname = "console.banner"
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class CONSOLE_MT_console(Menu):
|
|||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
|
|
||||||
|
layout.operator("console.copy_as_script")
|
||||||
layout.operator("console.copy")
|
layout.operator("console.copy")
|
||||||
layout.operator("console.paste")
|
layout.operator("console.paste")
|
||||||
layout.menu("CONSOLE_MT_language")
|
layout.menu("CONSOLE_MT_language")
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ static void console_keymap(struct wmKeyConfig *keyconf)
|
|||||||
WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */
|
WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
WM_keymap_add_item(keymap, "CONSOLE_OT_copy_as_script", CKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
|
||||||
WM_keymap_add_item(keymap, "CONSOLE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
|
WM_keymap_add_item(keymap, "CONSOLE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
|
||||||
WM_keymap_add_item(keymap, "CONSOLE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
|
WM_keymap_add_item(keymap, "CONSOLE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|||||||
@@ -2656,6 +2656,14 @@ static void rna_def_space_time(BlenderRNA *brna)
|
|||||||
|
|
||||||
static void rna_def_console_line(BlenderRNA *brna)
|
static void rna_def_console_line(BlenderRNA *brna)
|
||||||
{
|
{
|
||||||
|
static EnumPropertyItem console_line_type_items[] = {
|
||||||
|
{CONSOLE_LINE_OUTPUT, "OUTPUT", 0, "Output", ""},
|
||||||
|
{CONSOLE_LINE_INPUT, "INPUT", 0, "Input", ""},
|
||||||
|
{CONSOLE_LINE_INFO, "INFO", 0, "Info", ""},
|
||||||
|
{CONSOLE_LINE_ERROR, "ERROR", 0, "Error", ""},
|
||||||
|
{0, NULL, 0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
StructRNA *srna;
|
StructRNA *srna;
|
||||||
PropertyRNA *prop;
|
PropertyRNA *prop;
|
||||||
|
|
||||||
@@ -2673,6 +2681,11 @@ static void rna_def_console_line(BlenderRNA *brna)
|
|||||||
RNA_def_property_int_sdna(prop, NULL, "cursor");
|
RNA_def_property_int_sdna(prop, NULL, "cursor");
|
||||||
RNA_def_property_int_funcs(prop, NULL, NULL, "rna_ConsoleLine_cursor_index_range");
|
RNA_def_property_int_funcs(prop, NULL, NULL, "rna_ConsoleLine_cursor_index_range");
|
||||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CONSOLE, NULL);
|
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CONSOLE, NULL);
|
||||||
|
|
||||||
|
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
|
||||||
|
RNA_def_property_enum_sdna(prop, NULL, "type");
|
||||||
|
RNA_def_property_enum_items(prop, console_line_type_items);
|
||||||
|
RNA_def_property_ui_text(prop, "Type", "Console line type when used in scrollback");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rna_def_space_console(BlenderRNA *brna)
|
static void rna_def_space_console(BlenderRNA *brna)
|
||||||
|
|||||||
Reference in New Issue
Block a user