F8 reload works again, script errors are printed but dont stop loading every other script

This commit is contained in:
2009-11-13 11:10:29 +00:00
parent b17964af11
commit 5a322bd67c
10 changed files with 82 additions and 64 deletions

View File

@@ -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
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
# 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
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)
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)
load_scripts()

View File

@@ -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()

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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) );

View File

@@ -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 */

View File

@@ -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,