# Copyright (c) 1990-1994 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # =head1 NAME Tk::after - Execute a command after a time delay =for category Binding Events and Callbacks =head1 SYNOPSIS S< >I<$widget>-EB(I) S< >I<$id> = I<$widget>-EB(I?,I?) S< >I<$id> = I<$widget>-EB(I?,I?) S< >I<$widget>-EB(I<$id>) S< >I<$id> = I<$widget>-EB(I) S< >I<$widget>-EB?(I<$id>)? =head1 DESCRIPTION This method is used to delay execution of the program or to execute a callback in background sometime in the future. In perl/Tk I<$widget>-EB is implemented via the class C, and callbacks are associated with I<$widget>, and are automatically cancelled when the widget is destroyed. An almost identical interface, but without automatic cancel, and without repeat is provided via Tk::after method. The internal Tk::After class has the following synopsis: $id = Tk::After->new($widget,$time,'once',callback); $id = Tk::After->new($widget,$time,'repeat',callback); $id->cancel; The B method has several forms as follows: =over 4 =item I<$widget>-EB(I) The value I must be an integer giving a time in milliseconds. The command sleeps for I milliseconds and then returns. While the command is sleeping the application does not respond to events. =item I<$widget>-EB(I,I) In this form the command returns immediately, but it arranges for I be executed I milliseconds later as an event handler. The callback will be executed exactly once, at the given time. The command will be executed in context of I<$widget>. If an error occurs while executing the delayed command then the L mechanism is used to report the error. The B command returns an identifier (an object in the perl/Tk case) that can be used to cancel the delayed command using B. =item I<$widget>-EB(I,I) In this form the command returns immediately, but it arranges for I be executed I milliseconds later as an event handler. After I has executed it is re-scheduled, to be executed in a futher I, and so on until it is cancelled. =item I<$widget>-EB(I<$id>) =item I<$id>-Ecancel Cancels the execution of a delayed command that was previously scheduled. I<$id> indicates which command should be canceled; it must have been the return value from a previous B command. If the command given by I<$id> has already been executed (and is not scheduled to be executed again) then B has no effect. =item I<$widget>-EB(I) I This command should also cancel the execution of a delayed command. The I argument is compared with pending callbacks, if a match is found, that callback is cancelled and will never be executed; if no such callback is currently pending then the B has no effect. =item I<$widget>-EB(I) Arranges for I to be evaluated later as an idle callback. The script will be run exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that can be used to cancel the delayed command using B. If an error occurs while executing the script then the L mechanism is used to report the error. =item I<$widget>-EB?(I<$id>)? This command returns information about existing event handlers. If no I<$id> argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the B command for this MainWindow. If I<$id> is supplied, it specifies an existing handler; I<$id> must have been the return value from some previous call to B and it must not have triggered yet or been cancelled. In this case the command returns a list with two elements. The first element of the list is the callback associated with I<$id>, and the second element is either B or B to indicate what kind of event handler it is. =back The B(I) and B forms of the command assume that the application is event driven: the delayed commands will not be executed unless the application enters the event loop. In applications that are not normally event-driven, the event loop can be entered with the B and B commands. =head1 SEE ALSO L L =head1 KEYWORDS cancel, delay, idle callback, sleep, time =cut