Jump to content

Radios and Checkboxes in the same window


Recommended Posts

Hi,

I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.

I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.

I'd like to use one window with both checkboxes and radio buttons.

I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)

Func CheckOptions()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("SGX4CP Options", 275, 250)

    ; Create a checkbox control.
    Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25)
    Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25)
    Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25)
    GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED)

    Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25)
    Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25)
    GUICtrlSetState($iLogCheckbox, $GUI_CHECKED)
    Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $iLoopCheckbox
                If _IsChecked($iLoopCheckbox) Then
                    $bLoopChecked = True
                Else
                    $bLoopChecked = False
               EndIf

            Case $iFullScreenCheckbox
                if _IsChecked($iFullScreenCheckbox) Then
                    $bFullScreenChecked = True
                Else
                    $bFullScreenChecked = False
                EndIf

            Case $iRestartPlaybackCheckbox
                if _IsChecked($iRestartPlaybackCheckbox) Then
                    $bRestartPlaybackChecked = True
                Else
                    $bRestartPlaybackChecked = False
                EndIf

            Case $iDisableSleepCheckbox
                if _IsChecked($iDisableSleepCheckbox) Then
                    $bDisableSleepChecked = True
                Else
                    $bDisableSleepChecked = False
                EndIf

            Case $iLogCheckbox
                if _IsChecked($iLogCheckbox) Then
                    $bLogChecked = True
                Else
                    $bLogChecked = False
                EndIf
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc

Func RadioCheck()
    GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered

    Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10)
    Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40)
    Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70)
    GUICtrlSetState($idRadio1, $GUI_CHECKED)
    Local $idClose = GUICtrlCreateButton("Start Test", 120,100)

    GUISetState(@SW_SHOW)

    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()
        Select
            Case $idMsg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.')
                $bTestSelectForever = True
            Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.')
                $bTestSelect3Times = True
            Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED
                MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.')
                $bTestSelectSingleVideo = True
        EndSelect
    WEnd
EndFunc

I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.

I planned to remove the Loop checkbox and only enable it if Radio2 is selected.

Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?

Thanks

Jibberish

Link to comment
Share on other sites

I'm sorry but it's really difficult to try and understand what you're trying to explain in your post (it's probably not you, pretty sure it's me). I think you mean you want a checkbox or a radio to only be available if another radio/checkbox is selected? Something like this?

#include <GUIConstants.au3>

Global $hMain = GUICreate("", 400, 400)
Global $rdo1 = GUICtrlCreateRadio("Radio 1", 10, 10, 100, 20)
Global $rdo2 = GUICtrlCreateRadio("Radio 2", 10, 35, 100, 20)
Global $aCheckBox1[4]
Global $aCheckBox2[10]

For $i = 0 to UBound($aCheckBox1) - 1
    $aCheckBox1[$i] = GUICtrlCreateCheckbox("[" & $i & "] Checkbox for Radio 1", 120, 10 + ($i * 20), 150, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
Next

For $i = 0 to UBound($aCheckBox2) - 1
    $aCheckBox2[$i] = GUICtrlCreateCheckbox("[" & $i & "] Checkbox for Radio 2", 120, 10 + ($i * 20), 150, 20)
    GUICtrlSetState(-1, $GUI_HIDE)
Next

GUISetState(@SW_SHOW, $hMain)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit
        Case $rdo1
            ToggleCheckBoxes($aCheckBox2, $GUI_HIDE)
            ToggleCheckBoxes($aCheckBox1, $GUI_SHOW)
        Case $rdo2
            ToggleCheckBoxes($aCheckBox1, $GUI_HIDE)
            ToggleCheckBoxes($aCheckBox2, $GUI_SHOW)
    EndSwitch
WEnd

Func ToggleCheckBoxes($aCheckBoxes, $iState)
    For $i = 0 to UBound($aCheckBoxes) - 1
        GUICtrlSetState($aCheckBoxes[$i], $iState)
    Next
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...