Toggle Button Code Snippet

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

Moderator: Gurus

Toggle Button Code Snippet

Postby Sizzly » Mon Jan 18, 2010 8:42 am

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.
Sizzly
 
Posts: 106
Joined: Mon Apr 27, 2009 8:46 pm
Location: Worcester, MA

Re: Toggle Button Code Snippet

Postby trixmoto » Mon Jan 18, 2010 11:54 am

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 trixmoto.net. If you're interested, check out my Uniface blog.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

Image Image
trixmoto
 
Posts: 9961
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK

Re: Toggle Button Code Snippet

Postby Sizzly » Mon Jan 18, 2010 12:13 pm

That looks like exactly what I need!

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


Return to Addons developer forum

Who is online

Users browsing this forum: No registered users and 4 guests