I'd like to announce some new scripting features that will appear in MM 2.5.2 so that you can prepare for them, comment, etc.
First of all, handling of COM events will be much simplified, you'll no longer have to use tricks with WScript, all will be possible in a single script file. You'll only use Script.RegisterEvent command with 3 parameters: Object, it's event name (string) and script procedure name that handles the event (string). In the following script you can see several examples of usage. You can for example see a timer there or feedback to start of playback or paused playback:
Code: Select all
Sub OnStartup
Script.RegisterEvent SDB, "OnShutdown", "SDBShutdown"
Script.RegisterEvent SDB, "OnTrackProperties", "SDBTrackProperties"
Script.RegisterEvent SDB, "OnPlay", "SDBPlay"
Script.RegisterEvent SDB, "OnPause", "SDBPause"
Set Tmr = SDB.CreateTimer( 10000) ' Pop up a message in 10 seconds
' Script.RegisterEvent Tmr, "OnTimer", "TestTimer"
End Sub
Sub SDBTrackProperties( tracks)
SDB.MessageBox "Wow, track properties were modified for "&tracks.count&" track(s)!", mtInformation, Array(mbOk)
' Script.UnregisterEvents SDB
End Sub
Sub SDBShutdown
SDB.MessageBox "MediaMonkey is finishing... :(", mtInformation, Array(mbOk)
End Sub
Sub SDBPlay
SDB.MessageBox "Started playback of "&SDB.Player.CurrentSong.ArtistName&_
" - "&SDB.Player.CurrentSong.Title, mtInformation, Array(mbOk)
End Sub
Sub SDBPause
If SDB.Player.isPaused Then
SDB.MessageBox "Playback paused", mtInformation, Array(mbOk)
End If
End Sub
Sub TestTimer( Timer)
SDB.MessageBox "10 seconds elapsed!", mtInformation, Array(mbOk)
Script.UnregisterEvents Timer ' Terminate usage of this timer
End SubCode: Select all
Sub OnStartup
Set UI = SDB.UI
' Create the window to be shown
Set Form = UI.NewForm
Form.Common.SetRect 100, 100, 500, 400
Form.FormPosition = 4 ' Screen Center
Form.Caption = "Test"
Script.RegisterEvent Form.Common, "OnResize", "FormResize"
Set Lbl = UI.NewLabel( Form)
Lbl.Common.ControlName = "Lbl"
Lbl.Common.SetRect 10, 10, 100, 16
Set ChB = UI.NewCheckBox( Form)
ChB.Common.ControlName = "ChB"
ChB.Common.SetRect 10, 50, 100, 20
ChB.Caption = "Enabled"
Script.RegisterEvent ChB.Common, "OnClick", "ChBClick"
Set Btn = UI.NewButton( Form)
Btn.Common.ControlName = "Btn"
Btn.Common.SetRect 140, 48, 80, 25
Btn.Caption = "Test"
Script.RegisterEvent Btn, "OnClick", "BtnClick"
ChBClick( Form)
Form.ShowModal
Script.UnregisterAllEvents
End Sub
Sub FormResize( Form)
Set FC = Form.Common
Set Lbl = FC.ChildControl("Lbl")
Lbl.Caption = "("&FC.Left&","&FC.Top&")-("&FC.Width&","&FC.Height&")"
End Sub
Sub BtnClick
SDB.MessageBox "Wow, button clicked!", mtInformation, Array(mbOk)
End Sub
Sub ChBClick( ChB)
Set FC = ChB.Common.TopParent.Common
Set Btn = FC.ChildControl("Btn")
Set ChB = FC.ChildControl("ChB")
Btn.Common.Enabled = ChB.Checked
End SubCode: Select all
Dim Mnu, Pnl, Lbl, Lbl2
Sub OnStartup
Set UI = SDB.UI
Set Pnl = UI.NewDockablePersistentPanel("TestingPanel")
if Pnl.IsNew then
Pnl.DockedTo = 2
Pnl.Common.Width = 250
end if
Pnl.Caption = "My test"
Script.RegisterEvent Pnl, "OnClose", "PnlClose"
Set Lbl = UI.NewLabel(Pnl)
Lbl.Autosize = false
Lbl.Multiline = true
Lbl.Common.SetRect 10, 10, Pnl.Common.Width-20, Pnl.Common.Height-20
Lbl.Common.Anchors = 15 '1+2+4+8
' Add menu item that shows panel after it is closed
Set Sep = SDB.UI.AddMenuItemSep(SDB.UI.Menu_View,0,0)
Set Mnu = SDB.UI.AddMenuItem(SDB.UI.Menu_View,0,0)
Mnu.Caption = "My testing panel"
Mnu.Checked = Pnl.Common.Visible
Script.RegisterEvent Mnu, "OnClick", "ShowPanel"
Script.RegisterEvent SDB, "OnChangedSelection", "OnSelection"
End Sub
Sub ShowPanel(Item)
Pnl.Common.Visible = not Pnl.Common.Visible
Mnu.Checked = Pnl.Common.Visible
End Sub
Sub PnlClose( Item)
Mnu.Checked = false
End Sub
Sub OnSelection
Lbl.Caption = "Selected tracks: " & SDB.CurrentSongList.Count
End SubJiri

