Page 1 of 1

Toggle Button Code Snippet

Posted: Mon Jan 18, 2010 8:42 am
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.

Re: Toggle Button Code Snippet

Posted: Mon Jan 18, 2010 11:54 am
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 :)

Re: Toggle Button Code Snippet

Posted: Mon Jan 18, 2010 12:13 pm
by Sizzly
That looks like exactly what I need!

Many thanks!