Jump to content
Sign in to follow this  
SuperFletch

Change GUI depending on checkbox state

Recommended Posts

SuperFletch

I have a basic GUI which is ready to receive some input from the end user. One of the controls (control 14) is a checkbox which by default is unticked.

The script waits for the user to do the input and press the go button using a While statement, during this time I want it to monitor the state of the checkbox and if it becomes ticked I want to grey out one of the other controls (control 11 - an input box).

I can kind of do this, but they way I've done it makes control 11 in the GUI flicker loads because I've put an If statement near the top of my While which checks whether the checkbox (control 14) has been ticked or not and applies a state to the input box (control 11) based on that.

The way I'm doing it is a bit rubbish I guess, the state of the checkbox applies an update to the control every time the While statement loops. I want it to update the input box only when a change to the value of the checkbox is applied.

Can anyone help? I tried messing around by setting a variable at the start and end of the While statement then comparing them but I couldn't get it to work.

Thanks in advance...

 

While 1

If GUICtrlRead(14) = 1 then
GUICtrlSetState(11,128)
Else
GUICtrlSetState(11,64)
EndIf

$Msg = GUIGetMsg()

Select
    Case $Msg=$CANCEL
    GUIDelete()
    Exit
    Case $Msg=$GUI_EVENT_CLOSE
    GUIDelete()
    Exit
    Case $Msg=$GO
    ExitLoop
EndSelect


WEnd

 

Share this post


Link to post
Share on other sites
kylomas

SuperFletch,

You will receive better help if you post runnable code.

kylomas

  • Like 1

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
SuperFletch

OK - thanks - here is the full code so far.

#include<GuiConstants.au3>
#include<Process.au3>

;Tool to gather MAC Addresses of SOLUS 3 Machines and attempt Wake On Lan
GUICreate("S3 Wake on Lan Tool",400,400)
GUICtrlCreateLabel("This tool will extract agent Mac Addresses listed in the S3 database and",30,30)
GUICtrlCreateLabel("broadcast an attempt to wake them.",30,44)
GUICtrlCreateLabel("Once run you will need to monitor the S3 GUI to see how well it works.",30,66)
GUICtrlCreateLabel("Only desktop machines on a wired ethernet connection are likely to",30,80)
GUICtrlCreateLabel("succeed as Wireless network connections rarely support Wake On LAN.",30,94)

GUICtrlCreateLabel("To access the S3 database enter the SQL Server and SA password below",30,150)
GUICtrlCreateLabel("or enter the SQL Server and choose the Trusted authentication option.",30,164)
GUICtrlCreateInput("localhost\sims****",100,185,150)
GUICtrlCreateInput("SAPASSWORD",100,215,150)
GUICtrlCreateLabel("SQL Server",30,190)
GUICtrlCreateLabel("SA Password",30,220)
GUICtrlCreateCheckbox("Trusted Auth'",270,215)          ;NEED TO MAKE IT SO WHEN CHECKED IT GREYS THE SA PASSWORD BOX OUT
$GO = GUICtrlCreateButton("Go",100,240,80,30)
$CANCEL = GUICtrlCreateButton("Cancel",200,240,80,30)
GUISetState(@SW_SHOWNORMAL)


While 1

If GUICtrlRead(14) = 1 then
GUICtrlSetState(11,128)
Else
GUICtrlSetState(11,64)
EndIf

$Msg = GUIGetMsg()

Select
    Case $Msg=$CANCEL
    GUIDelete()
    Exit
    Case $Msg=$GUI_EVENT_CLOSE
    GUIDelete()
    Exit
    Case $Msg=$GO
    ExitLoop
EndSelect


WEnd

$Message = GUICtrlRead(14)


;READ THE DATA FROM THE GUI
If GUICtrlRead(14) = 1 Then
    Call("TrustedAuth")
Else
    Call("SQLAuth")
EndIf


Func SQLAuth()

$ServerName=GUICtrlRead(10)
$SAPassword=GUICtrlRead(11)

;ADD THE DATA INTO A STRING TO RUN THE SQL COMMAND OUTPUT TO A TEMPORARY FILE
$TempFile=(@ScriptDir & "\tempfile.txt")
$GetMacs=('osql -S ' & $ServerName & ' -d solus3_deployment_server -U sa -P ' & $SAPassword & ' -Q "SELECT mac_address FROM solus3.agent" -o "' & $TempFile & '"')
MsgBox(0,"Code to get Mac Addresses out of S3 DB and into a tempfile","" & $GetMacs)
_RunDos($GetMacs)

EndFunc


Func TrustedAuth()

$ServerName=GUICtrlRead(10)

