Jump to content
Sign in to follow this  
Jibberish

Radios and Checkboxes in the same window

Recommended Posts

Jibberish

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

Share this post


Link to post
Share on other sites
InunoTaishou

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

 

Share this post


Link to post
Share on other sites
Jibberish

No, I want both Checkboxes and Radio buttons in the same window. I think I have a solution though.

Thanks for trying!

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Silas
      By Silas
      Hello everyone,
      First, watch the screenshot I attached:

      The background beneath the radios is that a value is subtracted from Player 1, and added to player 2, in the case of the screenshot I made.
      You can see that I created 2 radio groups. On the upper part, radio 1 and 2, and on the lower part radio 5 and 6. Now I automated the buttons in such a way ,that when in group 1 player 1 is selected, player 2 in group 2 automatically gets checked for you. Same thing when checking player 2 in the upper part: player 1 gets checked on the lower part. I did this because there is no reason selecting player 1 or 2 twice, because nothing will change. Now that runs smoothly using this script:
      If GUICtrlRead($Radio1)=1 And Not BitAND(GUICtrlGetState($Radio6),1) And Not BitAND(GUICtrlGetState($Radio5),1) Then GUICtrlSetState($Radio6,1) If GUICtrlRead($Radio2)=1 And Not BitAND(GUICtrlGetState($Radio5),1) And Not BitAND(GUICtrlGetState($Radio6),1) Then GUICtrlSetState($Radio5,1) If GUICtrlRead($Radio5)=1 And Not BitAND(GUICtrlGetState($Radio2),1) And Not BitAND(GUICtrlGetState($Radio1),1) Then GUICtrlSetState($Radio2,1) If GUICtrlRead($Radio6)=1 And Not BitAND(GUICtrlGetState($Radio1),1) And Not BitAND(GUICtrlGetState($Radio2),1) Then GUICtrlSetState($Radio1,1) But there is a problem when clicking on a radio in group 2, the lower one. It is very hard to check one, because for some reason the radio get's deselected instantly most of the time. I already tried to prevent it by using the second BitAND() in the codes I shared (It doesn't check the radio automatically if the other radio in the other group is selected, meaning that the user want's to switch the radios). But it didn't work.
      Does somebody know why you sometimes can't check radio 5 or 6 (the lower part)?
    • bbProg
      By bbProg
      Hi,
       
      how can I wait activate for windows with information as in the photos attached?
      Class is not being recognized by the script.
       
      thanks in advanced.



    • OneSolution
      By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone

      I was playing a little bit with "Screen Capture" UDF, and I was trying to make a "Window" capture, but, since I made a GUI which through I fire the event "Capture", my GUI is captured as well, and I don't want to
      This is the line of code that makes the capture:
       
      _ScreenCapture_CaptureWnd($strScreenCaptureFileName, $objActiveWindow, 0, 0, -1, -1, False) And these are the lines of code which select the "active" window:
       
      Local $objCurrentWindow = 9999 If _IsPressed("01") Then $objCurrentWindow = WinGetHandle("[ACTIVE]") If $objCurrentWindow <> $objMyGUI Then $objActiveWindow = $objCurrentWindow EndIf EndIf Sorry If I made stupid mistakes
      Thanks in advance.

      Francesco
×