jhegener Posted February 23, 2005 Share Posted February 23, 2005 (edited) Hi guys, I seem to have gotten the hang of a few of the GUI basics and was able to create a simple script that checks the state of a single group of radio buttons when a button is clicked. See this sample sniplet: GUICreate($TITLEBAR, 400, 250) GUICtrlCreateLabel ("Select the images you want to rename.", 20, 20, 350, 50, $SS_CENTER) GuiCtrlCreateGroup ("Selections ", 20, 120, 200, 100) $RADIO1 = GUICtrlCreateRadio ("Rename Weekly to Monthly ", 40, 140) GUICtrlSetState ($RADIO1, $GUI_CHECKED) $RADIO2 = GUICtrlCreateRadio ("Rename Daily to Weekly ", 40, 165) $RADIO3 = GUICtrlCreateRadio ("Exit Program ", 40, 190) $PROCEEDID = GUICtrlCreateButton ("Proceed ", 280, 155) $PROGRESSID = GuiCtrlCreateProgress (120, 85, 150, 20) GuiCtrlSetData (-1, 0) GuiCtrlCreateLabel ("Progress: ", 60, 88) GUISetState () Do $MSG = GUIGetMsg () Select Case $MSG = $PROCEEDID GuiCtrlSetData ($PROGRESSID, 0) If GUICtrlRead ($RADIO1) = 1 Then $SOURCE = "Weekly" $DEST = "Monthly" RenameTree($SOURCE, $DEST) ElseIf GUICtrlRead ($RADIO2) = 1 Then $SOURCE = "Daily" $DEST = "Weekly" RenameTree($SOURCE, $DEST) ElseIf GUICtrlRead ($RADIO3) = 1 Then Exit EndIf EndSelect Until $MSG = $GUI_EVENT_CLOSE But what I'd like to do now is poll the state of *several* groups of radio buttons (and checkboxes) when the 'proceed' button is clicked. The only way that I can think of processing multiple groups is just with a big table of if/then/endif statements but I know that can't be the most elegant way to handle it. Anyone have any samples on how to poll the status of more than one group during a single button click? Any pointers would be much appreciated... (I looked at the msgboxwizard example that comes with v.3.1.0 and it was a bit over my head. I'm hoping that there is a simpler framework for the type of polling I'm trying to implement). Edited February 23, 2005 by jhegener Link to comment Share on other sites More sharing options...
CyberSlug Posted February 23, 2005 Share Posted February 23, 2005 (edited) I'm afraid my script got complicated quickly, but I want to point out two things: - Look up arrays when dealing with large groups of variables - Use the return value of GuiGetMsg() instead of contantly polling the checkboxes/radios with GuiCtrlRead(). Have a variable for each group. When the user clicks a radio button in that group, store the control reference ID. Checkboxes are more complicated, and I think you might just want to loop through the status of each one when you click the Proceed button..... WITHOUT ARRAYS expandcollapse popup; Script generated by AutoBuilder 0.5 Prototype (but heavily modified) #include <GuiConstants.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 $GUI = GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) GuiCtrlCreateGroup("GroupOne", 10, 10, 150, 160) $animal_0 = GuiCtrlCreateRadio("Cats", 20, 40, 120, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $animal_1 = GuiCtrlCreateRadio("Dogs", 20, 70, 120, 20) $animal_2 = GuiCtrlCreateRadio("Fish", 20, 110, 120, 20) GuiCtrlCreateGroup("GroupTwo", 190, 20, 180, 150) $fruit_0 = GuiCtrlCreateCheckbox("Apples", 210, 40, 130, 30) GuiCtrlSetState(-1, $GUI_CHECKED) $fruit_1 = GuiCtrlCreateCheckbox("Bananas", 210, 80, 120, 20) $fruit_2 = GuiCtrlCreateCheckbox("Oranges", 210, 110, 120, 20) $fruit_3 = GuiCtrlCreateCheckbox("Grapes", 210, 140, 120, 20) GuiCtrlCreateGroup("", -99, -99, 1, 1) $button = GuiCtrlCreateButton("Submit", 50, 240, 120, 40) Dim $favoriteAnimal = $animal_0, $favoriteFruit = $fruit_0 GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $animal_0 <= $msg And $msg <= $animal_2 $favoriteAnimal = $msg Case $fruit_0 <= $msg And $msg <= $fruit_3 $favoriteFruit = $msg Case $msg = $button $animalOutput = ControlGetText($GUI,"",$favoriteAnimal) ;get the label of the radio button $fruitOutput = "" If GuiCtrlRead($fruit_0) = $GUI_CHECKED Then $fruitOutput = $fruitOutput & ControlGetText($GUI,"",$fruit_0) & ", " If GuiCtrlRead($fruit_1) = $GUI_CHECKED Then $fruitOutput = $fruitOutput & ControlGetText($GUI,"",$fruit_1) & ", " If GuiCtrlRead($fruit_2) = $GUI_CHECKED Then $fruitOutput = $fruitOutput & ControlGetText($GUI,"",$fruit_2) & ", " If GuiCtrlRead($fruit_3) = $GUI_CHECKED Then $fruitOutput = $fruitOutput & ControlGetText($GUI,"",$fruit_3) & ", " MsgBox(4096, "Favorites", "You like " & $fruitOutput & " and " & $animalOutput ) EndSelect WEnd Exit WITH ARRAYS expandcollapse popup; Script generated by AutoBuilder 0.5 Prototype (but heavily modified) #include <GuiConstants.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 $GUI = GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) Dim $animal[3], $fruit[4] Dim $favoriteAnimal = 0, $favoriteFruit = 0 ;array indices GuiCtrlCreateGroup("GroupOne", 10, 10, 150, 160) $animal[0] = GuiCtrlCreateRadio("Cats", 20, 40, 120, 20) GuiCtrlSetState(-1, $GUI_CHECKED) $animal[1] = GuiCtrlCreateRadio("Dogs", 20, 70, 120, 20) $animal[2] = GuiCtrlCreateRadio("Fish", 20, 110, 120, 20) GuiCtrlCreateGroup("GroupTwo", 190, 20, 180, 150) $fruit[0] = GuiCtrlCreateCheckbox("Apples", 210, 40, 130, 30) GuiCtrlSetState(-1, $GUI_CHECKED) $fruit[1] = GuiCtrlCreateCheckbox("Bananas", 210, 80, 120, 20) $fruit[2] = GuiCtrlCreateCheckbox("Oranges", 210, 110, 120, 20) $fruit[3] = GuiCtrlCreateCheckbox("Grapes", 210, 140, 120, 20) GuiCtrlCreateGroup("", -99, -99, 1, 1) $button = GuiCtrlCreateButton("Submit", 50, 240, 120, 40) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $animal[0] <= $msg And $msg <= $animal[2] $favoriteAnimal = $msg - $animal[0];the subtraction converts the $msg ID to array index Case $fruit[0] <= $msg And $msg <= $fruit[3] $favoriteFruit = $msg - $fruit[0] Case $msg = $button $animalOutput = ControlGetText($GUI,"",$animal[$favoriteAnimal]);get the label of the radio button $fruitOutput = "" For $i = 0 to 3 If GuiCtrlRead($fruit[$i]) = $GUI_CHECKED Then $fruitOutput = $fruitOutput & ControlGetText($GUI,"",$fruit[$i]) & ", " Next MsgBox(4096, "Favorites", "You like " & $fruitOutput & " and " & $animalOutput ) EndSelect WEnd ExitEdit: Clarity and typo fixes Edited February 23, 2005 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
jhegener Posted February 23, 2005 Author Share Posted February 23, 2005 I'm afraid my script got complicated quickly but I want to point out two things:- Look up arrays when dealing with large groups of variables- Use the return value of GuiGetMsg() instead of contantly polling the checkboxes/radios with GuiCtrlRead()Geez, you guys are fast with the replies!!!Thanks... it's getting a little late, so I'll play around with the code tomorrow but I'm sure this will point me in the right direction. Now, I just need to figure out what each line is doing. Link to comment Share on other sites More sharing options...
CyberSlug Posted February 23, 2005 Share Posted February 23, 2005 Greatly expanded above post. Hope it makes sense Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
jhegener Posted February 23, 2005 Author Share Posted February 23, 2005 I see this often in the most of the sample code... GUICtrlCreateGroup ("",-99,-99,1,1) ;close group What is the purpose of closing the group? And should you do it for each group or just once after you've created all your groups? Link to comment Share on other sites More sharing options...
CyberSlug Posted February 23, 2005 Share Posted February 23, 2005 What is the purpose of closing the group? And should you do it for each group or just once after you've created all your groups?<{POST_SNAPBACK}>I actually don't need it in my example, but you typically would use it after your last group. It's a good idea if you use radio buttons.Notice that I don't call it before GuiCtrlCreateGroup("GroupTwo", 190, 20, 180, 150) because this automatically "closes" GroupOne before creating the new one. Or something like that. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
jhegener Posted February 24, 2005 Author Share Posted February 24, 2005 I actually don't need it in my example, but you typically would use it after your last group. It's a good idea if you use radio buttons.Notice that I don't call it before GuiCtrlCreateGroup("GroupTwo", 190, 20, 180, 150) because this automatically "closes" GroupOne before creating the new one. Or something like that.<{POST_SNAPBACK}>Thanks for all your help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now