After rereading your first post and your latest post, I will try to answer both together.
Maya already has a system work working with events through mel or python by using scriptJobs. There is a big list of events that you can choose from to trigger your scriptJob. The code for generating those events is already part of the maya UI. So for example when you select something maya generate a SelectionChanged event. If you have a scriptJob created that is waiting for this event, it will now run.
If you want to create your own events, then there a three things you need to do. 1. Register the event, 2. Tell maya what to do when the event happens, 3. Make the event happen.
To register an even you just need to tell maya… “please register an event called myEvent”. This is done with
om.MUserEventMessage.registerUserEvent(‘myEvent’)
and with that one line part 1 is taken care of.
Telling maya what to do when the event happens is also one line
callbackId =om.MUserEventMessage.addUserEventCallback(‘myEvent’, myFunc)
This tells maya to run a function called myFunc when the event happens.
To make the event happen is just one more line of code
om.MUserEventMessage.postUserEvent(‘myEvent’)
I think that maybe you are wondering where to put that last line? Well it could be anywhere. You could just type it into the script editor and do it there, but probably you want to put it inside another script. I could explain more, but without knowing what you are trying to do, I’d probably just be confusing things.
David