Sign in to follow this  
Followers 0
gregnottage

GUI Button Press Timeout

5 posts in this topic

Hi,

I'm trying to write a script that displays a box with two buttons. Depending on which of the buttons is pressed, I want different actions to be taken. What I'm also trying to do is have a default action taken after a period of time (25 seconds) has elapsed.

Here is what I have so far:

----------------------------------------------------------------

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf
$Form1 = GUICreate("ITS Applications", 211, 203, 333, 219)
$Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0)
$Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0)
$Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Do you want to start the Weekly  or Daily Applications?  This will affect Infopath and whether it opens a previously worked on file or starts a new report.  The script will timeout in 25 seconds and default to the Weekly Application startup.  Thanks and have a nice day;-)", 16, 24, 176, 108)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$msg = ""

While 1
$szName = GUIGetMsg()

Switch @error
Case 2
    $msg = "Timeout "
    ContinueCase
Case 1; Continuing previous case
    $msg &= "Cancellation"
Case 0
    Switch $szName
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            msgbox(0, "Weekly Restart", "Weekly Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe")
            Exit
        Case $Button2
            msgbox(0, "Daily Restart", "Daily Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe")
            Exit
    Case Else
        $msg = "Others"
    EndSwitch
Case Else
    $msg = "Something went horribly wrong."
EndSwitch
WEnd

Msgbox(0, "Timeout Reached", "Timeout Reached")
    ;   run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe")

----------------------------------------------------------------

It displays the box fine and all the buttons work, but I can't get my head around the timeout and then the default action.

Please can you help me work this out.

Many Thanks,

Greg.

Share this post


Link to post
Share on other sites



AdLibEnable("_Timeout", 25000)
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf
$Form1 = GUICreate("ITS Applications", 211, 203, 333, 219)
$Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0)
$Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0)
$Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Do you want to start the Weekly  or Daily Applications?  This will affect Infopath and whether it opens a previously worked on file or starts a new report.  The script will timeout in 25 seconds and default to the Weekly Application startup.  Thanks and have a nice day;-)", 16, 24, 176, 108)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$msg = ""

While 1
$szName = GUIGetMsg()

Switch @error
Case 2
    $msg = "Timeout "
    ContinueCase
Case 1; Continuing previous case
    $msg &= "Cancellation"
Case 0
    Switch $szName
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            msgbox(0, "Weekly Restart", "Weekly Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe")
            Exit
        Case $Button2
            msgbox(0, "Daily Restart", "Daily Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe")
            Exit
    Case Else
        $msg = "Others"
    EndSwitch
Case Else
    $msg = "Something went horribly wrong."
EndSwitch
WEnd

Msgbox(0, "Timeout Reached", "Timeout Reached")
    ;    run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe")

Func _Timeout()
    ;Put your main timeout function here
    MsgBox(0, "", "")
    AdLibDisable()
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

here is your script with a time-out

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\Koda\Forms\ITStart.kxf
$Form1 = GUICreate("ITS Applications", 211, 203, 333, 219)
$Button1 = GUICtrlCreateButton("&Weekly Restart", 8, 152, 81, 41, 0)
$Button2 = GUICtrlCreateButton("&Daily Restart", 122, 152, 81, 41, 0)
$Group1 = GUICtrlCreateGroup("Weekly or Daily?", 8, 8, 193, 129)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Do you want to start the Weekly  or Daily Applications?  This will affect Infopath and whether it opens a previously worked on file or starts a new report.  The script will timeout in 25 seconds and default to the Weekly Application startup.  Thanks and have a nice day;-)", 16, 24, 176, 108)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$msg = ""

$begin = TimerInit()

While 1
    $dif = Round(TimerDiff($begin) / 1000)
    If $dif >= 25 Then
        MsgBox(0,0,"timed out ")
        $begin = TimerInit()
        ; do other stuff
    EndIf
$szName = GUIGetMsg()

Switch @error
Case 2
    $msg = "Timeout "
    ContinueCase
Case 1; Continuing previous case
    $msg &= "Cancellation"
Case 0
    Switch $szName
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            msgbox(0, "Weekly Restart", "Weekly Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\ITS.exe")
            Exit
        Case $Button2
            msgbox(0, "Daily Restart", "Daily Restart button was pressed")
        ;run("C:\Program Files\AutoIt3\Scripts\ITSupport\DailyITS.exe")
            Exit
    Case Else
        $msg = "Others"
    EndSwitch
Case Else
    $msg = "Something went horribly wrong."
EndSwitch
WEnd

Msgbox(0, "Timeout Reached", "Timeout Reached")
    ;    run("C:\Program Files\AutoIt3\Scripts\ITSupport\Daily_ITS.exe")

8)

EDIT:... now you have two approaches

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

One approach would be to utilize a global variable w/ the amount of time elapsed since your timer set, and testing that value in each message loop rather than attempting to implement as a gui message.

#include <GUIConstants.au3>
; == GUI generated with Koda ==
$DelAForm1 = GUICreate("DelAForm1", 622, 444, 192, 125)
$Button1 = GUICtrlCreateButton("AButton1", 152, 64, 113, 49, 0)
GUISetState(@SW_SHOW,$DelAForm1)

$time_elapsed = TimerStart()
$timeout_seconds = 3

While 1
   If TimerDiff($time_elapsed) > $timeout_seconds * 1000 then Exit -$timeout_seconds
$msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    
    EndSelect
WEnd
Exit

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

with ... TimerStart()

did you mean... TimerInit()

8)


NEWHeader1.png

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  
Followers 0