- object.selected is now editable (uses update function to flag the scene base)
authorCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2009 07:54:20 +0000 (07:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 8 Oct 2009 07:54:20 +0000 (07:54 +0000)
- 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__)

release/scripts/ui/space_view3d.py
source/blender/editors/screen/screen_context.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesrna/intern/rna_object.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_rna.c

index 5827739aa530d90edd96de2758e0581c227ccdda..976c04a63bb0c1ba114e04056a31486d23f6752e 100644 (file)
@@ -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)
\ No newline at end of file
+bpy.types.register(VIEW3D_PT_transform_orientations)
+
+bpy.ops.add(OBJECT_OT_select_pattern)
+
index 17c51a7b7d3de3b5ffc9b6cee8855daf45bf5358..e573ef062478768e166bfbdda65fd04d568b3e65 100644 (file)
@@ -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};
index c175f835d676852874a957d77bdb6f1c0307b49c..735f3df9b09b0b789f86cd453ce38631989bd618 100644 (file)
@@ -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);
index 013d455b1b3754b2b516e16783c3fbd44cf4c25b..694eb7e23e41961d420e4c63d7e18e7f53338b8a 100644 (file)
@@ -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 */
 
index bbf657d8ce0fe70d02621b4896aa6b87c70c6153..bb0cea9e761ddf24a8ac4fb03a371b4a651f92cf 100644 (file)
@@ -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) {
index 1f800be266b8c16a9783407a2a7ab42a4683b7bb..42b905dc0d8c4e9241e804a82a14930d54f86dc7 100644 (file)
@@ -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;
 }