forked from bartvdbraak/blender
- added bpy.context to the python module
- made the console banner printing function into a python operator (includes sys.version) - added 'C' into the consoles default namespace for convenience
This commit is contained in:
parent
cacd68c335
commit
247f72fcc0
@ -127,7 +127,7 @@ def get_console(console_id):
|
|||||||
return console, stdout, stderr
|
return console, stdout, stderr
|
||||||
|
|
||||||
|
|
||||||
class CONSOLE_OT_exec(bpy.types.Operator):
|
class ConsoleExec(bpy.types.Operator):
|
||||||
'''Execute the current console line as a python expression.'''
|
'''Execute the current console line as a python expression.'''
|
||||||
bl_idname = "console.execute"
|
bl_idname = "console.execute"
|
||||||
bl_label = "Console Execute"
|
bl_label = "Console Execute"
|
||||||
@ -210,7 +210,7 @@ class CONSOLE_OT_exec(bpy.types.Operator):
|
|||||||
return ('FINISHED',)
|
return ('FINISHED',)
|
||||||
|
|
||||||
|
|
||||||
class CONSOLE_OT_autocomplete(bpy.types.Operator):
|
class ConsoleAutocomplete(bpy.types.Operator):
|
||||||
'''Evaluate the namespace up until the cursor and give a list of
|
'''Evaluate the namespace up until the cursor and give a list of
|
||||||
options or complete the name if there is only one.'''
|
options or complete the name if there is only one.'''
|
||||||
bl_idname = "console.autocomplete"
|
bl_idname = "console.autocomplete"
|
||||||
@ -256,9 +256,36 @@ class CONSOLE_OT_autocomplete(bpy.types.Operator):
|
|||||||
return ('FINISHED',)
|
return ('FINISHED',)
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleBanner(bpy.types.Operator):
|
||||||
|
bl_idname = "console.banner"
|
||||||
|
|
||||||
|
def execute(self, 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, Mathutils, Geometry, BGL", 'OUTPUT')
|
||||||
|
add_scrollback("", 'OUTPUT')
|
||||||
|
add_scrollback("", 'OUTPUT')
|
||||||
|
sc.prompt = ConsoleExec.PROMPT
|
||||||
|
|
||||||
|
# Add context into the namespace for quick access
|
||||||
|
console = get_console(hash(context.region))[0]
|
||||||
|
console.locals["C"] = bpy.context
|
||||||
|
|
||||||
|
return ('FINISHED',)
|
||||||
|
|
||||||
|
|
||||||
bpy.types.register(CONSOLE_HT_header)
|
bpy.types.register(CONSOLE_HT_header)
|
||||||
bpy.types.register(CONSOLE_MT_console)
|
bpy.types.register(CONSOLE_MT_console)
|
||||||
bpy.types.register(CONSOLE_MT_report)
|
bpy.types.register(CONSOLE_MT_report)
|
||||||
|
|
||||||
bpy.ops.add(CONSOLE_OT_exec)
|
bpy.ops.add(ConsoleExec)
|
||||||
bpy.ops.add(CONSOLE_OT_autocomplete)
|
bpy.ops.add(ConsoleAutocomplete)
|
||||||
|
bpy.ops.add(ConsoleBanner)
|
||||||
|
@ -164,20 +164,8 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
|
|||||||
View2DScrollers *scrollers;
|
View2DScrollers *scrollers;
|
||||||
//float col[3];
|
//float col[3];
|
||||||
|
|
||||||
/* add helper text, why not? */
|
if(sc->scrollback.first==NULL)
|
||||||
if(sc->scrollback.first==NULL) {
|
WM_operator_name_call((bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, NULL);
|
||||||
console_scrollback_add_str(C, " * Python Interactive Console *", 0);
|
|
||||||
console_scrollback_add_str(C, "Command History: Up/Down Arrow", 0);
|
|
||||||
console_scrollback_add_str(C, "Cursor: Left/Right Home/End", 0);
|
|
||||||
console_scrollback_add_str(C, "Remove: Backspace/Delete", 0);
|
|
||||||
console_scrollback_add_str(C, "Execute: Enter", 0);
|
|
||||||
console_scrollback_add_str(C, "Autocomplete: Ctrl+Space", 0);
|
|
||||||
console_scrollback_add_str(C, "Ctrl +/- Wheel: Zoom", 0);
|
|
||||||
console_scrollback_add_str(C, "Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.ui", 0);
|
|
||||||
|
|
||||||
/* This is normally set by python but to start with its easier just to set it like this rather then running python with no args */
|
|
||||||
strcpy(sc->prompt, ">>> ");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clear and setup matrix */
|
/* clear and setup matrix */
|
||||||
//UI_GetThemeColor3fv(TH_BACK, col);
|
//UI_GetThemeColor3fv(TH_BACK, col);
|
||||||
|
@ -101,8 +101,6 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
|
|||||||
|
|
||||||
if(py_call_level==1) {
|
if(py_call_level==1) {
|
||||||
|
|
||||||
BPY_update_modules(); /* can give really bad results if this isnt here */
|
|
||||||
|
|
||||||
if(C) { // XXX - should always be true.
|
if(C) { // XXX - should always be true.
|
||||||
BPy_SetContext(C);
|
BPy_SetContext(C);
|
||||||
bpy_import_main_set(CTX_data_main(C));
|
bpy_import_main_set(CTX_data_main(C));
|
||||||
@ -111,6 +109,8 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
|
|||||||
fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n");
|
fprintf(stderr, "ERROR: Python context called with a NULL Context. this should not happen!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BPY_update_modules(); /* can give really bad results if this isnt here */
|
||||||
|
|
||||||
#ifdef TIME_PY_RUN
|
#ifdef TIME_PY_RUN
|
||||||
if(bpy_timer_count==0) {
|
if(bpy_timer_count==0) {
|
||||||
/* record time from the beginning */
|
/* record time from the beginning */
|
||||||
@ -171,6 +171,7 @@ void BPY_free_compiled_text( struct Text *text )
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Description: Creates the bpy module and adds it to sys.modules for importing
|
* Description: Creates the bpy module and adds it to sys.modules for importing
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
static BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
|
||||||
static void bpy_init_modules( void )
|
static void bpy_init_modules( void )
|
||||||
{
|
{
|
||||||
PyObject *mod;
|
PyObject *mod;
|
||||||
@ -204,6 +205,15 @@ static void bpy_init_modules( void )
|
|||||||
bpy_import_test("bpy_ext"); /* extensions to our existing types */
|
bpy_import_test("bpy_ext"); /* extensions to our existing types */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* bpy context */
|
||||||
|
{
|
||||||
|
bpy_context_module= ( BPy_StructRNA * ) PyObject_NEW( BPy_StructRNA, &pyrna_struct_Type );
|
||||||
|
RNA_pointer_create(NULL, &RNA_Context, NULL, &bpy_context_module->ptr);
|
||||||
|
|
||||||
|
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* stand alone utility modules not related to blender directly */
|
/* stand alone utility modules not related to blender directly */
|
||||||
Geometry_Init();
|
Geometry_Init();
|
||||||
Mathutils_Init();
|
Mathutils_Init();
|
||||||
@ -220,7 +230,7 @@ void BPY_update_modules( void )
|
|||||||
|
|
||||||
/* refreshes the main struct */
|
/* refreshes the main struct */
|
||||||
BPY_update_rna_module();
|
BPY_update_rna_module();
|
||||||
|
bpy_context_module->ptr.data= (void *)BPy_GetContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
Loading…
Reference in New Issue
Block a user