diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-05 10:05:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-05 10:05:45 +0400 |
commit | e039a631a9983472c3ec67fa3aea9e5495eef65e (patch) | |
tree | f39ab0a2a6a752d32806ed0e9574b729f45300a8 /release/scripts/startup/bl_ui/space_logic.py | |
parent | 8d55b7bf0e43b655a9e74e4325ee835cc84355bb (diff) |
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.
Diffstat (limited to 'release/scripts/startup/bl_ui/space_logic.py')
-rw-r--r-- | release/scripts/startup/bl_ui/space_logic.py | 21 |
1 files changed, 8 insertions, 13 deletions
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() |