Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/modules/bpy/__init__.py51
-rw-r--r--release/scripts/modules/bpy/ops.py4
-rw-r--r--release/scripts/op/wm.py33
-rw-r--r--source/blender/editors/screen/screen_ops.c2
-rw-r--r--source/blender/editors/space_script/script_edit.c31
-rw-r--r--source/blender/editors/space_script/script_intern.h1
-rw-r--r--source/blender/editors/space_script/script_ops.c2
-rw-r--r--source/blender/python/intern/bpy_operator.c18
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c6
-rw-r--r--source/blender/python/intern/bpy_ui.c2
10 files changed, 84 insertions, 66 deletions
diff --git a/release/scripts/modules/bpy/__init__.py b/release/scripts/modules/bpy/__init__.py
index aa755bbc845..f5ecfaf1294 100644
--- a/release/scripts/modules/bpy/__init__.py
+++ b/release/scripts/modules/bpy/__init__.py
@@ -24,27 +24,44 @@ data = _bpy.data
context = _bpy.context
# python modules
-from bpy import utils, ops
+from bpy import utils
+from bpy import ops as ops_module
# fake operator module
-ops = ops.bpy_ops()
+ops = ops_module.ops_fake_module
# load all scripts
import os
import sys
-base_path = os.path.join(os.path.dirname(__file__), "..", "..")
-base_path = os.path.normpath(base_path) # clean
-
-# print(base_path, base_path_ui)
-
-for path_subdir in ("ui", "op", "io"):
- path = os.path.join(base_path, path_subdir)
- sys.path.insert(0, path)
- for f in sorted(os.listdir(path)):
- if f.endswith(".py"):
- # python module
- __import__(f[0:-3])
- elif "." not in f:
- # python package
- __import__(f)
+def load_scripts(reload_scripts=False):
+ import traceback
+
+ def test_import(module_name):
+ try:
+ return __import__(module_name)
+ except:
+ traceback.print_exc()
+ return None
+
+ base_path = os.path.join(os.path.dirname(__file__), "..", "..")
+ base_path = os.path.normpath(base_path) # clean
+
+ for path_subdir in ("ui", "op", "io"):
+ path = os.path.join(base_path, path_subdir)
+ sys.path.insert(0, path)
+ for f in sorted(os.listdir(path)):
+ if f.endswith(".py"):
+ # python module
+ mod = test_import(f[0:-3])
+ elif "." not in f:
+ # python package
+ mod = test_import(f)
+ else:
+ mod = None
+
+ if reload_scripts and mod:
+ print("Reloading:", mod)
+ reload(mod)
+
+load_scripts() \ No newline at end of file
diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py
index e3fa2ab94ca..5b3009db2bf 100644
--- a/release/scripts/modules/bpy/ops.py
+++ b/release/scripts/modules/bpy/ops.py
@@ -192,6 +192,4 @@ class bpy_ops_submodule_op(object):
return "<function bpy.ops.%s.%s at 0x%x'>" % \
(self.module, self.func, id(self))
-import bpy
-bpy.ops = bpy_ops()
-
+ops_fake_module = bpy_ops()
diff --git a/release/scripts/op/wm.py b/release/scripts/op/wm.py
index e65002ee0c0..39bd65eec25 100644
--- a/release/scripts/op/wm.py
+++ b/release/scripts/op/wm.py
@@ -362,6 +362,37 @@ class WM_OT_doc_edit(bpy.types.Operator):
return ('RUNNING_MODAL',)
+class WM_OT_reload_scripts(bpy.types.Operator):
+ '''Load online reference docs'''
+ bl_idname = "wm.reload_scripts"
+ bl_label = "Reload Scripts"
+
+ def execute(self, context):
+ MOD = type(bpy)
+ import sys
+ bpy.load_scripts(True)
+ '''
+ prefix = bpy.base_path
+ items = list(sys.modules.items())
+ items.sort()
+ items.reverse()
+ for mod_name, mod in items:
+ mod_file = getattr(mod, "__file__", "")
+ if mod_file.startswith(prefix) and "__init__" not in mod_file:
+ print(mod_file)
+ reload(mod)
+ """
+ for submod_name in dir(mod):
+ submod = getattr(mod, submod_name)
+ if isinstance(submod, MOD):
+ reload(submod)
+ """
+ else:
+ print("Ignoring:", mod, mod_file)
+ '''
+ return ('FINISHED',)
+
+
bpy.ops.add(MESH_OT_delete_edgeloop)
bpy.ops.add(WM_OT_context_set_boolean)
@@ -376,3 +407,5 @@ bpy.ops.add(WM_OT_context_cycle_int)
bpy.ops.add(WM_OT_doc_view)
bpy.ops.add(WM_OT_doc_edit)
+
+bpy.ops.add(WM_OT_reload_scripts)
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 0df7b326834..f90c1513116 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3704,7 +3704,7 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "SCREEN_OT_redo_last", F6KEY, KM_PRESS, 0, 0);
RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", F7KEY, KM_PRESS, 0, 0)->ptr, "path", "test.py");
- WM_keymap_verify_item(keymap, "SCRIPT_OT_python_run_ui_scripts", F8KEY, KM_PRESS, 0, 0);
+ WM_keymap_verify_item(keymap, "WM_OT_reload_scripts", F8KEY, KM_PRESS, 0, 0);
/* files */
WM_keymap_add_item(keymap, "FILE_OT_execute", RETKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index 630ea752f22..355095ea290 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -89,34 +89,3 @@ void SCRIPT_OT_python_file_run(wmOperatorType *ot)
RNA_def_string_file_path(ot->srna, "path", "", 512, "Path", "");
}
-static int run_ui_scripts_exec(bContext *C, wmOperator *op)
-{
-#ifndef DISABLE_PYTHON
-// TODO
-#endif
- return OPERATOR_FINISHED;
-}
-
-static int run_ui_scripts_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
- int ret= run_ui_scripts_exec(C, op);
-
- if(ret==OPERATOR_FINISHED)
- WM_event_add_notifier(C, NC_WINDOW, NULL);
-
- return ret;
-}
-
-
-void SCRIPT_OT_python_run_ui_scripts(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Reload Python Interface";
- ot->description= "Reload Python interface.";
- ot->idname= "SCRIPT_OT_python_run_ui_scripts";
-
- /* api callbacks */
- ot->exec= run_ui_scripts_exec;
- ot->invoke= run_ui_scripts_invoke;
- ot->poll= ED_operator_areaactive;
-}
diff --git a/source/blender/editors/space_script/script_intern.h b/source/blender/editors/space_script/script_intern.h
index 7534fc98de1..08ec8ea289a 100644
--- a/source/blender/editors/space_script/script_intern.h
+++ b/source/blender/editors/space_script/script_intern.h
@@ -40,7 +40,6 @@ void script_keymap(struct wmKeyConfig *keyconf);
/* script_edit.c */
void SCRIPT_OT_python_file_run(struct wmOperatorType *ot);
-void SCRIPT_OT_python_run_ui_scripts(struct wmOperatorType *ot);
#endif /* ED_SCRIPT_INTERN_H */
diff --git a/source/blender/editors/space_script/script_ops.c b/source/blender/editors/space_script/script_ops.c
index fd87705648f..4ac90e852fb 100644
--- a/source/blender/editors/space_script/script_ops.c
+++ b/source/blender/editors/space_script/script_ops.c
@@ -60,7 +60,6 @@
void script_operatortypes(void)
{
WM_operatortype_append(SCRIPT_OT_python_file_run);
- WM_operatortype_append(SCRIPT_OT_python_run_ui_scripts);
}
void script_keymap(wmKeyConfig *keyconf)
@@ -69,6 +68,5 @@ void script_keymap(wmKeyConfig *keyconf)
/* TODO - this is just while we have no way to load a text datablock */
RNA_string_set(WM_keymap_add_item(keymap, "SCRIPT_OT_python_file_run", PKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0)->ptr, "path", "test.py");
- WM_keymap_add_item(keymap, "SCRIPT_OT_python_run_ui_scripts", PKEY, KM_PRESS, KM_SHIFT, 0);
}
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index b1577969a22..409afee7d7d 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -57,13 +57,13 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
bContext *C = BPy_GetContext();
- if (!PyArg_ParseTuple(args, "sO|O!i:bpy.__ops__.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
+ if (!PyArg_ParseTuple(args, "sO|O!i:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
return NULL;
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
- PyErr_Format( PyExc_SystemError, "bpy.__ops__.call: operator \"%s\"could not be found", opname);
+ PyErr_Format( PyExc_SystemError, "_bpy.ops.call: operator \"%s\"could not be found", opname);
return NULL;
}
@@ -76,7 +76,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
Py_XINCREF(context_dict); /* so we done loose it */
if(WM_operator_poll((bContext*)C, ot) == FALSE) {
- PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
+ PyErr_SetString( PyExc_SystemError, "_bpy.ops.call: operator poll() function failed, context is incorrect");
error_val= -1;
}
else {
@@ -158,13 +158,13 @@ static PyObject *pyop_as_string( PyObject * self, PyObject * args)
bContext *C = BPy_GetContext();
- if (!PyArg_ParseTuple(args, "s|O!i:bpy.__ops__.as_string", &opname, &PyDict_Type, &kw, &all_args))
+ if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
return NULL;
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
- PyErr_Format( PyExc_SystemError, "bpy.__ops__.as_string: operator \"%s\"could not be found", opname);
+ PyErr_Format( PyExc_SystemError, "_bpy.ops.as_string: operator \"%s\"could not be found", opname);
return NULL;
}
@@ -217,12 +217,12 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
BPy_StructRNA *pyrna= NULL;
if(opname==NULL) {
- PyErr_SetString(PyExc_TypeError, "bpy.__ops__.get_rna() expects a string argument");
+ PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument");
return NULL;
}
ot= WM_operatortype_find(opname, TRUE);
if(ot==NULL) {
- PyErr_Format(PyExc_KeyError, "bpy.__ops__.get_rna(\"%s\") not found", opname);
+ PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname);
return NULL;
}
@@ -245,8 +245,8 @@ PyObject *BPY_operator_module( void )
static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
- PyObject *submodule = PyModule_New("bpy.__ops__");
- PyDict_SetItemString(PySys_GetObject("modules"), "bpy.__ops__", submodule);
+ PyObject *submodule = PyModule_New("_bpy.ops");
+ PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 95ffd3e1121..0aa6d8b6e6e 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -341,7 +341,11 @@ PyObject *PYOP_wrap_add(PyObject *self, PyObject *py_class)
// in python would be...
//PyObject *optype = PyObject_GetAttrString(PyObject_GetAttrString(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), "types"), "Operator");
- base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Operator");
+
+ //PyObject bpy_mod= PyDict_GetItemString(PyEval_GetGlobals(), "bpy");
+ PyObject *bpy_mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
+ base_class = PyObject_GetAttrStringArgs(bpy_mod, 2, "types", "Operator");
+ Py_DECREF(bpy_mod);
if(BPY_class_validate("Operator", py_class, base_class, pyop_class_attr_values, NULL) < 0) {
return NULL; /* BPY_class_validate sets the error */
diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c
index f03a83bee9c..ab50ebd8bd5 100644
--- a/source/blender/python/intern/bpy_ui.c
+++ b/source/blender/python/intern/bpy_ui.c
@@ -48,7 +48,7 @@ static struct PyMethodDef ui_methods[] = {
static struct PyModuleDef ui_module = {
PyModuleDef_HEAD_INIT,
- "bpy.ui",
+ "_bpy.ui",
"",
-1,/* multiple "initialization" just copies the module dict. */
ui_methods,