Page 1 of 1

AddCallbackItem menu item, how to pass a variable

Posted: 05 Apr 2017, 15:47
by Fabian
Hi,
is there a way to pass a string from the menu item to the callback handler function. For dynamically created menu items I'd like to attach some information (directory path) that is passed from the menu item to the callback function. I've tried to abose the help string for this but for some reason I can't set .Help for submenu or callback items.

The only thing I've managed so far is to have a dictionary mapping based on the menu item lablel and having the callback function lookup from that based on in_ctxt.Source.Name in the callback function.

Thank you,
Fabian

Re: AddCallbackItem menu item, how to pass a variable

Posted: 05 Apr 2017, 16:45
by rray
Hi
would be the only idea I have too, some dictionary or JS object that you could put in in_ctxt.UserData.
-rr

Re: AddCallbackItem menu item, how to pass a variable

Posted: 05 Apr 2017, 23:57
by luceric
I don't remember how to do this, but another method is to generate the code of the callback on the fly.

It's something like you use "exec()" to generate the new function.

You would generate it a unique name, like "def my_callback_01():" and what it does is calls a common method you have with the parameter you need for it.