Working With Radio Boxes [#6262]

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Working With Radio Boxes [#6262]

Re: Working With Radio Boxes [#6262]

by Peke » Thu Feb 04, 2010 1:41 am

Due above noted bug here is ShowModal Example where you can get what Radio Box is checked.

Code: Select all

Sub TestSCript
   Script.Reload(Script.ScriptPath) 'Script Reload on INI Sheet so that updates can be checked

   Dim Form

   FormWidth=250
   FormHeight=300
   
   ' Create the window to be shown
   Set Form = SDB.UI.NewForm
   Form.Common.SetRect 0, 0, FormWidth, FormHeight
   Form.FormPosition = 4   ' Screen Center
   Form.Caption = "IR Controls"
   Form.StayOnTop = True

   'Create a label at the top
   Set TheLabel = SDB.UI.NewLabel(Form)
   TheLabel.Caption = "Tree Node Name"
   TheLabel.Common.Left = 10
   TheLabel.Common.Top = 10
   TheLabel.Common.Width = 150
   TheLabel.Common.FontBold=1
   SDB.Objects("IRFormLabel") = TheLabel
   
   ' Create a TreeList for selection of data to be shown
   Set MTL = SDB.UI.NewTreeList(Form)
   MTL.Common.SetRect 10, 30, (FormWidth-40), (FormHeight-100)
   MTL.Common.ControlName = "CurrentlyPlaying"
   SDB.Objects("IRFormNode") = MTL

   Script.RegisterEvent MTL, "OnGetText", "MTLGetText"
  
   Set node1 = MTL.AddNode(Nothing) ' nothing puts it as a parent
   node1.TreeList.Common.ControlName = "CurrentlyPlaying1"
   node1.UserText = "Currently Playing"

   Set Node1Child1 = MTL.AddNode(node1)
   Node1Child1.UserText = "Enqueue Album"
   Node1Child1.CheckType = 3
   Node1Child1.CheckState = 0

   Set Node1Child1 = MTL.AddNode(node1)
   Node1Child1.UserText = "Enqueue Album 2"
   Node1Child1.CheckType = 3
   Node1Child1.CheckState = 1

   node1.Expanded = True 'this needs to be set here after all child nodes are added or node would not be expanded
   
   Set CBut = SDB.UI.NewButton(Form)
   CBut.Caption = "Check"
   CBut.OnClickFunc = "CbutClick"
   CBut.UseScript = Script.ScriptPath
   Cbut.Common.SetRect 10, (FormHeight-60), 50, 20 

   '------------- If we only show the forms nods do not get Updated
   'Form.Common.Visible = True                ' Only show the form, don't wait for user input
   'SDB.Objects("IRHelperForm") = Form  ' Save reference to the form somewhere, otherwise it would simply disappear
   '-------------

   '------------- If we show form as modal than it gets updated.
   Form.ShowModal
   '-------------

   Script.UnRegisterHandler "MTLGetText"
End Sub

Function MTLGetText(treenode, columnid)
  If InEventHandler Then Exit Function

  'Show Msg Box to see what will be shown in Tree Node
  'Dim resi
  'resi = SDB.MessageBox( treenode.UserText, mtError, Array(mbOk))
  SDB.Objects("IRFormLabel").Caption = "Node Name: "&treenode.UserText
  MTLGetText = treenode.UserText 'Return text of Node
End Function

Sub CbutClick( Btn) 'Check which ones are selected
  Dim resi
  
  Set treenode = SDB.Objects("IRFormNode") 'get treelist object
  Set WorkingNode = treenode.FirstNode 'Get first treenode
  While not WorkingNode is Nothing 'Set loop thrum all Tree Root Nodes
    If WorkingNode.HasChildren Then 'Check if TreeNode Has Child Nodes in this case Radio button nodes
      Set NextWorkingNode = WorkingNode.FirstChild 'Load first child nodes
      Set NextWorkingNodeChild = NextWorkingNode 'Remember treenode object
      While Not NextWorkingNodeChild Is Nothing 'create loop thrum childnodes
        If NextWorkingNodeChild.CheckState = 1 Then resi = SDB.MessageBox( NextWorkingNodeChild.UserText&" Is Checked", mtInformation, Array(mbOk)) 'If checked show MSGBox
        Set NextWorkingNodeChild = NextWorkingNodeChild.NextSibling 'get next child node
        If Not NextWorkingNodeChild Is Nothing Then Set NextWorkingNode = NextWorkingNodeChild 'check if next childnode exist remember is last known node
      Wend
    Set WorkingNode = NextWorkingNode.NextNode 'retrieve next Root Node if exist
    End If
  Wend
End Sub
For others that want to test this you need to save this code to Test form modal.vbs in Scripts folder and add these lines to Scripts.ini

Code: Select all

[SampleFormScript1]
Filename=Test form modal.vbs
Procname=TestSCript
Order=99
DisplayName=Create new Form Modal
Description=This will create New MM form and show it as modal
Language=VBScript
ScriptType=0

Re: Working With Radio Boxes [#6262]

by Peke » Wed Feb 03, 2010 11:56 pm

It looks that there is a bug when filling names of TreeList nodes
I added it to http://www.ventismedia.com/mantis/view.php?id=6262

Re: Working With Radio Boxes

by MarquisEXB » Tue Feb 02, 2010 8:13 am

Here's the full code I'm using:

Code: Select all

sub TestSCript
	Dim Form
 
	FormWidth=250
	FormHeight=250
	
	' Create the window to be shown
	Set Form = SDB.UI.NewForm
	Form.Common.SetRect 0, 0, FormWidth, FormHeight
	Form.FormPosition = 4   ' Screen Center
	Form.Caption = "IR Controls"
	Form.StayOnTop = True

	'Create a label at the top
	Set TheLabel = SDB.UI.NewLabel(Form) 
	TheLabel.Caption = "Hit the Record Button to Select." 
	TheLabel.Common.Left = 10
	TheLabel.Common.Top = 10
	TheLabel.Common.Width = 150
	TheLabel.MultiLine=True
	TheLabel.Common.FontBold=1    ' Top
	
	' Create a TreeList for selection of data to be shown
	Set MTL = SDB.UI.NewTreeList(Form)
	MTL.Common.SetRect 10, 50, (FormWidth-40), (FormHeight-100)
	MTL.Common.ControlName = "CurrentlyPlaying"

	
	Set node1 = MTL.AddNode(Nothing) ' nothing puts it as a parent
	node1.UserText = "Currently Playing"
	node1.Expanded = True 
	
		
	Set Node1Child1 = MTL.AddNode(node1) 
	Node1Child1.UserText = "Enqueue Album"
	Node1Child1.CheckType = 3
	Node1Child1.CheckState = 0

	
	Set Node1Child2 = MTL.AddNode(node1) 
	Node1Child2.UserText = "Enqueue Artist"
	Node1Child2.CheckType = 3
	Node1Child2.CheckState = 0

  
	Set node2 = MTL.AddNode(Nothing)
	node2.UserText = "TreeList"

	Set Node2Child1 = MTL.AddNode(node2) 
	Node2Child1.UserText = "Enqueue Song"
	Node2Child1.CheckType = 3
	Node2Child1.CheckState = 0
	
	Set Node2Child2 = MTL.AddNode(node2) 
	Node2Child2.UserText = "Enqueue Album"
	Node2Child2.CheckType = 3
	Node2Child2.CheckState = 0
	
	Set node3 = MTL.AddNode(Nothing)
	node3.UserText = "PlayList"

	Set Node2Child1 = MTL.AddNode(node3) 
	Node2Child1.UserText = "Remove Next Song"
	Node2Child1.CheckType = 3
	Node2Child1.CheckState = 0
	
	Set Node2Child2 = MTL.AddNode(node3) 
	Node2Child2.UserText = "Remove Song After"
	Node2Child2.CheckType = 3
	Node2Child2.CheckState = 0
	
	
	'Form.ActiveControl = MTL.Common.ControlName
	
	Form.Common.Visible = True                ' Only show the form, don't wait for user input
	SDB.Objects("IRHelperForm") = Form  ' Save reference to the form somewhere, otherwise it would simply disappear

	Script.RegisterEvent MTL, "OnFocusChanged", "MTLFocusChanged"
	Script.RegisterEvent MTL, "OnExpanding", "MTLExpanding"
	Script.RegisterEvent MTL, "OnGetText", "MTLGetText"
	
	'Kill the form in 10 seconds
	Set Timer1 = SDB.CreateTimer( 10000)   ' Pop up a message in 10 seconds
	Script.RegisterEvent Timer1, "OnTimer", "TestTimer1"
	
End Sub



Sub TestTimer1( Timer)
	Script.UnregisterEvents Timer  ' Terminate usage of this timer

	set Form = SDB.Objects("IRHelperForm")

	' kill the form
	SDB.Objects("IRHelperForm") = Nothing

End Sub



Sub MTLFocusChanged( Node, Column)
  'lbl.Caption = Node.Index & " - " & Column
End Sub
 
Sub MTLExpanding( Node)
  'MTL.AddNode( node)
  'MTL.AddNode( node)
  'MTL.AddNode( node)
End Sub
 
Function MTLGetText( Node, Column)
  If node.UserText<>"" Then
    MTLGetText = node.UserText
  Else
    MTLGetText = "Node index: " & node.index
  End If
End Function

Re: Working With Radio Boxes

by MarquisEXB » Fri Jan 29, 2010 9:52 pm

Hmm doesn't seem like I can find any code with radio boxes. Google turns up this post. This example from the wiki is what I copied, but it doesn't have any code that shows how to get which radio box is unchecked.

Re: Working With Radio Boxes

by MarquisEXB » Fri Jan 29, 2010 9:24 pm

Hmmm Lastfm uses checkboxes with

Code: Select all

UI.NewCheckBox(GBoxSubmit)
...
CheckBox1.Common.ControlName = "EnableLastFM"

[and then later to get the value]

Sheet.Common.ChildControl( "EnableLastFM").Checked
I'm using

Code: Select all

	Set Node1Child1 = MTL.AddNode(node1) 
	Node1Child1.UserText = "Enqueue Album"
	Node1Child1.CheckType = 3
	Node1Child1.CheckState = 0
Which doesn't seem to be able to be used with "Common.ControlName". Not sure what I'm doing wrong here. I'm connecting these to a treelist (which I like the functionality of), just not sure how to combine this...

Re: Working With Radio Boxes

by Peke » Fri Jan 29, 2010 6:30 pm

Example of Using Check boxes can be found in Last.fm scrobbler plugin.

Regarding Second thing you ask the best is to Save MTL as Object and then access it directly (Again there is example in scrobbler plugin where Toolbar button is updated according to Selected settings).

Hope this helps a little.

Working With Radio Boxes [#6262]

by MarquisEXB » Fri Jan 29, 2010 1:55 pm

Ok here's a script I'm working on below. First off how can I check which radio boxes are selected? Secondly, is there a way to dynamically add nodes/get data from there. For instance if I had something like CheckBoxOptions = array ("Enqueue Album", "Enqueue Artist"), how can I add check boxes for this and read if they are on/off?

Thanks in advance

Code: Select all

Sub TestScript
	FormWidth=250
	FormHeight=250
	
	' Create the window to be shown
	Set Form = SDB.UI.NewForm
	Form.Common.SetRect 0, 0, FormWidth, FormHeight
	Form.FormPosition = 4   ' Screen Center
	Form.Caption = "IR Controls"
	Form.StayOnTop = True

	'Create a label at the top
	Set TheLabel = SDB.UI.NewLabel(Form) 
	TheLabel.Caption = "Hit the Record Button to Select." 
	TheLabel.Common.Left = 10
	TheLabel.Common.Top = 10
	TheLabel.Common.Width = 150
	TheLabel.MultiLine=True
	TheLabel.Common.FontBold=1    ' Bold
	
	'Create TreeList
	Set MTL = SDB.UI.NewTreeList(Form)
	MTL.Common.SetRect 10, 50, (FormWidth-40), (FormHeight-100)

	' First Parent
	Set node1 = MTL.AddNode(Nothing) ' nothing puts it as a parent
	node1.UserText = "Currently Playing"
	node1.Expanded = True 
	
	'Checkbox 1
	Set Node1Child1 = MTL.AddNode(node1) 
	Node1Child1.UserText = "Enqueue Album"
	Node1Child1.CheckType = 3
	Node1Child1.CheckState = 0
  
	'Check box2
	Set Node1Child2 = MTL.AddNode(node1) 
	Node1Child2.UserText = "Enqueue Album"
	Node1Child2.CheckType = 3
	Node1Child2.CheckState = 0
	
	Script.RegisterEvent MTL, "OnGetText", "MTLGetText"
	
	'Show form
	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
End Sub


Function MTLGetText( Node, Column)
  If node.UserText<>"" Then
    MTLGetText = node.UserText
  Else
    MTLGetText = "Node index: " & node.index
  End If
End Function


Top