Author Topic: Menu Changed Property Handler  (Read 385 times)

garry23

  • Hero Member
  • *****
  • Posts: 1524
Menu Changed Property Handler
« 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.

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: Menu Changed Property Handler
« Reply #1 on: December 10, 2017, 04:34:54 AM »
You should already be able to do that (for menus that you create): menu:select

See copy2m.lua for an example:

Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 1524
Re: Menu Changed Property Handler
« Reply #2 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

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: Menu Changed Property Handler
« Reply #3 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. 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

  • Hero Member
  • *****
  • Posts: 1524
Re: Menu Changed Property Handler
« Reply #4 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