shbatm / MMM-OnScreenMenu

MagicMirror² utility module that provides a simple on screen menu for control
MIT License
62 stars 22 forks source link

Toggle specific instance #11

Closed cdkonecny closed 5 years ago

cdkonecny commented 5 years ago

Is there a way to toggle visibility of a specific instance of a module, say MMM-iFrame, since I have a number of instances of this module? Thanks!

shbatm commented 5 years ago

Not at the moment. I can add something when I get home next week.

cdkonecny commented 5 years ago

Oh, that would be great. Thank you so much

On October 6, 2018 8:12:18 PM shbatm notifications@github.com wrote:

Not at the moment. I can add something when I get home next week. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

shbatm commented 5 years ago

Feature has been added. Please update to 0.1.5 and try it.

Basically, add instance: "whatever" to both the menu item and the other module's config section and you should be able to toggle the module that matches both that name and instance name.

Relevant new section of README: If you have multiple instances of a module, add an instance name to both that module's config and the menu item (see third example below)

Examples:

moduleHide1: { title: "Hide Clock", icon: "minus-square", name: "clock" },
moduleShow1: { title: "Show Clock", icon: "plus-square", name: "clock" },
moduleToggle1: { title: "Toggle iFrame", icon: "info-circle", name: "MMM-iFrame", instance: "Frame1"}
   # For example above, in MMM-iFrame-s config section, you also need to add `instance: "Frame1"`
MCWChu commented 5 years ago

Can I toggle (hide/show) of say "clock" or any module? I'm just a hobbyist, not a programmer. Could you give me an example how to add an instance in the config of a module? Thanks.

shbatm commented 5 years ago

Here's an example modules section of a config file. This has 2 different "clock" modules, one digital at the top left of the screen and one with digital and analog clocks in the center. The menu has 2 options for toggling the two different clocks.

modules: [
  {
    module: "alert",
  },
  {
    module: "updatenotification",
    position: "top_bar"
  },
  {
    module: "clock",
    position: "middle_center",
    config: {
      instance: "analog_clock",
      displayType: "both"
    }
  }, 
  {
    module: "clock",
    position: "top_left",
    config: {
      instance: "digital_clock"
    }
  },
  {
    module: 'MMM-OnScreenMenu',
    position: 'bottom_right',
    /* Valid positions: 'top_right', 'top_left', 'bottom_right', 'bottom_left' */
    config: {
      menuItems: {
        moduleToggle1: { 
          title: "Toggle Analog Clock", 
          icon: "clock-o", 
          name: "clock", 
          instance: "analog_clock"
        },
        moduleToggle2: { 
          title: "Toggle Digital Clock", 
          icon: "clock-o", 
          name: "clock", 
          instance: "digital_clock" // 
        },
        restart: { title: "Restart MagicMirror", icon: "refresh" },
        reboot: { title: "Reboot", icon: "spinner" },
        shutdown: { title: "Shutdown", icon: "power-off" }
      },
    }
  }
]

Note the instance: lines in the 2 clock sections and how they match up to the MMM-OnScreenMenu menuItems section.

MCWChu commented 5 years ago

I see.  This way I can toggle between analog and digital.  What about toggling between on and off (show/hide clock)? Mcwchu

Sent from Yahoo Mail on Android

On Wed, Nov 14, 2018 at 17:21, shbatmnotifications@github.com wrote:
Here's an example modules section of a config file. This has 2 different "clock" modules, one digital at the top left of the screen and one with digital and analog clocks in the center. The menu has 2 options for toggling the two different clocks. modules: [ { module: "alert", }, { module: "updatenotification", position: "top_bar" }, { module: "clock", position: "middle_center", config: { instance: "analog_clock", displayType: "both" } }, { module: "clock", position: "top_left", config: { instance: "digital_clock" } }, { module: 'MMM-OnScreenMenu', position: 'bottom_right', / Valid positions: 'top_right', 'top_left', 'bottom_right', 'bottom_left' / config: { menuItems: { moduleToggle1: { title: "Toggle Analog Clock", icon: "clock-o", name: "clock", instance: "analog_clock" }, moduleToggle2: { title: "Toggle Digital Clock", icon: "clock-o", name: "clock", instance: "digital_clock" // }, restart: { title: "Restart MagicMirror", icon: "refresh" }, reboot: { title: "Reboot", icon: "spinner" }, shutdown: { title: "Shutdown", icon: "power-off" } }, } } ] Note the instance: lines in the 2 clock sections and how they match up to the MMM-OnScreenMenu menuItems section.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

MCWChu commented 5 years ago

Thanks a lot.  After putting your codes in my MM config file, I see how "instance" work.  I got what I want.

On Wednesday, November 14, 2018, 5:21:12 PM GMT+8, shbatm <notifications@github.com> wrote:  

Here's an example modules section of a config file. This has 2 different "clock" modules, one digital at the top left of the screen and one with digital and analog clocks in the center. The menu has 2 options for toggling the two different clocks. modules: [ { module: "alert", }, { module: "updatenotification", position: "top_bar" }, { module: "clock", position: "middle_center", config: { instance: "analog_clock", displayType: "both" } }, { module: "clock", position: "top_left", config: { instance: "digital_clock" } }, { module: 'MMM-OnScreenMenu', position: 'bottom_right', / Valid positions: 'top_right', 'top_left', 'bottom_right', 'bottom_left' / config: { menuItems: { moduleToggle1: { title: "Toggle Analog Clock", icon: "clock-o", name: "clock", instance: "analog_clock" }, moduleToggle2: { title: "Toggle Digital Clock", icon: "clock-o", name: "clock", instance: "digital_clock" // }, restart: { title: "Restart MagicMirror", icon: "refresh" }, reboot: { title: "Reboot", icon: "spinner" }, shutdown: { title: "Shutdown", icon: "power-off" } }, } } ] Note the instance: lines in the 2 clock sections and how they match up to the MMM-OnScreenMenu menuItems section.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.