[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27977] trunk/blender: keymap.add_item, add_modal_items --> keymap.items.add()/add_modal()

Campbell Barton ideasman42 at gmail.com
Sun Apr 4 00:09:44 CEST 2010


Revision: 27977
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27977
Author:   campbellbarton
Date:     2010-04-04 00:09:44 +0200 (Sun, 04 Apr 2010)

Log Message:
-----------
keymap.add_item, add_modal_items --> keymap.items.add()/add_modal()

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_userpref.py
    trunk/blender/source/blender/makesrna/intern/rna_wm.c
    trunk/blender/source/blender/makesrna/intern/rna_wm_api.c

Modified: trunk/blender/release/scripts/ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/ui/space_userpref.py	2010-04-03 19:19:32 UTC (rev 27976)
+++ trunk/blender/release/scripts/ui/space_userpref.py	2010-04-03 22:09:44 UTC (rev 27977)
@@ -1716,9 +1716,9 @@
 
         def kmistr(kmi):
             if km.modal:
-                s = ["kmi = km.add_modal_item(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)]
+                s = ["kmi = km.items.add_modal(\'%s\', \'%s\', \'%s\'" % (kmi.propvalue, kmi.type, kmi.value)]
             else:
-                s = ["kmi = km.add_item(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)]
+                s = ["kmi = km.items.add(\'%s\', \'%s\', \'%s\'" % (kmi.idname, kmi.type, kmi.value)]
 
             if kmi.any:
                 s.append(", any=True")
@@ -1924,9 +1924,9 @@
             f.write("km = kc.add_keymap('%s', space_type='%s', region_type='%s', modal=%s)\n\n" % (km.name, km.space_type, km.region_type, km.modal))
             for kmi in km.items:
                 if km.modal:
-                    f.write("kmi = km.add_modal_item('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
+                    f.write("kmi = km.items.add_modal('%s', '%s', '%s'" % (kmi.propvalue, kmi.type, kmi.value))
                 else:
-                    f.write("kmi = km.add_item('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
+                    f.write("kmi = km.items.add('%s', '%s', '%s'" % (kmi.idname, kmi.type, kmi.value))
                 if kmi.any:
                     f.write(", any=True")
                 else:
@@ -2030,9 +2030,9 @@
         kc = wm.default_keyconfig
 
         if km.modal:
-            km.add_modal_item("", 'A', 'PRESS') # kmi
+            km.items.add_modal("", 'A', 'PRESS') # kmi
         else:
-            km.add_item("none", 'A', 'PRESS') # kmi
+            km.items.add("none", 'A', 'PRESS') # kmi
 
         # clear filter and expand keymap so we can see the newly added item
         if kc.filter != '':

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c	2010-04-03 19:19:32 UTC (rev 27976)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c	2010-04-03 22:09:44 UTC (rev 27977)
@@ -891,6 +891,66 @@
 	return (op->type && op->type->ext.srna)? op->type->ext.srna: &RNA_Macro;
 }
 
+static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char *idname, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
+{
+//	wmWindowManager *wm = CTX_wm_manager(C);
+	int modifier= 0;
+
+	/* only on non-modal maps */
+	if (km->flag & KEYMAP_MODAL) {
+		BKE_report(reports, RPT_ERROR, "Not a non-modal keymap.");
+		return NULL;
+	}
+
+	if(shift) modifier |= KM_SHIFT;
+	if(ctrl) modifier |= KM_CTRL;
+	if(alt) modifier |= KM_ALT;
+	if(oskey) modifier |= KM_OSKEY;
+
+	if(any) modifier = KM_ANY;
+
+	return WM_keymap_add_item(km, idname, type, value, modifier, keymodifier);
+}
+
+static wmKeyMapItem *rna_KeyMap_add_modal_item(wmKeyMap *km, bContext *C, ReportList *reports, char* propvalue_str, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
+{
+	wmWindowManager *wm = CTX_wm_manager(C);
+	int modifier= 0;
+	int propvalue = 0;
+
+	/* only modal maps */
+	if ((km->flag & KEYMAP_MODAL) == 0) {
+		BKE_report(reports, RPT_ERROR, "Not a modal keymap.");
+		return NULL;
+	}
+
+	if (!km->modal_items) {
+		if(!WM_keymap_user_init(wm, km)) {
+			BKE_report(reports, RPT_ERROR, "User defined keymap doesn't correspond to a system keymap.");
+			return NULL;
+		}
+	}
+
+	if (!km->modal_items) {
+		BKE_report(reports, RPT_ERROR, "No property values defined.");
+		return NULL;
+	}
+
+
+	if(RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue)==0) {
+		BKE_report(reports, RPT_WARNING, "Property value not in enumeration.");
+	}
+
+	if(shift) modifier |= KM_SHIFT;
+	if(ctrl) modifier |= KM_CTRL;
+	if(alt) modifier |= KM_ALT;
+	if(oskey) modifier |= KM_OSKEY;
+
+	if(any) modifier = KM_ANY;
+
+	return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue);
+}
+
 #else
 
 static void rna_def_operator(BlenderRNA *brna)
@@ -1203,6 +1263,56 @@
 	RNA_api_wm(srna);
 }
 
+/* keyconfig.items */
+static void rna_def_keymap_items(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+//	PropertyRNA *prop;
+
+	FunctionRNA *func;
+	PropertyRNA *parm;
+	
+	RNA_def_property_srna(cprop, "KeyMapItems");
+	srna= RNA_def_struct(brna, "KeyMapItems", NULL);
+	RNA_def_struct_sdna(srna, "wmKeyMap");
+	RNA_def_struct_ui_text(srna, "KeyMap Items", "Collection of keymap items");
+
+	func= RNA_def_function(srna, "add", "rna_KeyMap_add_item");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	parm= RNA_def_string(func, "idname", "", 0, "Operator Identifier", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	RNA_def_boolean(func, "any", 0, "Any", "");
+	RNA_def_boolean(func, "shift", 0, "Shift", "");
+	RNA_def_boolean(func, "ctrl", 0, "Ctrl", "");
+	RNA_def_boolean(func, "alt", 0, "Alt", "");
+	RNA_def_boolean(func, "oskey", 0, "OS Key", "");
+	RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");
+	parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item.");
+	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "add_modal", "rna_KeyMap_add_modal_item");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+	parm= RNA_def_string(func, "propvalue", "", 0, "Property Value", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", "");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	RNA_def_boolean(func, "any", 0, "Any", "");
+	RNA_def_boolean(func, "shift", 0, "Shift", "");
+	RNA_def_boolean(func, "ctrl", 0, "Ctrl", "");
+	RNA_def_boolean(func, "alt", 0, "Alt", "");
+	RNA_def_boolean(func, "oskey", 0, "OS Key", "");
+	RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");
+	parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item.");
+	RNA_def_function_return(func, parm);
+	
+}
+
 static void rna_def_keyconfig(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -1269,6 +1379,7 @@
 	prop= RNA_def_property(srna, "items", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_struct_type(prop, "KeyMapItem");
 	RNA_def_property_ui_text(prop, "Items", "Items in the keymap, linking an operator to an input event");
+	rna_def_keymap_items(brna, prop);
 
 	prop= RNA_def_property(srna, "user_defined", PROP_BOOLEAN, PROP_NEVER_NULL);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_USER);

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2010-04-03 19:19:32 UTC (rev 27976)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm_api.c	2010-04-03 22:09:44 UTC (rev 27977)
@@ -70,72 +70,11 @@
 	return WM_keymap_active(wm, km);
 }
 
-
-static wmKeyMapItem *rna_KeyMap_add_modal_item(wmKeyMap *km, bContext *C, ReportList *reports, char* propvalue_str, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
-{
-	wmWindowManager *wm = CTX_wm_manager(C);
-	int modifier= 0;
-	int propvalue = 0;
-
-	/* only modal maps */
-	if ((km->flag & KEYMAP_MODAL) == 0) {
-		BKE_report(reports, RPT_ERROR, "Not a modal keymap.");
-		return NULL;
-	}
-
-	if (!km->modal_items) {
-		if(!WM_keymap_user_init(wm, km)) {
-			BKE_report(reports, RPT_ERROR, "User defined keymap doesn't correspond to a system keymap.");
-			return NULL;
-		}
-	}
-
-	if (!km->modal_items) {
-		BKE_report(reports, RPT_ERROR, "No property values defined.");
-		return NULL;
-	}
-
-
-	if(RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue)==0) {
-		BKE_report(reports, RPT_WARNING, "Property value not in enumeration.");
-	}
-
-	if(shift) modifier |= KM_SHIFT;
-	if(ctrl) modifier |= KM_CTRL;
-	if(alt) modifier |= KM_ALT;
-	if(oskey) modifier |= KM_OSKEY;
-
-	if(any) modifier = KM_ANY;
-
-	return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue);
-}
-
 static void rna_keymap_restore_item_to_default(wmKeyMap *km, bContext *C, wmKeyMapItem *kmi)
 {
 	WM_keymap_restore_item_to_default(C, km, kmi);
 }
 
-static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char *idname, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
-{
-//	wmWindowManager *wm = CTX_wm_manager(C);
-	int modifier= 0;
-
-	/* only on non-modal maps */
-	if (km->flag & KEYMAP_MODAL) {
-		BKE_report(reports, RPT_ERROR, "Not a non-modal keymap.");
-		return NULL;
-	}
-
-	if(shift) modifier |= KM_SHIFT;
-	if(ctrl) modifier |= KM_CTRL;
-	if(alt) modifier |= KM_ALT;
-	if(oskey) modifier |= KM_OSKEY;
-
-	if(any) modifier = KM_ANY;
-
-	return WM_keymap_add_item(km, idname, type, value, modifier, keymodifier);
-}
-
 static void rna_Operator_report(wmOperator *op, int type, char *msg)
 {
 	BKE_report(op->reports, type, msg);
@@ -352,40 +291,6 @@
 	FunctionRNA *func;
 	PropertyRNA *parm;
 
-	func= RNA_def_function(srna, "add_item", "rna_KeyMap_add_item");
-	RNA_def_function_flag(func, FUNC_USE_REPORTS);
-	parm= RNA_def_string(func, "idname", "", 0, "Operator Identifier", "");
-	RNA_def_property_flag(parm, PROP_REQUIRED);
-	parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", "");
-	RNA_def_property_flag(parm, PROP_REQUIRED);
-	parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", "");
-	RNA_def_property_flag(parm, PROP_REQUIRED);
-	RNA_def_boolean(func, "any", 0, "Any", "");
-	RNA_def_boolean(func, "shift", 0, "Shift", "");
-	RNA_def_boolean(func, "ctrl", 0, "Ctrl", "");
-	RNA_def_boolean(func, "alt", 0, "Alt", "");
-	RNA_def_boolean(func, "oskey", 0, "OS Key", "");
-	RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list