robinsiebler Posted June 20, 2008 Posted June 20, 2008 (edited) I'm making my 1st attempt at creating a GUI using AutoIT. I have a few command line tools and the GUI is just a front for these tools.I am having a problem with a checkbox. When the 1st radio button is selected (default), a checkbox is visible. I am using a label to display the command line that will be executed when the 'Execute' button is clicked. I'm at a loss as to the best way to update the label. If the checkbox is checked, the command line should contain ' -a ' (either inserted after '.exe ' or at the end of the line). If it is not checked, ' -a ' should not be there.I figured out the checkbox part....Case $nMsg = $chkAppend If _IsChecked($chkAppend) Then GUICtrlSetData($lblCmd, $msg_cmd_imagelist & "-a " & $args) Else GUICtrlSetData($lblCmd, $msg_cmd_imagelist & $args) EndIf Func _IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFuncAlso, if you notice anything else I could improve upon, please let me know.expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=C:\scripts\autoit3\ToolsGUI\ToolsGUI.kxf $frmTool = GUICreate("Tools GUI", 633, 448, 194, 126) $grpTools = GUICtrlCreateGroup("Tools", 24, 32, 225, 129) $radio_1 = GUICtrlCreateRadio("Create ImageList (Picture Viewer)", 40, 48, 185, 17) $radio_2 = GUICtrlCreateRadio("Get IPs", 40, 69, 89, 17) $radio_3 = GUICtrlCreateRadio("Route Print", 40, 93, 89, 17) $radio_4 = GUICtrlCreateRadio("Reboot Servers", 40, 117, 105, 17) $radio_5 = GUICtrlCreateRadio("SQL Query", 40, 139, 89, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $lblTools = GUICtrlCreateLabel("Select the tool you wish to use", 24, 8, 148, 17) $txtInstructions = GUICtrlCreateEdit("", 256, 8, 369, 185, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlSetData($txtInstructions, "") GUICtrlSetState($txtInstructions, $GUI_DISABLE) $lblCmdText = GUICtrlCreateLabel("Command to be used:", 24, 304, 126, 17) GUICtrlSetFont($lblCmdText, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor($lblCmdText, 0x0054E3) $lblCmd = GUICtrlCreateLabel("", 24, 328, 400, 40) $btnBrowse = GUICtrlCreateButton("Browse", 24, 212, 49, 25) $lblBrowse = GUICtrlCreateLabel("", 80, 216, 201, 17) $btnExecute = GUICtrlCreateButton("Execute", 304, 212, 65, 25) GUICtrlSetState($btnExecute, $GUI_DISABLE) $inpFile = GUICtrlCreateInput("", 24, 272, 169, 21) GUICtrlSetState($inpFile, $GUI_HIDE) $lblInput = GUICtrlCreateLabel("Name for output file", 24, 248, 200, 17) GUICtrlSetState($lblInput, $GUI_HIDE) $chkAppend = GUICtrlCreateCheckbox("Append to exising file", 30, 184, 145, 17) GUICtrlSetState($chkAppend, $GUI_HIDE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;~ VARIABLES ;~ ----------------------------- ;~ variables for radio buttons $radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button $radioval2 = 4 $current_radio = -1 ;~ help messages $msg_imagelist = "This script will create a list of all of the JPG files in a given dir and then\r\ncreate an AVS file containing an array using those file names.\r\n\r\nUsage:\r\n\r\n create_imageList [path]\r\n\r\n path = directory containing the project\r\n (images are expected to be in /images)\r\n\r\nExample:\r\n\r\n create_imageList c:\\AVE\\Sample_Project" $msg_ips = "This script will get all of the IPs for the machines listed in the serverlist,\r\nsave the IPs in outputfile and open outputfile in notepad.\r\n\r\nUsage:\r\n\r\n get_all_ips [serverlist] [outputfile]\r\n\r\n serverlist = text file containing server name/IP, 1 per line\r\n outputfile = text file in which to write the IPs\r\n\r\nExample:\r\n\r\n get_all_ips d:\\temp\\serverlist.txt d:\\temp\\ips.txt" $msg_routeprint = "This script will run 'route print' for the machines listed in the serverlist.\r\n\r\nUsage:\r\n\r\n route_print [serverlist]\r\n\r\n serverlist = text file containing server name/IP, 1 per line\r\n\r\nExample:\r\n\r\n route_print d:\\temp\\serverlist.txt" $msg_reboot = "This script will reboot all of the machines listed in the serverlist.\r\n\r\nUsage:\r\n\r\n reboot_servers [serverlist]\r\n\r\n serverlist = text file containing server name/IP, 1 per line\r\n\r\nExample:\r\n\r\n reboot_servers d:\\temp\\serverlist.txt" $msg_sql = "This script will run an SQL query (using the input file), clean up the\r\noutput, and print it to the screen.\r\n\r\nUsage:\r\n\r\n sql_query.exe [inputfile]\r\n\r\n inputfile = text file containing the SQL query\r\n Note: Example queries can be found in \r\n ftp://10.200.100.19/Robin/test_tools/SQL_queries" ;~ tool command $msg_cmd_imagelist = "create_imageList.exe " $msg_cmd_ips = "get_ips.exe " $msg_cmd_routeprint = "get_route_print.exe " $msg_cmd_reboot = "reboot_servers.exe " $msg_cmd_sql = "sql_query.exe " ;~ misc controls $msg_lblbrowse = "Click to browse for " ControlClick($frmTool, "", $radio_1) While 1 $nMsg = GUIGetMsg() If $radioval1 <> 0 Then GUICtrlSetState($chkAppend, $GUI_HIDE) EndIf If $radioval1 <> 1 Then GUICtrlSetState($lblInput, $GUI_HIDE) GUICtrlSetState($inpFile, $GUI_HIDE) GUICtrlSetData($inpFile, "") EndIf Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg >= $radio_1 And $nMsg <= $radio_5 $radioval1 = $nMsg - $radio_1 Select Case $radioval1 = 0 disableExecute() GUICtrlSetData($txtInstructions, StringFormat($msg_imagelist)) GUICtrlSetState($chkAppend, $GUI_SHOW) GUICtrlSetData($lblCmd, $msg_cmd_imagelist & "[path]") GUICtrlSetData($lblBrowse, $msg_lblbrowse & "project path") Case $radioval1 = 1 disableExecute() GUICtrlSetData($txtInstructions, StringFormat($msg_ips)) GUICtrlSetData($lblCmd, $msg_cmd_ips & "[serverlist] [outputfile]") GUICtrlSetData($lblBrowse, $msg_lblbrowse & "server list") Case $radioval1 = 2 disableExecute() GUICtrlSetData($txtInstructions, StringFormat($msg_routeprint)) GUICtrlSetData($lblCmd, $msg_cmd_routeprint) Case $radioval1 = 3 disableExecute() GUICtrlSetData($txtInstructions, StringFormat($msg_reboot)) GUICtrlSetData($lblCmd, $msg_cmd_reboot) Case $radioval1 = 4 disableExecute() GUICtrlSetData($txtInstructions, StringFormat($msg_sql)) GUICtrlSetData($lblCmd, $msg_cmd_sql) EndSelect Case $nMsg = $btnBrowse Select Case $radioval1 = 0 $folder = FileSelectFolder("Browse for project path", "d:\", "2") if StringInStr($folder, " ") Then $folder = '"' & $folder & '"' $args = $msg_cmd_imagelist & $folder GUICtrlSetData($lblCmd, $args) GUICtrlSetState($btnExecute, $GUI_ENABLE) Case $radioval1 = 1 $file = FileOpenDialog("Browse for server list", "d:\", "All (*.*)|Text files (*.txt)") if StringInStr($file, " ") Then $file = '"' & $file & '"' GUICtrlSetData($lblCmd, $msg_cmd_ips & $file & " [outputfile]") GUICtrlSetState($lblInput, $GUI_SHOW) GUICtrlSetState($inpFile, $GUI_SHOW) ControlFocus($frmTool, "", $inpFile) EndSelect Case $nMsg = $btnExecute Run(@ComSpec & " /k echo " & $args & Chr(38) & $args) GUICtrlSetState($btnExecute, $GUI_DISABLE) Case $nMsg = $inpFile Select Case $radioval1 = 1 $out_file = GUICtrlRead($inpFile) if StringInStr($out_file, " ") Then $out_file = '"' & $out_file & '"' $args = $msg_cmd_ips & $file & " " & $out_file GUICtrlSetData($lblCmd, $msg_cmd_ips & $args) GUICtrlSetState($btnExecute, $GUI_ENABLE) EndSelect EndSelect WEnd Func disableExecute() if $current_radio <> $radioval1 Then GUICtrlSetState($btnExecute, $GUI_DISABLE) $current_radio = $radioval1 EndIf EndFuncYou can download the file directly from http://members.dslextreme.com/users/robins...es/ToolsGUI.au3 Edited June 20, 2008 by robinsiebler
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