1after(3)              User Contributed Perl Documentation             after(3)
2
3
4

NAME

6       Tk::after - Execute a command after a time delay
7

SYNOPSIS

9        $widget->after(ms)
10
11        $id = $widget->after(ms?,callback?)
12
13        $id = $widget->repeat(ms?,callback?)
14
15        $widget->afterCancel($id)
16
17        $id = $widget->afterIdle(callback)
18
19        $widget->afterInfo?($id)?
20
21        $id->time(?delay?)
22

DESCRIPTION

24       This method is used to delay execution of the program or to execute a
25       callback in background sometime in the future.
26
27       In perl/Tk $widget->after is implemented via the class "Tk::After", and
28       callbacks are associated with $widget, and are automatically cancelled
29       when the widget is destroyed. An almost identical interface, but with‐
30       out automatic cancel, and without repeat is provided via Tk::after
31       method.
32
33       Internal Details
34
35       The internal Tk::After class has the following synopsis:
36
37         $id = Tk::After->new($widget, tid, $time, 'once',   callback);
38         $id = Tk::After->new($widget, tid, $time, 'repeat', callback);
39         $id->cancel;
40         $id->time(?delay?);
41
42       $id is a Tk::After object, an array of 5 elements:
43
44       $widget is the parent widget reference.
45
46       tid is the internal timer id, a unique string.
47
48       $time is the string 'idle', representing an idle queue timer, or a
49       integer millisecond value.
50
51       once or repeat specifies whether the timer is a one-time after event,
52       or a repeating repeat event.
53
54       callback specifies a Perl/Tk Tk::Callback object.
55

Changing a repeat timer interval

57       It's posible to change a repeat timer's delay value, or even cancel any
58       timer, using the time method. If delay is specified and non-zero, a new
59       timer delay is established.  If delay is zero the timer event is can‐
60       celed just as if $id->cancel were invoked.  In all cases the current
61       millisecond timer delay is returned.
62
63       Note: the new timer delay will take effect on the subsequent timer
64       event - this command will not cancel the pending timer event and re-
65       issue it with the new delay time.
66

The after() method has several forms as follows:

68       $widget->after(ms)
69           The value ms must be an integer giving a time in milliseconds.  The
70           command sleeps for ms milliseconds and then returns.  While the
71           command is sleeping the application does not respond to events.
72
73       $widget->after(ms,callback)
74           In this form the command returns immediately, but it arranges for
75           callback be executed ms milliseconds later as an event handler.
76           The callback will be executed exactly once, at the given time.  The
77           command will be executed in context of $widget.  If an error occurs
78           while executing the delayed command then the Tk::Error mechanism is
79           used to report the error.  The after command returns an identifier
80           (an object in the perl/Tk case) that can be used to cancel the
81           delayed command using afterCancel.
82
83       $widget->repeat(ms,callback)
84           In this form the command returns immediately, but it arranges for
85           callback be executed ms milliseconds later as an event handler.
86           After callback has executed it is re-scheduled, to be executed in a
87           futher ms, and so on until it is cancelled.
88
89       $widget->afterCancel($id)
90       $id->cancel
91           Cancels the execution of a delayed command that was previously
92           scheduled.  $id indicates which command should be canceled;  it
93           must have been the return value from a previous after command.  If
94           the command given by $id has already been executed (and is not
95           scheduled to be executed again) then afterCancel has no effect.
96
97       $widget->afterCancel(callback)
98           This form is not robust in perl/Tk - its use is deprecated.  This
99           command should also cancel the execution of a delayed command.  The
100           callback argument is compared with pending callbacks, if a match is
101           found, that callback is cancelled and will never be executed;  if
102           no such callback is currently pending then the afterCancel has no
103           effect.
104
105       $widget->afterIdle(callback)
106           Arranges for callback to be evaluated later as an idle callback.
107           The script will be run exactly once, the next time the event loop
108           is entered and there are no events to process.  The command returns
109           an identifier that can be used to cancel the delayed command using
110           afterCancel.  If an error occurs while executing the script then
111           the Tk::Error mechanism is used to report the error.
112
113       $widget->afterInfo?($id)?
114           This command returns information about existing event handlers.  If
115           no $id argument is supplied, the command returns a list of the
116           identifiers for all existing event handlers created by the after
117           and repeat commands for $widget. If $id is supplied, it specifies
118           an existing handler; $id must have been the return value from some
119           previous call to after or repeat and it must not have triggered yet
120           or been cancelled. In this case the command returns a list with
121           three elements.  The first element of the list is the callback
122           associated with $id, the second element is either idle or the inte‐
123           ger timer millisecond value to indicate what kind of event handler
124           it is, and the third is a string once or repeat to differentiate an
125           after from a repeat event.
126
127       The after(ms) and afterIdle forms of the command assume that the appli‐
128       cation is event driven:  the delayed commands will not be executed
129       unless the application enters the event loop.  In applications that are
130       not normally event-driven, the event loop can be entered with the vwait
131       and update commands.
132

SEE ALSO

134       Tk::Error Tk::callbacks
135

KEYWORDS

137       cancel, delay, idle callback, sleep, time
138
139
140
141perl v5.8.8                       2008-02-05                          after(3)
Impressum