forked from bartvdbraak/blender
- object.selected is now editable (uses update function to flag the scene base)
- editing properties from python wasnt running their update function. - missing commas made dir(context) give joined strings. - added __undo__ as an operator class attribute so python ops can be set as undoable. (like existing __register__)
This commit is contained in:
parent
da698657ce
commit
df6c18e963
@ -179,6 +179,7 @@ class VIEW3D_MT_select_object(bpy.types.Menu):
|
||||
layout.itemO("object.select_by_layer", text="Select All by Layer")
|
||||
layout.item_enumO("object.select_by_type", "type", "", text="Select All by Type...")
|
||||
layout.itemO("object.select_grouped", text="Select Grouped...")
|
||||
layout.itemO("object.select_pattern", text="Select Pattern...")
|
||||
|
||||
class VIEW3D_MT_select_pose(bpy.types.Menu):
|
||||
__space_type__ = 'VIEW_3D'
|
||||
@ -1306,7 +1307,42 @@ class VIEW3D_PT_transform_orientations(bpy.types.Panel):
|
||||
col.itemO("TFM_OT_select_orientation", text="Select")
|
||||
col.itemO("TFM_OT_create_orientation", text="Create")
|
||||
col.itemO("TFM_OT_delete_orientation", text="Delete")
|
||||
|
||||
|
||||
# Operators
|
||||
|
||||
class OBJECT_OT_select_pattern(bpy.types.Operator):
|
||||
'''Select object matching a naming pattern.'''
|
||||
__idname__ = "object.select_pattern"
|
||||
__label__ = "Select Pattern"
|
||||
__register__ = True
|
||||
__undo__ = True
|
||||
__props__ = [
|
||||
bpy.props.StringProperty(attr="pattern", name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen= 32, default= "*"),
|
||||
bpy.props.BoolProperty(attr="case_sensitive", name="Case Sensitive", description="Do a case sensitive compare", default= False),
|
||||
]
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
import fnmatch
|
||||
if self.case_sensitive: pattern_match = fnmatch.fnmatchcase
|
||||
else: pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
|
||||
|
||||
for ob in context.visible_objects:
|
||||
if pattern_match(ob.name, self.pattern):
|
||||
ob.selected = True
|
||||
|
||||
return ('FINISHED',)
|
||||
|
||||
# TODO - python cant do popups yet
|
||||
'''
|
||||
def invoke(self, context, event):
|
||||
wm = context.manager
|
||||
wm.add_fileselect(self.__operator__)
|
||||
return ('RUNNING_MODAL',)
|
||||
'''
|
||||
|
||||
|
||||
|
||||
bpy.types.register(VIEW3D_HT_header) # Header
|
||||
|
||||
bpy.types.register(VIEW3D_MT_view) #View Menus
|
||||
@ -1382,4 +1418,7 @@ bpy.types.register(VIEW3D_PT_3dview_display)
|
||||
bpy.types.register(VIEW3D_PT_3dview_meshdisplay)
|
||||
bpy.types.register(VIEW3D_PT_3dview_curvedisplay)
|
||||
bpy.types.register(VIEW3D_PT_background_image)
|
||||
bpy.types.register(VIEW3D_PT_transform_orientations)
|
||||
bpy.types.register(VIEW3D_PT_transform_orientations)
|
||||
|
||||
bpy.ops.add(OBJECT_OT_select_pattern)
|
||||
|
||||
|
@ -52,7 +52,7 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
|
||||
if(CTX_data_dir(member)) {
|
||||
static const char *dir[] = {
|
||||
"scene", "selected_objects", "selected_bases",
|
||||
"selected_editable_objects", "selected_editable_bases"
|
||||
"selected_editable_objects", "selected_editable_bases",
|
||||
"active_base", "active_object", "edit_object",
|
||||
"sculpt_object", "vertex_paint_object", "weight_paint_object",
|
||||
"texture_paint_object", "brush", "particle_edit_object", NULL};
|
||||
|
@ -620,10 +620,10 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
|
||||
|
||||
if(CTX_data_dir(member)) {
|
||||
static const char *dir[] = {
|
||||
"selected_objects", "selected_bases" "selected_editable_objects",
|
||||
"selected_editable_bases" "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
|
||||
"selected_objects", "selected_bases", "selected_editable_objects",
|
||||
"selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
|
||||
"active_base", "active_object", "visible_bones", "editable_bones",
|
||||
"selected_bones", "selected_editable_bones" "visible_pchans",
|
||||
"selected_bones", "selected_editable_bones", "visible_pchans",
|
||||
"selected_pchans", "active_bone", "active_pchan", NULL};
|
||||
|
||||
CTX_data_dir_set(result, dir);
|
||||
|
@ -126,6 +126,14 @@ static void rna_Object_dependency_update(bContext *C, PointerRNA *ptr)
|
||||
DAG_scene_sort(CTX_data_scene(C));
|
||||
}
|
||||
|
||||
/* when changing the selection flag the scene needs updating */
|
||||
static void rna_Object_select_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
Object *ob= (Object*)ptr->id.data;
|
||||
short mode = ob->flag & SELECT ? BA_SELECT : BA_DESELECT;
|
||||
ED_base_object_select(object_in_scene(ob, CTX_data_scene(C)), mode);
|
||||
}
|
||||
|
||||
static void rna_Object_layer_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
Object *ob= (Object*)ptr->id.data;
|
||||
@ -1145,9 +1153,8 @@ static void rna_def_object(BlenderRNA *brna)
|
||||
|
||||
prop= RNA_def_property(srna, "selected", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_ui_text(prop, "Selected", "Object selection state.");
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
|
||||
RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Object_select_update");
|
||||
|
||||
/* parent and track */
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
#define PYOP_ATTR_IDNAME_BL "__idname_bl__" /* our own name converted into blender syntax, users wont see this */
|
||||
#define PYOP_ATTR_DESCRIPTION "__doc__" /* use pythons docstring */
|
||||
#define PYOP_ATTR_REGISTER "__register__" /* True/False. if this python operator should be registered */
|
||||
#define PYOP_ATTR_UNDO "__undo__" /* True/False. if this python operator should be undone */
|
||||
|
||||
static struct BPY_flag_def pyop_ret_flags[] = {
|
||||
{"RUNNING_MODAL", OPERATOR_RUNNING_MODAL},
|
||||
@ -277,16 +278,27 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
|
||||
ot->pyop_data= userdata;
|
||||
|
||||
/* flags */
|
||||
ot->flag= 0;
|
||||
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_REGISTER);
|
||||
if (item) {
|
||||
ot->flag= PyObject_IsTrue(item)!=0 ? OPTYPE_REGISTER:0;
|
||||
ot->flag |= PyObject_IsTrue(item)!=0 ? OPTYPE_REGISTER:0;
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
ot->flag= OPTYPE_REGISTER; /* unspesified, leave on for now to help debug */
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
item= PyObject_GetAttrString(py_class, PYOP_ATTR_UNDO);
|
||||
if (item) {
|
||||
ot->flag |= PyObject_IsTrue(item)!=0 ? OPTYPE_UNDO:0;
|
||||
Py_DECREF(item);
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
props= PyObject_GetAttrString(py_class, PYOP_ATTR_PROP);
|
||||
|
||||
if (props) {
|
||||
|
@ -762,7 +762,10 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Run rna property functions */
|
||||
RNA_property_update(BPy_GetContext(), ptr, prop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user