Toggle Button Code Snippet

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Sizzly
Posts: 106
Joined: Mon Apr 27, 2009 8:46 pm
Location: Worcester, MA
Contact:

Toggle Button Code Snippet

Post by Sizzly »

Greetings!

I was wondering if anyone could point me to a script that has a snippet of code to put a toggle button on the tool bar...

I'm trying to write a script to enable the play now but not continue option without having to go into the options menu.

I think I have the body of the code... But I'm lazy.
Rob
DJ Sizzly
http://djsizzly.com
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Toggle Button Code Snippet

Post by trixmoto »

Well in my "Monkey Rok" script the button is created in "onStartup" like this...

Code: Select all

  Dim ini : Set ini = SDB.IniFile
  ini.IntValue("MonkeyRok","OnIconIndex") = SDB.RegisterIcon("Scripts\MonkeyRok\monkeyrok_on.ico",0) 
  ini.IntValue("MonkeyRok","OffIconIndex") = SDB.RegisterIcon("Scripts\MonkeyRok\monkeyrok_off.ico",0)
  Dim btn : Set btn = SDB.Objects("MonkeyRokButt")
  If btn Is Nothing Then
    Set btn = ui.AddMenuItem(ui.Menu_TbStandard,0,0)
    btn.Caption = "MonkeyRok"
    btn.IconIndex = ini.IntValue("MonkeyRok","OffIconIndex")
    Set SDB.Objects("MonkeyRokButt") = btn
    Call Script.RegisterEvent(btn,"OnClick","ToggleContextPanel")
  End If
Then the rest of the relevant code (cut down a bit) looks like this...

Code: Select all

Sub ToggleContextPanel(i)
  If SDB.Objects("MonkeyRokPanel") Is Nothing Then
    Call ShowContextPanel()
    Exit Sub
  End If
  If SDB.Objects("MonkeyRokPanel").Common.Visible = False Then
    Call ShowContextPanel()
    Exit Sub
  End If
  Call HideContextPanel()
End Sub

Sub ShowContextPanel()
  Dim but : Set but = SDB.Objects("MonkeyRokButt")
  but.IconIndex = ini.IntValue("MonkeyRok","OnIconIndex")
  but.Hint = "Hide MonkeyRok"
End Sub

Sub HideContextPanel()
  Dim but : Set but = SDB.Objects("MonkeyRokButt")
  but.IconIndex = ini.IntValue("MonkeyRok","OffIconIndex")
  but.Hint = "Show MonkeyRok"
End Sub
Hope that helps :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Sizzly
Posts: 106
Joined: Mon Apr 27, 2009 8:46 pm
Location: Worcester, MA
Contact:

Re: Toggle Button Code Snippet

Post by Sizzly »

That looks like exactly what I need!

Many thanks!
Rob
DJ Sizzly
http://djsizzly.com
Post Reply