[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24346] trunk/blender: - added bpy. context to the python module
Campbell Barton
ideasman42 at gmail.com
Thu Nov 5 12:17:09 CET 2009
Revision: 24346
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24346
Author: campbellbarton
Date: 2009-11-05 12:17:09 +0100 (Thu, 05 Nov 2009)
Log Message:
-----------
- 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
Modified Paths:
--------------
trunk/blender/release/scripts/ui/space_console.py
trunk/blender/source/blender/editors/space_console/space_console.c
trunk/blender/source/blender/python/intern/bpy_interface.c
Modified: trunk/blender/release/scripts/ui/space_console.py
===================================================================
--- trunk/blender/release/scripts/ui/space_console.py 2009-11-05 10:50:58 UTC (rev 24345)
+++ trunk/blender/release/scripts/ui/space_console.py 2009-11-05 11:17:09 UTC (rev 24346)
@@ -127,7 +127,7 @@
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.'''
bl_idname = "console.execute"
bl_label = "Console Execute"
@@ -210,7 +210,7 @@
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
options or complete the name if there is only one.'''
bl_idname = "console.autocomplete"
@@ -256,9 +256,36 @@
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_MT_console)
bpy.types.register(CONSOLE_MT_report)
-bpy.ops.add(CONSOLE_OT_exec)
-bpy.ops.add(CONSOLE_OT_autocomplete)
+bpy.ops.add(ConsoleExec)
+bpy.ops.add(ConsoleAutocomplete)
+bpy.ops.add(ConsoleBanner)
Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c 2009-11-05 10:50:58 UTC (rev 24345)
+++ trunk/blender/source/blender/editors/space_console/space_console.c 2009-11-05 11:17:09 UTC (rev 24346)
@@ -164,21 +164,9 @@
View2DScrollers *scrollers;
//float col[3];
- /* add helper text, why not? */
- if(sc->scrollback.first==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);
+ if(sc->scrollback.first==NULL)
+ WM_operator_name_call((bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, NULL);
- /* 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 */
//UI_GetThemeColor3fv(TH_BACK, col);
//glClearColor(col[0], col[1], col[2], 0.0);
Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-05 10:50:58 UTC (rev 24345)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c 2009-11-05 11:17:09 UTC (rev 24346)
@@ -101,8 +101,6 @@
if(py_call_level==1) {
- BPY_update_modules(); /* can give really bad results if this isnt here */
-
if(C) { // XXX - should always be true.
BPy_SetContext(C);
bpy_import_main_set(CTX_data_main(C));
@@ -111,6 +109,8 @@
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
if(bpy_timer_count==0) {
/* record time from the beginning */
@@ -171,6 +171,7 @@
/*****************************************************************************
* 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 )
{
PyObject *mod;
@@ -204,6 +205,15 @@
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 */
Geometry_Init();
Mathutils_Init();
@@ -220,7 +230,7 @@
/* refreshes the main struct */
BPY_update_rna_module();
-
+ bpy_context_module->ptr.data= (void *)BPy_GetContext();
}
/*****************************************************************************
More information about the Bf-blender-cvs
mailing list