How to fire a function after select element on a UiList

Hi.
I’ve word in several programming language bue I’m quite new to python, and i dont quite understant the events of it. Right now i’m making an addon where i have markers names and markers frames on a UiList. Everything works fine, i can list everything perfectly.
But i want when i chose(click) an element of the UiList, for it to change the current frame.

My UiList is very simple:

class ListItem(bpy.types.PropertyGroup):

name = StringProperty(
       name="Name",
       description="A name for this item",
       default="Untitled")

frame = IntProperty(
       name="Any other property you want",
       description="",
       default=0)

class MY_UL_List(bpy.types.UIList):

    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):

    # We could write some code to decide which icon to use here...
    custom_icon = 'MARKER_HLT'

    # Make sure your code supports all 3 layout types
    if self.layout_type in {'DEFAULT', 'COMPACT'}:
        layout.label(item.name, icon = custom_icon)
        layout.label(str(item.frame))



    elif self.layout_type in {'GRID'}:
        layout.alignment = 'CENTER'
        layout.label("", icon = custom_icon)      


#class that draws the UiList

row.template_list(“MY_UL_List”, “The_List”, sce, “my_list”, sce, “list_index” )

register classes

Thank you in advance for your help

You can specify a callback function when registering the list_index property, that should do the trick.

http://www.blender.org/api/blender_python_api_2_74_release/bpy.props.html#update-example

It worked, thank you so much :slight_smile:

In the end it looked like:

def seListIndexFunction(self, value):
bpy.ops.generate_markers.change_marker() #other class function

def register():
bpy.types.Scene.list_index = bpy.props.IntProperty(name = “Index for my_list”, default = 0, update=seListIndexFunction)