;ADD THE DATA INTO A STRING TO RUN THE SQL COMMAND OUTPUT TO A TEMPORARY FILE
$TempFile=(@ScriptDir & "\tempfile.txt")
$GetMacs=('osql -S ' & $ServerName & ' -d solus3_deployment_server -E -Q "SELECT mac_address FROM solus3.agent" -o "' & $TempFile & '"')
MsgBox(0,"Code to get Mac Addresses out of S3 DB and into a tempfile","" & $GetMacs)
_RunDos($GetMacs)

EndFunc

 

Share this post


Link to post
Share on other sites
ahmet

Instead of checking state of checkbox at the beginning of wile loop you could only check its state when you click on it, just how you do with Cancel or Go buttons.Is there a specific reason you have not assigned control id returned from GUICtrlCreateCheckbox() and two inputs to a variable?

Share this post


Link to post
Share on other sites
kylomas

SuperFletch,

Try this.  The checkbox control is handled in the message loop just like any other control.  Naming your controls will save you many headaches down the road.

#include<GuiConstants.au3>
#include<Process.au3>

;Tool to gather MAC Addresses of SOLUS 3 Machines and attempt Wake On Lan

GUICreate("S3 Wake on Lan Tool", 400, 400)
GUICtrlCreateLabel("This tool will extract agent Mac Addresses listed in the S3 database and", 30, 30)
GUICtrlCreateLabel("broadcast an attempt to wake them.", 30, 44)
GUICtrlCreateLabel("Once run you will need to monitor the S3 GUI to see how well it works.", 30, 66)
GUICtrlCreateLabel("Only desktop machines on a wired ethernet connection are likely to", 30, 80)
GUICtrlCreateLabel("succeed as Wireless network connections rarely support Wake On LAN.", 30, 94)

GUICtrlCreateLabel("To access the S3 database enter the SQL Server and SA password below", 30, 150)
GUICtrlCreateLabel("or enter the SQL Server and choose the Trusted authentication option.", 30, 164)
Local $cHost = GUICtrlCreateInput("localhost\sims****", 100, 185, 150)
Local $cPSWD = GUICtrlCreateInput("SAPASSWORD", 100, 215, 150)
GUICtrlCreateLabel("SQL Server", 30, 190)
GUICtrlCreateLabel("SA Password", 30, 220)
Local $cCHK = GUICtrlCreateCheckbox("Trusted Auth'", 270, 215) ;NEED TO MAKE IT SO WHEN CHECKED IT GREYS THE SA PASSWORD BOX OUT
$GO = GUICtrlCreateButton("Go", 100, 240, 80, 30)
$CANCEL = GUICtrlCreateButton("Cancel", 200, 240, 80, 30)
GUISetState(@SW_SHOWNORMAL)


While 1

    $Msg = GUIGetMsg()

    Select
        Case $Msg = $CANCEL
            GUIDelete()
            Exit
        Case $Msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case $Msg = $cCHK

            If BitAND(GUICtrlRead($cCHK), $GUI_CHECKED) = $GUI_CHECKED  Then
                GUICtrlSetState($cPSWD, 128)
            Else
                GUICtrlSetState($cPSWD, 64)
            EndIf

        Case $Msg = $GO
            ExitLoop

    EndSelect





WEnd



$Message = GUICtrlRead($cCHK)


;READ THE DATA FROM THE GUI
If GUICtrlRead($cCHK) = 1 Then
    Call("TrustedAuth")
Else
    Call("SQLAuth")
EndIf





Func SQLAuth()

    $ServerName = GUICtrlRead($cHost)
    $SAPassword = GUICtrlRead($cPSWD)

    ;ADD THE DATA INTO A STRING TO RUN THE SQL COMMAND OUTPUT TO A TEMPORARY FILE
    $TempFile = (@ScriptDir & "\tempfile.txt")
    $GetMacs = ('osql -S ' & $ServerName & ' -d solus3_deployment_server -U sa -P ' & $SAPassword & ' -Q "SELECT mac_address FROM solus3.agent" -o "' & $TempFile & '"')
    MsgBox(0, "Code to get Mac Addresses out of S3 DB and into a tempfile", "" & $GetMacs)
    _RunDos($GetMacs)

EndFunc   ;==>SQLAuth





Func TrustedAuth()

    $ServerName = GUICtrlRead($cHost)

    ;ADD THE DATA INTO A STRING TO RUN THE SQL COMMAND OUTPUT TO A TEMPORARY FILE
    $TempFile = (@ScriptDir & "\tempfile.txt")
    $GetMacs = ('osql -S ' & $ServerName & ' -d solus3_deployment_server -E -Q "SELECT mac_address FROM solus3.agent" -o "' & $TempFile & '"')
    MsgBox(0, "Code to get Mac Addresses out of S3 DB and into a tempfile", "" & $GetMacs)
    _RunDos($GetMacs)

EndFunc   ;==>TrustedAuth

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
SuperFletch

Thanks everyone,

Pretty sure I can crack this now - I'll deffo remember to name my controls in future.

Cheers.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.