[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24058] trunk/blender: changed WM_OT_context_* operators to pass through if one of the members in the path is None , rather then raising an error.

Campbell Barton ideasman42 at gmail.com
Thu Oct 22 18:21:09 CEST 2009


Revision: 24058
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24058
Author:   campbellbarton
Date:     2009-10-22 18:21:06 +0200 (Thu, 22 Oct 2009)

Log Message:
-----------
changed WM_OT_context_* operators to pass through if one of the members in the path is None, rather then raising an error.
This means if you refer to a member of an object it will fail silently if there is no active object, but if you use an invalid attribute of the object it raises an error.
The method to check this is not nice but works well enough.

also removed pageup/down keys for changing the active shape since listviews can do this now.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_ops.py
    trunk/blender/source/blender/editors/object/object_ops.c

Modified: trunk/blender/release/scripts/modules/bpy_ops.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_ops.py	2009-10-22 15:53:30 UTC (rev 24057)
+++ trunk/blender/release/scripts/modules/bpy_ops.py	2009-10-22 16:21:06 UTC (rev 24058)
@@ -156,7 +156,29 @@
 rna_path_prop = bpy.props.StringProperty(attr="path", name="Context Attributes", description="rna context string", maxlen= 1024, default= "")
 rna_reverse_prop = bpy.props.BoolProperty(attr="reverse", name="Reverse", description="Cycle backwards", default= False)
 
+class NullPathMember:
+	pass
+
+def context_path_validate(context, path):
+	import sys
+	try:
+		value = eval("context.%s" % path)
+	except AttributeError:
+		if "'NoneType'" in str(sys.exc_info()[1]):
+			# One of the items in the rna path is None, just ignore this
+			value = NullPathMember
+		else:
+			# We have a real error in the rna path, dont ignore that
+			raise
+	
+	return value
+		
+	
+
 def execute_context_assign(self, context):
+	if context_path_validate(context, self.path) == NullPathMember:
+		return ('PASS_THROUGH',)
+	
 	exec("context.%s=self.value" % self.path)
 	return ('FINISHED',)
 
@@ -201,6 +223,10 @@
 	__label__ = "Context Toggle"
 	__props__ = [rna_path_prop]
 	def execute(self, context):
+		
+		if context_path_validate(context, self.path) == NullPathMember:
+			return ('PASS_THROUGH',)
+		
 		exec("context.%s=not (context.%s)" % (self.path, self.path)) # security nuts will complain.
 		return ('FINISHED',)
 
@@ -214,6 +240,10 @@
 		bpy.props.StringProperty(attr="value_2", name="Value", description="Toggle enum", maxlen= 1024, default= "")
 	]
 	def execute(self, context):
+		
+		if context_path_validate(context, self.path) == NullPathMember:
+			return ('PASS_THROUGH',)
+		
 		exec("context.%s = ['%s', '%s'][context.%s!='%s']" % (self.path, self.value_1, self.value_2, self.path, self.value_2)) # security nuts will complain.
 		return ('FINISHED',)
 
@@ -223,7 +253,12 @@
 	__label__ = "Context Int Cycle"
 	__props__ = [rna_path_prop, rna_reverse_prop]
 	def execute(self, context):
-		self.value = eval("context.%s" % self.path)
+		
+		value = context_path_validate(context, self.path)
+		if value == NullPathMember:
+			return ('PASS_THROUGH',)
+		
+		self.value = value
 		if self.reverse:	self.value -= 1
 		else:		self.value += 1
 		execute_context_assign(self, context)
@@ -242,8 +277,13 @@
 	__label__ = "Context Enum Cycle"
 	__props__ = [rna_path_prop, rna_reverse_prop]
 	def execute(self, context):
-		orig_value = eval("context.%s" % self.path) # security nuts will complain.
 		
+		value = context_path_validate(context, self.path)
+		if value == NullPathMember:
+			return ('PASS_THROUGH',)
+		
+		orig_value = value
+		
 		# Have to get rna enum values
 		rna_struct_str, rna_prop_str =  self.path.rsplit('.', 1)
 		i = rna_prop_str.find('[')

Modified: trunk/blender/source/blender/editors/object/object_ops.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_ops.c	2009-10-22 15:53:30 UTC (rev 24057)
+++ trunk/blender/source/blender/editors/object/object_ops.c	2009-10-22 16:21:06 UTC (rev 24058)
@@ -292,15 +292,6 @@
 	WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
 	WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
 
-	/* if 2.4x keys use these can be replaced, could also use page up/down keys to switch vgroups */
-	kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PAGEUPKEY, KM_PRESS, 0, 0);
-	RNA_string_set(kmi->ptr, "path", "object.active_shape_key_index");
-	RNA_boolean_set(kmi->ptr, "reverse", TRUE);
-
-	kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", PAGEDOWNKEY, KM_PRESS, 0, 0);
-	RNA_string_set(kmi->ptr, "path", "object.active_shape_key_index");
-
-
 	/* Lattice */
 	keymap= WM_keymap_find(keyconf, "Lattice", 0, 0);
 	keymap->poll= ED_operator_editlattice;





More information about the Bf-blender-cvs mailing list