From: <au...@us...> - 2011-06-18 16:46:06
|
Revision: 8953 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=8953&view=rev Author: auria Date: 2011-06-18 16:45:59 +0000 (Sat, 18 Jun 2011) Log Message: ----------- Add some type checking to properties in the panel; especially useful when converting from 2.4 to 2.5 since we used to use string properties everywhere, but now we use int or float properties Modified Paths: -------------- media/trunk/blender_25/stk_panel.py Modified: media/trunk/blender_25/stk_panel.py =================================================================== --- media/trunk/blender_25/stk_panel.py 2011-06-18 16:39:17 UTC (rev 8952) +++ media/trunk/blender_25/stk_panel.py 2011-06-18 16:45:59 UTC (rev 8953) @@ -12,8 +12,6 @@ "tracker_url": "https://sourceforge.net/apps/trac/supertuxkart/", "category": "Object"} -# TODO: verify properties have the right type : isinstance(bpy.data.scenes[0]['sky_speed_x'], float) - import bpy from collections import OrderedDict import getpass @@ -120,6 +118,29 @@ if isinstance(props[p], StkEnumProperty): if v in props[p].values: createProperties(object, props[p].values[v].subproperties) + + # check the property has the right type + elif isinstance(props[p], StkFloatProperty) : + + if not isinstance(object[p], float): + try: + object[p] = float(object[p]) + except: + object[p] = props[p].default + + elif isinstance(props[p], StkIntProperty): + + if not isinstance(object[p], int): + try: + object[p] = int(object[p]) + except: + object[p] = props[p].default + + elif isinstance(props[p], StkProperty) and not isinstance(object[p], str): + try: + object[p] = str(object[p]) + except: + object[p] = props[p].default #! An enum property class StkEnumProperty(StkProperty): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |