Bilson Posted October 25, 2010 Posted October 25, 2010 Hey Guys, I'm new to AutoIT and I'm not much of a programmer, I'm trying to automate an install for software we have that has ~7 pieces to it. I'd like to have a menu pop up where you can select the parts you'd like to install, hit a button and have it start installing the pieces. But for now I'm just trying to take babysteps and get a firm undertanding of the language before I start installing software and what not, so I'm trying to make a little program to play 3 selectable tones. right now I have a GUI i put together with KODA and have 3 different check boxes labeled "High Tone" Mid Tone" and "Low Tone" and 2 more check boxes lableled select all and deselect all (this really could be a button instead) below that I 2 buttons "Play" and "close" I know this is probably a pretty basic question, but I'm stuck, I'll post my code below, but what i would like to be able to make this do is let me select any combo of boxes, and when I press Play, play the selected sounds for 1 second (all together) and when I press the close button, I would like the program to close. so basically my questions are: How do I assign actions to buttons (i.e. make select/deselect All, Play, close)? What is the best way to have my program read the values of my 3 tone values and have it play when instructed? Thank you for any and all help guys, please do not be afraid to over simplify things, I won't be offended! and Hopefully this will be of help to others as well/ Chris #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Program Selections", 446, 300, 192, 114) $Label1 = GUICtrlCreateLabel("Please Select Desired Tones", 40, 64, 208, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Program = GUICtrlCreateLabel("Tone Selections", 16, 8, 232, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") $HighTone = GUICtrlCreateCheckbox("High Tone", 60, 100, 280, 20) $MidTone = GUICtrlCreateCheckbox("Mid Tone", 60, 120, 280, 20) $LowTone = GUICtrlCreateCheckbox("Low Tone", 60, 140, 280, 20) $SelectAll = GUICtrlCreateCheckbox("Select All", 60, 180, 80, 20) $DeselectAll = GUICtrlCreateCheckbox("DeSelect All", 180, 180, 80, 20) $Play = GUICtrlCreateButton("Play", 60, 220, 100, 40, $WS_GROUP) $Close = GUICtrlCreateButton("Close", 220, 220, 100, 40, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
PsaltyDS Posted October 25, 2010 Posted October 25, 2010 There are geekier ways to do it, but this keeps it simple: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Program Selections", 446, 300, 192, 114) $Label1 = GUICtrlCreateLabel("Please Select Desired Tones", 40, 64, 208, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Program = GUICtrlCreateLabel("Tone Selections", 16, 8, 232, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") $HighTone = GUICtrlCreateCheckbox("High Tone", 60, 100, 280, 20) $MidTone = GUICtrlCreateCheckbox("Mid Tone", 60, 120, 280, 20) $LowTone = GUICtrlCreateCheckbox("Low Tone", 60, 140, 280, 20) $SelectAll = GUICtrlCreateButton("Select All", 60, 180, 80, 20) $DeselectAll = GUICtrlCreateButton("DeSelect All", 180, 180, 80, 20) $Play = GUICtrlCreateButton("Play", 60, 220, 100, 40, $WS_GROUP) $Close = GUICtrlCreateButton("Close", 220, 220, 100, 40, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $SelectAll ControlCommand($Form1, "", $HighTone, "Check") ControlCommand($Form1, "", $MidTone, "Check") ControlCommand($Form1, "", $LowTone, "Check") Case $DeselectAll ControlCommand($Form1, "", $HighTone, "UnCheck") ControlCommand($Form1, "", $MidTone, "UnCheck") ControlCommand($Form1, "", $LowTone, "UnCheck") Case $Play $sText = "Selected: " If ControlCommand($Form1, "", $HighTone, "IsChecked") Then $sText &= "High " If ControlCommand($Form1, "", $MidTone, "IsChecked") Then $sText &= "Mid " If ControlCommand($Form1, "", $LowTone, "IsChecked") Then $sText &= "Low " MsgBox(64, "Result", $sText) Case $Close Exit EndSwitch WEnd The basics are that clicking on things like checkboxes and buttons generates a Gui Message, which will be seen by GuiGetMsg() just as $GUI_EVENT_CLOSE was. You just need more cases to handle the other possibilities. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Bilson Posted October 26, 2010 Author Posted October 26, 2010 (edited) Thank you very much PSaltyDS! I would have said this sooner, but I had some questions that I wanted to figure out, to minimize Unnecessary bumping of the thread I did add this to it (I also changed the output from a message box to different Tones, and then Programs) If (ControlCommand($Form1, "", $HighTone, "IsChecked")=0 And ControlCommand($Form1,"",$MidTone, "IsChecked") =0 And ControlCommand($Form1,"",$LowTone, "IsChecked") =0 ) Then MsgBox(0,"No Selections", "You have not made any selections") and that was a struggle, but after i figured out that the =0 would be a now and i needed to wrap my 3 options in parenthesis it came together like magic! Here's my final code, Instead of Tones, I made it open Notepad, Paint, and/or RDP (which I mistakenly labled $Telnet) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Program Selections", 446, 300, 192, 114) $Label1 = GUICtrlCreateLabel("Please Select Desired Programs", 40, 64, 208, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Program = GUICtrlCreateLabel("Tone Selections", 16, 8, 232, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") $notepad = GUICtrlCreateCheckbox("Notepad", 60, 100, 280, 20) $paint = GUICtrlCreateCheckbox("Paint", 60, 120, 280, 20) $telnet = GUICtrlCreateCheckbox("Telnet", 60, 140, 280, 20) $SelectAll = GUICtrlCreateButton("Select All", 60, 180, 80, 20) $DeselectAll = GUICtrlCreateButton("DeSelect All", 180, 180, 80, 20) $Play = GUICtrlCreateButton("Play", 60, 220, 100, 40, $WS_GROUP) $Close = GUICtrlCreateButton("Close", 220, 220, 100, 40, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $SelectAll ControlCommand($Form1, "", $notepad, "Check") ControlCommand($Form1, "", $paint, "Check") ControlCommand($Form1, "", $telnet, "Check") Case $DeselectAll ControlCommand($Form1, "", $notepad, "UnCheck") ControlCommand($Form1, "", $paint, "UnCheck") ControlCommand($Form1, "", $telnet, "UnCheck") Case $Play If ControlCommand($Form1, "", $notepad, "IsChecked") Then Run ("Notepad.exe") If ControlCommand($Form1, "", $paint, "IsChecked") Then Run("mspaint.exe") If ControlCommand($Form1,"",$telnet, "IsChecked") Then Run("mstsc.exe") If (ControlCommand($Form1, "", $notepad, "IsChecked")=0 And ControlCommand($Form1,"",$paint, "IsChecked") =0 And ControlCommand($Form1,"",$telnet, "IsChecked") =0 ) Then MsgBox(0,"No Selections", "You have not made any selections") Case $Close Exit EndSwitch WEnd Edited October 26, 2010 by Bilson
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