Pretend2Script Posted June 18, 2008 Share Posted June 18, 2008 Normally I'm able to dig through tons of post and my slow brain will eventually glean, from everyone's brilliance, the information I need, but I've spent all afternoon in the "Forum" trenches and the Help File and I'm still at a loss. I have an old Backup/Restore Script I created using AutoIt back in the day and I'm trying to re-write/improve it with all that I've learned from trudging in everyone's footsteps around here. I've got the actual functionality covered, but the GUI is killing me. I've created a checkbox and some radio buttons and I'm trying to disable and enable input options (dropdowns, input, file select, etc...) based on if they are selected or not. In my select case, only the top most listed choice will work. Should I be using onevent instead? What obvious mistake am I making here? (here's most of the GUI minus unnecessary extras) CODE#include <file.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <array.au3> $Main = GUICreate("Welcome to the Backup program!", 500, 500) $group_1 = GUICtrlCreateGroup("Set Backup Locations", 20, 10, 200, 100) GUIStartGroup() $location_1 = GUICtrlCreateCheckbox("Default selections", 30, 30, 182, 20) GUICtrlSetState($location_1, $GUI_CHECKED + $GUI_DISABLE) $location_2 = GUICtrlCreateCheckbox("Add Locations...", 30, 50, 160, 20) $AddFile = GUICtrlCreateButton("Add File", 30, 75, 45, 20) $AddFolder = GUICtrlCreateButton("Add Folder", 80, 75, 60, 20) GUICtrlSetState($AddFile, $GUI_DISABLE) GUICtrlSetState($AddFolder, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group $group_2 = GUICtrlCreateGroup("Set Backup Media", 20, 120, 200, 220) GUIStartGroup() $chkFixed = GUICtrlCreateRadio("Backup to Hard Drive", 30, 140, 180, 20) $fixed = GUICtrlCreateCombo("Hard Drive", 30, 160, 180, 20) GUICtrlSetState($fixed, $GUI_DISABLE) $chkCDRom = GUICtrlCreateRadio("Backup to CD Burner", 30, 185, 180, 20) $CDRom = GUICtrlCreateCombo("CD-Rom Drive", 30, 205, 180, 20) GUICtrlSetState($CDRom, $GUI_DISABLE) $chkRemovable = GUICtrlCreateRadio("Backup to Removable Drive", 30, 230, 180, 20) $Removeable = GUICtrlCreateCombo("Removeable Drive", 30, 250, 180, 20) GUICtrlSetState($Removeable, $GUI_DISABLE) $chkNetwork = GUICtrlCreateRadio("Backup to Network Location", 30, 275, 180, 20) $Network = GUICtrlCreateCombo("Network Drive", 30, 295, 180, 20) GUICtrlSetState($Network, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group $group_4 = GUICtrlCreateGroup("Backup List", 230, 10, 260, 470) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;X in corner is clicked ;_FileWriteLog($LogFile, "Closed application - X in corner") ;FileClose($LogMe) Exit Case $msg = $AddFile $inputBrowse = FileOpenDialog("Select a file...", "", "All (*.*)", 3) $YNadd = MsgBox(36, "Verify File", "Are you sure you want to add:"&@CR&@CR&$inputBrowse) If $YNadd = 6 Then MsgBox(64, "File Added...", $inputBrowse&@CR&@CR&"...has been added to your backup.") ;_FileWriteLog($LogFile, "Added file =" & $inputBrowse) Else MsgBox(48, "No Addition", $inputBrowse&@CR&@CR&"...was NOT added to the backup.") EndIf Case $msg = $AddFolder $inputBrowse = FileSelectFolder("Select a folder...", "") $YNadd = MsgBox(36, "Verify Folder", "Are you sure you want to add:"&@CR&@CR&$inputBrowse) If $YNadd = 6 Then MsgBox(64, "Folder Added...", $inputBrowse&@CR&@CR&"...has been added to your backup.") ;_FileWriteLog($LogFile, "Added folder =" & $inputBrowse) Else MsgBox(48, "No Addition", $inputBrowse&@CR&@CR&"...was NOT added to the backup.") EndIf Case BitAND(GUICtrlRead($location_2), $GUI_CHECKED) If Not BitAND(GUICtrlGetState($AddFile), $GUI_ENABLE) Then GUICtrlSetState($AddFile, $GUI_ENABLE) If Not BitAND(GUICtrlGetState($AddFolder), $GUI_ENABLE) Then GUICtrlSetState($AddFolder, $GUI_ENABLE) Case BitAND(GUICtrlRead($location_2), $GUI_UNCHECKED) If Not BitAND(GUICtrlGetState($AddFile), $GUI_DISABLE) Then GUICtrlSetState($AddFile, $GUI_DISABLE) If Not BitAND(GUICtrlGetState($AddFolder), $GUI_DISABLE) Then GUICtrlSetState($AddFolder, $GUI_DISABLE) Case BitAND(GUICtrlRead($chkFixed), $GUI_CHECKED) If Not BitAND(GUICtrlGetState($fixed), $GUI_ENABLE) Then GUICtrlSetState($fixed, $GUI_ENABLE) Case BitAND(GUICtrlRead($chkFixed), $GUI_UNCHECKED) If Not BitAND(GUICtrlGetState($fixed), $GUI_DISABLE) Then GUICtrlSetState($fixed, $GUI_DISABLE) EndSelect WEnd ...preparing to bow to the forthcoming enlightenment! (any of which I am truly grateful for) The difference between Genius and Stupidity is that Genius has its limits....Einstein Link to comment Share on other sites More sharing options...
monoceres Posted June 18, 2008 Share Posted June 18, 2008 (edited) Hi!Add this to your select statement in your message loop Case $msg = $chkNetwork GUICtrlSetState($Network, $GUI_ENABLE) GUICtrlSetState($CDRom, $GUI_DISABLE) GUICtrlSetState($Removeable, $GUI_DISABLE) GUICtrlSetState($fixed, $GUI_DISABLE) Case $msg = $chkCDRom GUICtrlSetState($Network, $GUI_DISABLE) GUICtrlSetState($CDRom, $GUI_ENABLE) GUICtrlSetState($Removeable, $GUI_DISABLE) GUICtrlSetState($fixed, $GUI_DISABLE) Case $msg = $chkFixed GUICtrlSetState($Network, $GUI_DISABLE) GUICtrlSetState($CDRom, $GUI_DISABLE) GUICtrlSetState($Removeable, $GUI_DISABLE) GUICtrlSetState($fixed, $GUI_ENABLE) Case $msg = $chkRemovable GUICtrlSetState($Network, $GUI_DISABLE) GUICtrlSetState($CDRom, $GUI_DISABLE) GUICtrlSetState($Removeable, $GUI_ENABLE) GUICtrlSetState($fixed, $GUI_DISABLE)Quick 'n dirty Edit: Also consider downloading SciTe4AutoIt it includes a tool called TiDy that can format your code into a more readable state Edited June 18, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Valuater Posted June 18, 2008 Share Posted June 18, 2008 Maybe... expandcollapse popup#include <file.au3> #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <array.au3> Dim $Radio[5], $Combo[5] $Main = GUICreate("Welcome to the Backup program!", 500, 500) $group_1 = GUICtrlCreateGroup("Set Backup Locations", 20, 10, 200, 100) GUIStartGroup() $location_1 = GUICtrlCreateCheckbox("Default selections", 30, 30, 182, 20) GUICtrlSetState($location_1, $GUI_CHECKED + $GUI_DISABLE) $location_2 = GUICtrlCreateCheckbox("Add Locations...", 30, 50, 160, 20) $AddFile = GUICtrlCreateButton("Add File", 30, 75, 45, 20) $AddFolder = GUICtrlCreateButton("Add Folder", 80, 75, 60, 20) GUICtrlSetState($AddFile, $GUI_DISABLE) GUICtrlSetState($AddFolder, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group $group_2 = GUICtrlCreateGroup("Set Backup Media", 20, 120, 200, 220) GUIStartGroup() $Radio[1] = GUICtrlCreateRadio("Backup to Hard Drive", 30, 140, 180, 20) $Combo[1] = GUICtrlCreateCombo("Hard Drive", 30, 160, 180, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Radio[2] = GUICtrlCreateRadio("Backup to CD Burner", 30, 185, 180, 20) $Combo[2] = GUICtrlCreateCombo("CD-Rom Drive", 30, 205, 180, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Radio[3] = GUICtrlCreateRadio("Backup to Removable Drive", 30, 230, 180, 20) $Combo[3] = GUICtrlCreateCombo("Removeable Drive", 30, 250, 180, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Radio[4] = GUICtrlCreateRadio("Backup to Network Location", 30, 275, 180, 20) $Combo[4] = GUICtrlCreateCombo("Network Drive", 30, 295, 180, 20) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group $group_4 = GUICtrlCreateGroup("Backup List", 230, 10, 260, 470) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;X in corner is clicked ;_FileWriteLog($LogFile, "Closed application - X in corner") ;FileClose($LogMe) Exit Case $msg = $AddFile $inputBrowse = FileOpenDialog("Select a file...", "", "All (*.*)", 3) $YNadd = MsgBox(36, "Verify File", "Are you sure you want to add:" & @CR & @CR & $inputBrowse) If $YNadd = 6 Then MsgBox(64, "File Added...", $inputBrowse & @CR & @CR & "...has been added to your backup.") ;_FileWriteLog($LogFile, "Added file =" & $inputBrowse) Else MsgBox(48, "No Addition", $inputBrowse & @CR & @CR & "...was NOT added to the backup.") EndIf Case $msg = $AddFolder $inputBrowse = FileSelectFolder("Select a folder...", "") $YNadd = MsgBox(36, "Verify Folder", "Are you sure you want to add:" & @CR & @CR & $inputBrowse) If $YNadd = 6 Then MsgBox(64, "Folder Added...", $inputBrowse & @CR & @CR & "...has been added to your backup.") ;_FileWriteLog($LogFile, "Added folder =" & $inputBrowse) Else MsgBox(48, "No Addition", $inputBrowse & @CR & @CR & "...was NOT added to the backup.") EndIf Case $msg = $location_2 If _IsChecked($location_2) Then GUICtrlSetState($AddFile, $GUI_ENABLE) GUICtrlSetState($AddFolder, $GUI_ENABLE) Else GUICtrlSetState($AddFile, $GUI_DISABLE) GUICtrlSetState($AddFolder, $GUI_DISABLE) EndIf EndSelect For $x = 1 To UBound($Radio) - 1 If $msg = $Radio[$x] Then ReSet($x) Next WEnd Func _IsChecked($control) Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func ReSet($num) For $x = 1 To UBound($Radio) - 1 GUICtrlSetState($Radio[$x], $GUI_UNCHECKED) GUICtrlSetState($Combo[$x], $GUI_DISABLE) Next GUICtrlSetState($Radio[$num], $GUI_CHECKED) GUICtrlSetState($Combo[$num], $GUI_ENABLE) EndFunc ;==>ReSet 8) Link to comment Share on other sites More sharing options...
Pretend2Script Posted June 18, 2008 Author Share Posted June 18, 2008 (edited) Duh! Thank you both! Both of these options worked perfectly and I feel like a total idiot for not seeing it myself... Apologies for the bad formatting, I do use (and love) SciTe. I think I just lost my formatting when I was trying some edits... Bravo to you both! Edited June 18, 2008 by Pretend2Script The difference between Genius and Stupidity is that Genius has its limits....Einstein 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