py/api registration:
move calls to the classes register/unregister function into register_class() / unregister_class() and add docs. also other minor changes: - remove face sorting keybinding, was Ctrl+Alt+F, this is quite and obscure feature and face order normally doesn't matter, so access from Face menu is enough. - add commented out call to mesh.validate() in addon template since its useful to correct incomplete meshes during development.
This commit is contained in:
parent
74a996c869
commit
f3686b5885
@ -426,21 +426,19 @@ def _bpy_module_classes(module, is_registered=False):
|
||||
def register_module(module, verbose=False):
|
||||
if verbose:
|
||||
print("bpy.utils.register_module(%r): ..." % module)
|
||||
cls = None
|
||||
for cls in _bpy_module_classes(module, is_registered=False):
|
||||
if verbose:
|
||||
print(" %r" % cls)
|
||||
try:
|
||||
register_class(cls)
|
||||
cls_func = getattr(cls, "register", None)
|
||||
if cls_func is not None:
|
||||
cls_func()
|
||||
except:
|
||||
print("bpy.utils.register_module(): failed to registering class %r" % cls)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
if verbose:
|
||||
print("done.\n")
|
||||
if "cls" not in locals():
|
||||
if cls is None:
|
||||
raise Exception("register_module(%r): defines no classes" % module)
|
||||
|
||||
|
||||
@ -452,9 +450,6 @@ def unregister_module(module, verbose=False):
|
||||
print(" %r" % cls)
|
||||
try:
|
||||
unregister_class(cls)
|
||||
cls_func = getattr(cls, "unregister", None)
|
||||
if cls_func is not None:
|
||||
cls_func()
|
||||
except:
|
||||
print("bpy.utils.unregister_module(): failed to unregistering class %r" % cls)
|
||||
import traceback
|
||||
|
@ -31,8 +31,10 @@ def add_object(self, context):
|
||||
edges = []
|
||||
faces = [[0, 1, 2, 3]]
|
||||
|
||||
mesh_data = bpy.data.meshes.new(name='New Object Mesh')
|
||||
mesh_data.from_pydata(verts, edges, faces)
|
||||
mesh = bpy.data.meshes.new(name='New Object Mesh')
|
||||
mesh.from_pydata(verts, edges, faces)
|
||||
# useful for development when the mesh may be invalid.
|
||||
# mesh.validate(verbose=True)
|
||||
add_object_data(context, mesh_data, operator=self)
|
||||
|
||||
|
||||
@ -55,7 +57,7 @@ class OBJECT_OT_add_object(bpy.types.Operator, AddObjectHelper):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
#### REGISTER ####
|
||||
# Registration
|
||||
|
||||
def add_object_button(self, context):
|
||||
self.layout.operator(
|
||||
|
@ -282,7 +282,6 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
|
||||
|
||||
WM_keymap_add_item(keymap, "MESH_OT_fill", FKEY, KM_PRESS, KM_ALT, 0);
|
||||
WM_keymap_add_item(keymap, "MESH_OT_beautify_fill", FKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
|
||||
WM_keymap_add_item(keymap, "MESH_OT_sort_faces", FKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
|
||||
WM_keymap_add_item(keymap, "MESH_OT_quads_convert_to_tris", TKEY, KM_PRESS, KM_CTRL, 0);
|
||||
WM_keymap_add_item(keymap, "MESH_OT_tris_convert_to_quads", JKEY, KM_PRESS, KM_ALT, 0);
|
||||
WM_keymap_add_item(keymap, "MESH_OT_edge_flip", FKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
|
||||
|
@ -95,11 +95,13 @@ int pyrna_prop_validity_check(BPy_PropertyRNA *self)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(USE_PYRNA_INVALIDATE_GC) || defined(USE_PYRNA_INVALIDATE_WEAKREF)
|
||||
static void pyrna_invalidate(BPy_DummyPointerRNA *self)
|
||||
{
|
||||
self->ptr.type= NULL; /* this is checked for validity */
|
||||
self->ptr.id.data= NULL; /* should not be needed but prevent bad pointer access, just incase */
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_PYRNA_INVALIDATE_GC
|
||||
#define FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1))
|
||||
@ -6106,6 +6108,8 @@ static char pyrna_register_class_doc[] =
|
||||
"\n"
|
||||
" Register a subclass of a blender type in (:class:`Panel`, :class:`Menu`, :class:`Header`, :class:`Operator`, :class:`KeyingSetInfo`, :class:`RenderEngine`).\n"
|
||||
"\n"
|
||||
" If the class has a *register* class method it will be called before registration.\n"
|
||||
"\n"
|
||||
" .. note:: :exc:`ValueError` exception is raised if the class is not a subclass of a registerable blender class.\n"
|
||||
"\n"
|
||||
;
|
||||
@ -6118,6 +6122,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
|
||||
StructRNA *srna;
|
||||
StructRNA *srna_new;
|
||||
const char *identifier;
|
||||
PyObject *py_cls_meth;
|
||||
|
||||
if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) {
|
||||
PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
|
||||
@ -6145,6 +6150,22 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* call classed register function () */
|
||||
py_cls_meth= PyObject_GetAttrString(py_class, "register");
|
||||
if(py_cls_meth == NULL) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
PyObject *ret= PyObject_CallObject(py_cls_meth, NULL);
|
||||
if(ret) {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get the context, so register callback can do necessary refreshes */
|
||||
C= BPy_GetContext();
|
||||
|
||||
@ -6210,6 +6231,8 @@ static char pyrna_unregister_class_doc[] =
|
||||
".. method:: unregister_class(cls)\n"
|
||||
"\n"
|
||||
" Unload the python class from blender.\n"
|
||||
"\n"
|
||||
" If the class has an *unregister* class method it will be called before unregistering.\n"
|
||||
;
|
||||
PyMethodDef meth_bpy_unregister_class= {"unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc};
|
||||
static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_class)
|
||||
@ -6217,6 +6240,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
|
||||
bContext *C= NULL;
|
||||
StructUnregisterFunc unreg;
|
||||
StructRNA *srna;
|
||||
PyObject *py_cls_meth;
|
||||
|
||||
/*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) {
|
||||
PWM_cursor_wait(0);
|
||||
@ -6236,6 +6260,21 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* call classed register function */
|
||||
py_cls_meth= PyObject_GetAttrString(py_class, "unregister");
|
||||
if(py_cls_meth == NULL) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
PyObject *ret= PyObject_CallObject(py_cls_meth, NULL);
|
||||
if(ret) {
|
||||
Py_DECREF(ret);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* should happen all the time but very slow */
|
||||
if(G.f & G_DEBUG) {
|
||||
/* remove all properties using this class */
|
||||
|
Loading…
Reference in New Issue
Block a user