From e039a631a9983472c3ec67fa3aea9e5495eef65e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 5 Jan 2012 06:05:45 +0000 Subject: add bpy collection method .find(key), so you can get the index of an item in a collection, -1 if not found. use this to replace bge text ui py function. --- release/scripts/startup/bl_ui/space_logic.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'release') diff --git a/release/scripts/startup/bl_ui/space_logic.py b/release/scripts/startup/bl_ui/space_logic.py index 79a3f72ff48..7057fed75d2 100644 --- a/release/scripts/startup/bl_ui/space_logic.py +++ b/release/scripts/startup/bl_ui/space_logic.py @@ -20,13 +20,6 @@ import bpy from bpy.types import Header, Menu, Panel -def get_id_by_name(properties, name): - """returns ID""" - for i, prop in enumerate(properties): - if prop.name == name: - return i - return -1 - class LOGIC_PT_properties(Panel): bl_space_type = 'LOGIC_EDITOR' bl_region_type = 'UI' @@ -42,20 +35,22 @@ class LOGIC_PT_properties(Panel): ob = context.active_object game = ob.game + is_font = (ob.type == 'FONT') - if ob.type == 'FONT': - prop = game.properties.get("Text") - if prop: - layout.operator("object.game_property_remove", text="Text Game Property", icon='X').index = get_id_by_name(game.properties, "Text") + if is_font: + prop_index = game.properties.find("Text") + if prop_index != -1: + layout.operator("object.game_property_remove", text="Renove Text Game Property", icon='X').index = prop_index row = layout.row() sub=row.row() sub.enabled=0 + prop = game.properties[prop_index] sub.prop(prop, "name", text="") row.prop(prop, "type", text="") # get the property from the body, not the game property row.prop(ob.data, "body", text="") else: - props=layout.operator("object.game_property_new", text="Text Game Property", icon='ZOOMIN') + props=layout.operator("object.game_property_new", text="Add Text Game Property", icon='ZOOMIN') props.name='Text' props.type='STRING' @@ -63,7 +58,7 @@ class LOGIC_PT_properties(Panel): for i, prop in enumerate(game.properties): - if ob.type == 'FONT' and prop.name == "Text": + if is_font and i == prop_index: continue box = layout.box() -- cgit v1.2.3