Hey Cesar
nice idea
in recent hours i found a way in one module that is like your idea but with
list:
callbacks = []
def do_something():
print "anything"
def main():
global callbacks
idx = OpenMaya.MEventMessage.addEventCallback("timeChanged", get_sec)
callbacks.append(idx)
def remove_callbacks():
for call in callbacks:
OpenMaya.MMessage.removeCallback(call)
it works fine for me
thanks man
thanks to marcus
On Thu, Jul 14, 2016 at 3:03 PM, Cesar Saez <[email protected]> wrote:
> You don't even need an external module to save your ids in memory :)
>
> ---
>
> from maya import OpenMaya
>
>
> # setup
> if not globals().get("my_callbacks"): # this avoid overriding the ids on
> re-run
> my_callbacks = dict()
>
> def addCallback(func):
> idx = OpenMaya.MEventMessage.addEventCallback("timeChanged", func)
> my_callbacks[idx] = func
> return idx
>
> def clearCallbacks():
> for idx in my_callbacks.keys():
> OpenMaya.MEventMessage.removeCallback(idx)
> my_callbacks.clear()
>
> # usage
> def do_something(*args, **kwargs):
> print "hello"
>
> addCallback(do_something)
> addCallback(do_something)
> addCallback(do_something)
>
> print my_callbacks # {id: func}
> clearCallbacks()
> print my_callbacks # empty
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPamJi_RT%3DNjaZSi1-s_1WXHdKTQGmJEguP_QpXJ-_knJNfZTQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPamJi_RT%3DNjaZSi1-s_1WXHdKTQGmJEguP_QpXJ-_knJNfZTQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
Bests,
madoodia
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CADvbQw%2Bzdx%3Deee4UbHQjMq5Ym5i7hye6W%2B-k6ZnsDUmzDUJF_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.