Menu Changed Property Handler

Started by garry23, December 09, 2017, 12:43:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

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.

dmilligan

You should already be able to do that (for menus that you create): menu:select

See copy2m.lua 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

garry23

@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

dmilligan

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. 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.

garry23

@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