Magic Lantern Forum

Developing Magic Lantern => Scripting Corner => Scripting API suggestions => Topic started by: garry23 on December 09, 2017, 12:43:21 PM

Title: Menu Changed Property Handler
Post by: garry23 on December 09, 2017, 12:43:21 PM
Use Case: look out for changes in a specific named menu or sub-menu.

Why: one script changes the state of another and this needs to be detected.

Suggested format: extend lua module property to handle the 'ML side' of life or even an event handler.
Title: Re: Menu Changed Property Handler
Post by: dmilligan on December 10, 2017, 04:34:54 AM
You should already be able to do that (for menus that you create): menu:select (https://builds.magiclantern.fm/lua_api/modules/menu.html#menu:select)

See copy2m.lua (https://builds.magiclantern.fm/lua_api/examples/copy2m.lua.html) for an example:


copy2m_menu = menu.new
{
    parent  = "Copy exposure to M",
    name    = "Enabled",
    help    = "Copy exposure settings (Tv, Av, ISO) when switching to M.",
    choices = {"OFF","ON"},
    value   = "OFF"
}

function copy2m_menu:select(delta)
    if self.value == "OFF" then self.value = "ON" else self.value = "OFF" end
    copy2m_update(self.value)
end
Title: Re: Menu Changed Property Handler
Post by: garry23 on December 10, 2017, 08:53:00 AM
@dmilligan

David I thought select only worked if the menu was being used, i.e. Is displayed.

My use case is that the menu handler is watching for menu changes made by other scripts, i.e. Like the property handler does for Canon items.

Or have I got it wrong...again  ;)

Cheers

Garry
Title: Re: Menu Changed Property Handler
Post by: dmilligan on December 10, 2017, 11:06:37 PM
Have you tried it?

It sounds like what you are actually trying to do is communicate between scripts and somewhat misusing the menu API to accomplish this. This is pretty classic xy problem (http://mywiki.wooledge.org/XyProblem). When you ask questions, it's much more helpful to state exactly what it is you are actually trying to do. Rather than finding some sort of alternative way to do it and then asking about that. There may be a much better solution to the original problem, or if an API is missing or lacking, we might have a much better idea what new functionality should be provided.
Title: Re: Menu Changed Property Handler
Post by: garry23 on December 10, 2017, 11:39:11 PM
@dmilligan

Sorry if I confused things.

I've got a work around going by having a dummy menu item in script A that can be switched by script B. Thus script A only needs to watch the menu item and take action.

Thanks for your feedback and help.

Cheers

Garry