Sample New Window - Report script: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Added remark about wiki problem, and added/removed spaces) |
||
Line 1: | Line 1: | ||
'''Important remark: due to a problem in the Wiki software, ''Shell_Explorer'' is displayed with an underscore instead of a dot. This isn't correct and the script won't work. Before running the script, be sure to change the underscore ( _ ) to a dot ( . )''' | |||
<source lang="vb"> | <source lang="vb"> | ||
' Sample New Window - Report script | ' Sample New Window - Report script | ||
Line 11: | Line 12: | ||
' Add a submenu to the View menu... | ' Add a submenu to the View menu... | ||
Set Mnu = UI.AddMenuItemSub( UI.Menu_View, -1, 1) | Set Mnu = UI.AddMenuItemSub(UI.Menu_View, -1, 1) | ||
Mnu.Caption = "Custom items" | Mnu.Caption = "Custom items" | ||
' ... and add Statistics item there | ' ... and add Statistics item there | ||
Set Mnu = UI.AddMenuItem( Mnu, 0, 0) | Set Mnu = UI.AddMenuItem(Mnu, 0, 0) | ||
Mnu.Caption = "&Statistics" | Mnu.Caption = "&Statistics" | ||
Mnu.UseScript = Script.ScriptPath | Mnu.UseScript = Script.ScriptPath | ||
Line 23: | Line 24: | ||
' Add Statistics item to tray icon menu... | ' Add Statistics item to tray icon menu... | ||
Set Mnu = UI.AddMenuItem( UI.Menu_TrayIcon, -1, 1) | Set Mnu = UI.AddMenuItem(UI.Menu_TrayIcon, -1, 1) | ||
Mnu.Caption = "&Statistics" | Mnu.Caption = "&Statistics" | ||
Mnu.UseScript = Script.ScriptPath | Mnu.UseScript = Script.ScriptPath | ||
Line 35: | Line 36: | ||
UI.AddMenuItemSep UI.Menu_TbStandard, 0, 0 | UI.AddMenuItemSep UI.Menu_TbStandard, 0, 0 | ||
Set Mnu = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0) | Set Mnu = UI.AddMenuItem(UI.Menu_TbStandard, 0, 0) | ||
Mnu.Caption = "Statistics" | Mnu.Caption = "Statistics" | ||
Mnu.UseScript = Script.ScriptPath | Mnu.UseScript = Script.ScriptPath | ||
Line 43: | Line 44: | ||
End Sub | End Sub | ||
Sub ShowIt( Itm) | Sub ShowIt(Itm) | ||
Set UI = SDB.UI | Set UI = SDB.UI | ||
Line 57: | Line 58: | ||
' Create a panel at the top of the window | ' Create a panel at the top of the window | ||
Set Head = UI.NewPanel( Form) | Set Head = UI.NewPanel(Form) | ||
Head.Common.Align = 1 ' Top | Head.Common.Align = 1 ' Top | ||
Head.Common.Height = 30 | Head.Common.Height = 30 | ||
' Create a DropDown for selection of data to be shown | ' Create a DropDown for selection of data to be shown | ||
Set Combo = UI.NewDropDown( Head) | Set Combo = UI.NewDropDown(Head) | ||
Combo.Common.SetRect 5, 5, 150, 25 | Combo.Common.SetRect 5, 5, 150, 25 | ||
Combo.Style = 2 ' List | Combo.Style = 2 ' List | ||
Line 72: | Line 73: | ||
' Create a panel at the bottom of the window | ' Create a panel at the bottom of the window | ||
Set Foot = UI.NewPanel( Form) | Set Foot = UI.NewPanel(Form) | ||
Foot.Common.Align = 2 ' Bottom | Foot.Common.Align = 2 ' Bottom | ||
Foot.Common.Height = 35 | Foot.Common.Height = 35 | ||
' Create a button that closes the window | ' Create a button that closes the window | ||
Set Btn = UI.NewButton( Foot) | Set Btn = UI.NewButton(Foot) | ||
Btn.Caption = "Close" | Btn.Caption = "Close" | ||
Btn.Common.SetRect Foot.Common.Width - 90, 9, 85, 24 | Btn.Common.SetRect Foot.Common.Width - 90, 9, 85, 24 | ||
Btn.Common.Hint = "Close this report" | Btn.Common.Hint = "Close this report" | ||
Btn.Common.Anchors = 4+8 ' Right+Bottom | Btn.Common.Anchors = 4 + 8 ' Right+Bottom | ||
Btn.UseScript = Script.ScriptPath | Btn.UseScript = Script.ScriptPath | ||
Btn.OnClickFunc = "OnClose" | Btn.OnClickFunc = "OnClose" | ||
' Create a web browser component | ' Create a web browser component | ||
Set WB = UI.NewActiveX( Form, " | Set WB = UI.NewActiveX(Form, "Shell_Explorer") | ||
WB.Common.Align = 5 ' Fill all client rectangle | WB.Common.Align = 5 ' Fill all client rectangle | ||
WB.Common.ControlName = "WB" | WB.Common.ControlName = "WB" | ||
Line 94: | Line 95: | ||
Form.Common.Visible = True ' Only show the form, don't wait for user input | Form.Common.Visible = True ' Only show the form, don't wait for user input | ||
SDB.Objects("Sample Report Form") = Form ' Save reference to the form somewhere, otherwise it would simply disappear | SDB.Objects("Sample Report Form") = Form ' Save reference to the form somewhere, otherwise it would simply disappear | ||
OnSelect( Combo) | OnSelect(Combo) | ||
End Sub | End Sub | ||
Line 105: | Line 106: | ||
Set WB = Form.Common.ChildControl("WB") | Set WB = Form.Common.ChildControl("WB") | ||
Set Doc = WB.Interf.Document | Set Doc = WB.Interf.Document | ||
If DD.ItemIndex=0 Then | If DD.ItemIndex = 0 Then | ||
Set QueryRes = SDB.Database.OpenSQL( "SELECT COUNT(*) FROM Songs") | Set QueryRes = SDB.Database.OpenSQL("SELECT COUNT(*) FROM Songs") | ||
Doc.Write "<h2>Library summary</h2>" | Doc.Write "<h2>Library summary</h2>" | ||
Doc.Write "Track count: " & QueryRes.StringByIndex(0) & "<br>" | Doc.Write "Track count: " & QueryRes.StringByIndex(0) & "<br>" | ||
Set QueryRes = SDB.Database.OpenSQL( "SELECT COUNT(*) FROM Artists") | Set QueryRes = SDB.Database.OpenSQL("SELECT COUNT(*) FROM Artists") | ||
Doc.Write "Artist count: " & QueryRes.StringByIndex(0) & "<br>" | Doc.Write "Artist count: " & QueryRes.StringByIndex(0) & "<br>" | ||
Doc.Close | Doc.Close | ||
End If | End If | ||
If DD.ItemIndex=1 Then | If DD.ItemIndex = 1 Then | ||
Doc.Write "Report 2" | Doc.Write "Report 2" | ||
Doc.Close | Doc.Close |
Revision as of 10:52, 2 November 2007
Important remark: due to a problem in the Wiki software, Shell_Explorer is displayed with an underscore instead of a dot. This isn't correct and the script won't work. Before running the script, be sure to change the underscore ( _ ) to a dot ( . )
' Sample New Window - Report script
'
' This script shows how to add new UI elements to MM. It adds several menu items and
' a toolbar item that all show a new dialog with a very simple statistics.
Sub OnStartup
Set UI = SDB.UI
' Add a couple of menu items here:
' Add a submenu to the View menu...
Set Mnu = UI.AddMenuItemSub(UI.Menu_View, -1, 1)
Mnu.Caption = "Custom items"
' ... and add Statistics item there
Set Mnu = UI.AddMenuItem(Mnu, 0, 0)
Mnu.Caption = "&Statistics"
Mnu.UseScript = Script.ScriptPath
Mnu.OnClickFunc = "ShowIt"
Mnu.Shortcut = "Ctrl+1"
Mnu.IconIndex = 35
' Add Statistics item to tray icon menu...
Set Mnu = UI.AddMenuItem(UI.Menu_TrayIcon, -1, 1)
Mnu.Caption = "&Statistics"
Mnu.UseScript = Script.ScriptPath
Mnu.OnClickFunc = "ShowIt"
Mnu.IconIndex = 35
' ... and separate it from other items
UI.AddMenuItemSep UI.Menu_TrayIcon, -1, 2
' And lastly add the item to the main toolbar, again separated from other items
UI.AddMenuItemSep UI.Menu_TbStandard, 0, 0
Set Mnu = UI.AddMenuItem(UI.Menu_TbStandard, 0, 0)
Mnu.Caption = "Statistics"
Mnu.UseScript = Script.ScriptPath
Mnu.OnClickFunc = "ShowIt"
Mnu.IconIndex = 35
Mnu.Hint = "Sample script that shows some statistics"
End Sub
Sub ShowIt(Itm)
Set UI = SDB.UI
' Create the window to be shown
Set Form = UI.NewForm
Form.Common.SetRect 100, 100, 500, 400
Form.Common.MinWidth = 200
Form.Common.MinHeight = 150
Form.FormPosition = 4 ' Screen Center
Form.SavePositionName = "Report form"
Form.Caption = "Statistics"
Form.StayOnTop = True
' Create a panel at the top of the window
Set Head = UI.NewPanel(Form)
Head.Common.Align = 1 ' Top
Head.Common.Height = 30
' Create a DropDown for selection of data to be shown
Set Combo = UI.NewDropDown(Head)
Combo.Common.SetRect 5, 5, 150, 25
Combo.Style = 2 ' List
Combo.AddItem "Summary"
Combo.AddItem "Artists"
Combo.ItemIndex = 0
Combo.UseScript = Script.ScriptPath
Combo.OnSelectFunc = "OnSelect"
' Create a panel at the bottom of the window
Set Foot = UI.NewPanel(Form)
Foot.Common.Align = 2 ' Bottom
Foot.Common.Height = 35
' Create a button that closes the window
Set Btn = UI.NewButton(Foot)
Btn.Caption = "Close"
Btn.Common.SetRect Foot.Common.Width - 90, 9, 85, 24
Btn.Common.Hint = "Close this report"
Btn.Common.Anchors = 4 + 8 ' Right+Bottom
Btn.UseScript = Script.ScriptPath
Btn.OnClickFunc = "OnClose"
' Create a web browser component
Set WB = UI.NewActiveX(Form, "Shell_Explorer")
WB.Common.Align = 5 ' Fill all client rectangle
WB.Common.ControlName = "WB"
WB.Interf.Navigate "about:" ' A trick to make sure document exists
Set Doc = WB.Interf.Document
Form.Common.Visible = True ' Only show the form, don't wait for user input
SDB.Objects("Sample Report Form") = Form ' Save reference to the form somewhere, otherwise it would simply disappear
OnSelect(Combo)
End Sub
Sub OnClose(Btn)
SDB.Objects("Sample Report Form") = Nothing ' Remove the last reference to our form which also causes it to disappear
End Sub
Sub OnSelect(DD)
Set Form = SDB.Objects("Sample Report Form")
Set WB = Form.Common.ChildControl("WB")
Set Doc = WB.Interf.Document
If DD.ItemIndex = 0 Then
Set QueryRes = SDB.Database.OpenSQL("SELECT COUNT(*) FROM Songs")
Doc.Write "<h2>Library summary</h2>"
Doc.Write "Track count: " & QueryRes.StringByIndex(0) & "<br>"
Set QueryRes = SDB.Database.OpenSQL("SELECT COUNT(*) FROM Artists")
Doc.Write "Artist count: " & QueryRes.StringByIndex(0) & "<br>"
Doc.Close
End If
If DD.ItemIndex = 1 Then
Doc.Write "Report 2"
Doc.Close
End If
End Sub