F8 reload works again, script errors are printed but dont stop loading every other...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 13 Nov 2009 11:10:29 +0000 (11:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 13 Nov 2009 11:10:29 +0000 (11:10 +0000)
release/scripts/modules/bpy/__init__.py
release/scripts/modules/bpy/ops.py
release/scripts/op/wm.py
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_script/script_edit.c
source/blender/editors/space_script/script_intern.h
source/blender/editors/space_script/script_ops.c
source/blender/python/intern/bpy_operator.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_ui.c

index aa755bbc84531cefcea0e23d40d0389774b1f9c0..f5ecfaf1294d6a44da4379ad7332a180fe789e93 100644 (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
-
-# 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
index e3fa2ab94caf1498391b0e191f1cf2813eb88ce4..5b3009db2bf4ad3c6dccefbe00cb8ac5b3cba30c 100644 (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()
index e65002ee0c09613228c58f3b27ff4681a1ae0a6e..39bd65eec259884cd086ca017b68d592765992af 100644 (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)
index 0df7b326834542c590c9b4276d4c46fd1b60a057..f90c15131163a0bc2ef48e165d978706eda7e36f 100644 (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);
index 630ea752f229d18ff74a19e91af15896ff600ba0..355095ea290e9a4beb5e2665c8a0bbcc11955dda 100644 (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;
-}
index 7534fc98de111430a7c615813487e1f290c3b75f..08ec8ea289a23810385b9c2ad729bbef30423724 100644 (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 */
 
index fd87705648f9192ed1be40b998e7945cda953f48..4ac90e852fbb385c27c91cb098c2066b837c00e3 100644 (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);
 }
 
index b1577969a222e8ae3f82f8de7c9ac9be24210e83..409afee7d7dd0d9e53460be11a721958dd0f9367 100644 (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) );
index 95ffd3e11215f6cbb0da40f00ecdb080039d7601..0aa6d8b6e6e1bfdee4c8d57ca5ced40b355c2219 100644 (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 */
index f03a83bee9c6c46032175cd7433ff8286178a201..ab50ebd8bd5efde944902db0e256963473c5a312 100644 (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,