Scripting Help - controlling groups

My widget looks like this:


Group 4

Toggle 1-----Group 1

Master Toggle ----Toggle 2-----Group 2

Toggle 3-----Group 3

Basically, the various toggles in group 4 show and hide their respective groups, and the master toggle shows/hides group 4. I hope that's pretty clear, it was the best way I could describe it.

So far, I'm only using the inbuilt popup controller, but I think I need to use scripting, because here's what I'd like. When you click on the master toggle, it hides group 4, and also groups 1, 2, and 3. Ideally, I'd also like it to remember which of the groups was visible, so when you click it again, the groups that were open, open, and those that were previously closed remain close.

I realise I've described this really badly, and I've looked at sViz's controlling groups tut, but that didn't help.

Thanks.
5,292 views 5 replies
Reply #1 Top
If I understand you correctly Toggle 1, 2, and 3 comprise Group 4. Your Master Toggle controls group 4 and also if any of groups 1, 2, or 3 are visible it makes them invisible when making group 4 invisible and when making group 4 visible it restores group 1, 2, and 3 to their prior state(if any were visible they become visible again). That would require a script and some patience to work it out. If group 1, 2 and 3 could belong to their own parent object, it would make the script task easier.
Reply #2 Top
Currently the 'master control', the object that deals with most of the script per group, is the child of the master toggle. So, essentially all 3 groups share the same parent - the master toggle. Is that any help?

EDIT: Incidentally, you got what I was trying to do in one, even though my diagram came out all jumbled up.

EDIT EDIT: After a second closer read of sViz's tutorial, I managed to get the master toggle to toggle everything on and off. However, I can't get it to remember the state of the groups yet. I'm still working on this, but would still appreciate any help.
Reply #3 Top

I would personally do this through scripting, but that could just be since that's where I'm comfortable.

When I think of the word toggle, I think of the keyword Not. Seems like an escape to pessimism, but this is actually very useful. When you're in a script at any given position. If you need to toggle some object's value, like it's visibility, you could do something simple like this:

DesktopX.Object("ObjName").Visible = Not DesktopX.Object("ObjName").Visible

This could similarly be used in any situation where you have a boolean variable (one that has possible values of True or False). For example:

Private Sub ToggleIt()
  bToggled = Not bToggled
End Sub

If you could possibly describe what you're doing or mspaint a picture and reference that here, that could help to describe your situation.

-Mike
[Stardock Support]

Reply #4 Top
I had a go at your problem and I worked something out.

Let me make sure the setup is correct.

toggle 1- toggles group 1
toggle 2- toggles group 2
toggle 3- toggles group 3
toggle 1,2,3 make up group 4
Master toggle, toggles group 4. Via scripting it also toggles groups 1,2,3 if any are visible, and restores everything to their previous visibilty (true or false).
Master toggle is parent of toggle 1,2,3.


This script goes in the master toggle:

Dim grp1vis, grp2vis, grp3vis, grp4vis'--This goes at the very top of the script
'Called when L-click is released
Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
For Each elem In Desktopx.GroupObjects("group4")
If elem.visible = True Then
checkOthergroups
grp4vis = False
Else
grp4vis = True
End If
Next
setVisible
End If
End Function

Function checkOthergroups
For Each elem In desktopx.GroupObjects("group1")
If elem.visible = True Then
grp1vis = True
Else
grp1vis = False
End If
Next
For Each elem In desktopx.GroupObjects("group2")
If elem.visible = True Then
grp2vis = True
Else
grp2vis = False
End If
Next
For Each elem In desktopx.GroupObjects("group3")
If elem.visible = True Then
grp3vis = True
Else
grp3vis = False
End If
Next
End Function

Function setVisible
Select Case grp4vis
Case False
For Each elem In desktopx.GroupObjects("group1")
elem.visible = False
Next
For Each elem In desktopx.GroupObjects("group2")
elem.visible = False
Next
For Each elem In desktopx.GroupObjects("group3")
elem.visible = False
Next
For Each elem In desktopx.GroupObjects("group4")
elem.visible = False
Next
Case True
For Each elem In desktopx.GroupObjects("group1")
elem.visible = grp1vis
Next
For Each elem In desktopx.GroupObjects("group2")
elem.visible = grp2vis
Next
For Each elem In desktopx.GroupObjects("group3")
elem.visible = grp3vis
Next
For Each elem In desktopx.GroupObjects("group4")
elem.visible = True
Next
End Select
End Function


Basically, I check the visibilty of group 4 (the 3 toggles) and save their subsequent visibilty to a variable (meaning if they are visible I save "false" to a variable and if they are hidden I save "true" to a variable).
If group 4 is visible then I also check the visibilty of groups 1,2,3 and save their visibilty to respective variables.
After that I call a function to set the visibilty of all the objects based on whether or not their variables are true or false.

I hope this helps.
Reply #5 Top

sViz: Looks good to me   . Formatting might help improve the clarity though (not that inserting leading whitespace is an easy task in our Add A Reply form  )

For example:

Function Object_OnLButtonUp(x, y, dragged)

  If Not dragged Then

    For Each elem In Desktopx.GroupObjects("group4")
      If elem.visible = True Then
        checkOthergroups
        grp4vis = False
      Else
        grp4vis = True
      End If
    Next

    setVisible

  End If

End Function

-Mike
[Stardock Support]