Chris_1013 Posted December 1, 2004 Share Posted December 1, 2004 I've written a GUI script that as part of another program displays the GUI with a countdown that if the user doesn't respond it will disconnect their network connection. If they do respond it will either do this (if they click connect), or hide it for the wait time again. The problem I'm having is that when the GUI is shown for a second time the buttons do not work. Can someone see if they can see what is going on? Execute the script, wait ten seconds it'll pop a GUI. If you press disconnect it'll give an error (cos the external program isn't there). This doesn't matter, but at least it's doing something. If you press Stay Connected it'll go away and pop back in another 5 seconds. Try the buttons, nothing works!Timer.au3 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 1, 2004 Developers Share Posted December 1, 2004 (edited) Your script got caught in the While 1 .. Wend loop after pressing the button. changed it around a bit but think that it works in this way: expandcollapse popup#include <GuiConstants.au3> #include <Date.au3> ;amount of time connection is allowed to be up before warning to disconnect (in minutes) Dim $disconnectwarn = 1 Dim $livetime = $disconnectwarn Global $disconTOHour = 0 Global $disconTOmin = 0 Global $disconTOsec = 0 ; Main() ; Func Main() $connect = TimerInit() While 1 Sleep(1000) ;If TimerDiff($connect) >= ($disconnectwarn * 60000) Then If TimerDiff($connect) >= ($disconnectwarn * 3000) Then ShowGUI() $connect = TimerInit() EndIf Wend EndFunc ;==>Main ; Func ShowGUI() ;amount of time user has to cancel disconnection (in seconds) Global $disconTO = 50 Opt ("GUIOnEventMode", 0) GUICreate("Network connection", 335, 180, (@DesktopWidth - 335) / 2, (@DesktopHeight - 180) / 2) GUICtrlCreateIcon("SHELL32.dll", 15, 10, 10, 50, 50) If $livetime > 59 Then $livehour = $livetime / 60 $livemin = Mod($livetime, 60) EndIf $msgtext = "Your connection has been enabled for " If IsDeclared("livehour") Then $msgtext = $msgtext & $livehour & "hour" If $livehour > 1 Then $msgtext = $msgtext & "s" $msgtext = $msgtext & " and " & $livemin Else $msgtext = $msgtext & $livetime EndIf $msgtext = $msgtext & " minute(s). " $MsgLabel = GUICtrlCreateLabel($msgtext & "Do you still wish to use it? If you ignore this message the connection will automatically disconnect.", 80, 10, 240, 60) _TicksToTime($disconTO * 1000,$disconTOHour, $disconTOmin, $disconTOsec) $Time = StringFormat("%02i:%02i", $disconTOmin, $disconTOsec) $TimeLabel = GUICtrlCreateLabel("Time to disconnection:" & @TAB & $Time, 70, 90, 250, 20) $DisconnectButton = GUICtrlCreateButton("&Disconnect", 40, 130, 110, 30) $StayConnectedButton = GUICtrlCreateButton("Stay &Connected", 190, 130, 110, 30) GUISetState() AdlibEnable("DisconnectCountdown", 1000) While 1 $msg = GUIGetMsg() ; disconnect If $msg = $DisconnectButton Then Disconnect() ; stay connected If $msg = $StayConnectedButton Then AdlibDisable() GUIDelete() $livetime = $livetime + $disconnectwarn Return EndIf Sleep(10) Wend EndFunc ;==>ShowGUI ; Func Disconnect() GUIDelete() Run(@ScriptDir & "\NetCon.exe Disable") Exit EndFunc ;==>Disconnect ; Func DisconnectCountdown() $disconTO = $disconTO - 1 _TicksToTime($disconTO * 1000, $disconTOHour, $disconTOmin, $disconTOsec) $Time = StringFormat("%02i:%02i", $disconTOmin, $disconTOsec) ControlSetText("Network connection", "", "Static3", "Time to disconnection:" & @TAB & $Time) If $disconTO <= 0 Then Disconnect() EndFunc ;==>DisconnectCountdown #cs If MsgBox(4148,"Network connection","Your network connection has been in use for over " & $livetime & " minutes." & @LF & "Do you want to keep using it?") = 7 Then Run(@ScriptDir & "\NetCon.exe Disable") Exit Else $livetime=$livetime+$disconnectwarn $connect=TimerInit() EndIf #ce Edited December 1, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Chris_1013 Posted December 1, 2004 Author Share Posted December 1, 2004 (edited) Thanks, looks good. I generally like to use Opt("GUIOnEventMode", 1), because it seems easier to code for me, but I suppose this isn't the best thing to do in all scenarios. This works as I intended though, thanks. One other thing, what's the point of the line Global $switch = 0 as I can't see $switch being referenced anywhere else. Edited December 1, 2004 by Chris_1013 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 1, 2004 Developers Share Posted December 1, 2004 One other thing, what's the point of the lineGlobal $switch = 0as I can't see $switch being referenced anywhere else.<{POST_SNAPBACK}>None... my first thought was to leave the functions as is and set a Gobal var when the stay connected is clicked. Then test in the While 1 ... wend loop for this var.But changed my mind... so just remove it... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Chris_1013 Posted December 1, 2004 Author Share Posted December 1, 2004 Coolcool, already have done. It works quite beautifully actually. I could probably chuck this back into my original script but I kinda like the ease of seperating it. Do you have any comments on a better way to do my ugly splitting time to Hours/Mins bit in there? I remember you posting a lil script that was a modification to something I did where you had a timer counting up. Is there a cleaner was to do a count-down timer? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 1, 2004 Developers Share Posted December 1, 2004 Coolcool, already have done. It works quite beautifully actually. I could probably chuck this back into my original script but I kinda like the ease of seperating it. Do you have any comments on a better way to do my ugly splitting time to Hours/Mins bit in there? I remember you posting a lil script that was a modification to something I did where you had a timer counting up. Is there a cleaner was to do a count-down timer?<{POST_SNAPBACK}>I guess i would use _TicksToTime ... see previous posted updated script SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Chris_1013 Posted December 2, 2004 Author Share Posted December 2, 2004 Thanks, looks a bit neater, I was thinking of that function. 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