Debian Codegraph @

pod/after.pod

raw ◀ ▶
1 Debian patch touch this file
1 # Copyright (c) 1990-1994 The Regents of the University of California.
2 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
3 # See the file "license.terms" for information on usage and redistribution
4 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5 #
6 #
7
8 =head1 NAME
9
10 Tk::after - Execute a command after a time delay
11
12 =for category Binding Events and Callbacks
13
14 =head1 SYNOPSIS
15
16 S< >I<$widget>-E<gt>B<after>(I<ms>)
17
18 S< >I<$id> = I<$widget>-E<gt>B<after>(I<ms>?,I<callback>?)
19
20 S< >I<$id> = I<$widget>-E<gt>B<repeat>(I<ms>?,I<callback>?)
21
22 S< >I<$widget>-E<gt>B<afterCancel>(I<$id>)
23
24 S< >I<$id> = I<$widget>-E<gt>B<afterIdle>(I<callback>)
25
26 S< >I<$widget>-E<gt>B<afterInfo>?(I<$id>)?
27
28 S< >I<$id>-E<gt>B<time>(?I<delay>?)
29
30 =head1 DESCRIPTION
31
32 This method is used to delay execution of the program or to execute
33 a callback in background sometime in the future.
34
35 In perl/Tk I<$widget>-E<gt>B<after> is implemented via the class C<Tk::After>,
36 and callbacks are associated with I<$widget>, and are automatically cancelled
37 when the widget is destroyed. An almost identical interface, but without
38 automatic cancel, and without repeat is provided via Tk::after method.
39
40 =head2 Internal Details
41
42 The internal Tk::After class has the following synopsis:
43
44 $id = Tk::After->new($widget, tid, $time, 'once', callback);
45 $id = Tk::After->new($widget, tid, $time, 'repeat', callback);
46 $id->cancel;
47 $id->time(?delay?);
48
49 $id is a Tk::After object, an array of 5 elements:
50
51 I<$widget> is the parent widget reference.
52
53 I<tid> is the internal timer id, a unique string.
54
55 I<$time> is the string 'idle', representing an idle queue timer, or a
56 integer millisecond value.
57
58 I<once> or I<repeat> specifies whether the timer is a one-time B<after>
59 event, or a repeating B<repeat> event.
60
61 I<callback> specifies a Perl/Tk Tk::Callback object.
62
63 =head1 Changing a B<repeat> timer interval
64
•65 It's possible to change a B<repeat> timer's delay value, or even cancel
66 any timer, using the B<time> method. If I<delay> is specified and
67 non-zero, a new timer delay is established. If I<delay> is zero the
68 timer event is canceled just as if I<$id>-E<gt>B<cancel> were invoked.
69 In all cases the current millisecond timer delay is returned.
70
71 Note: the new timer delay will take effect on the I<subsequent> timer
72 event - this command will not cancel the pending timer event and
73 re-issue it with the new delay time.
74
75 =head1 The after() method has several forms as follows:
76
77 =over 4
78
79 =item I<$widget>-E<gt>B<after>(I<ms>)
80
81 The value I<ms> must be an integer giving a time in milliseconds.
82 The command sleeps for I<ms> milliseconds and then returns.
83 While the command is sleeping the application does not respond to
84 events.
85
86 =item I<$widget>-E<gt>B<after>(I<ms>,I<callback>)
87
88 In this form the command returns immediately, but it arranges
89 for I<callback> be executed I<ms> milliseconds later as an
90 event handler.
91 The callback will be executed exactly once, at the given time.
92 The command will be executed in context of I<$widget>.
93 If an error occurs while executing the delayed command then the
94 L<Tk::Error|Tk::Error> mechanism is used to report the error.
95 The B<after> command returns an identifier (an object in the perl/Tk
96 case) that can be used to cancel the delayed command using B<afterCancel>.
97
98 =item I<$widget>-E<gt>B<repeat>(I<ms>,I<callback>)
99
100 In this form the command returns immediately, but it arranges
101 for I<callback> be executed I<ms> milliseconds later as an
102 event handler. After I<callback> has executed it is re-scheduled,
103 to be executed in a futher I<ms>, and so on until it is cancelled.
104
105 =item I<$widget>-E<gt>B<afterCancel>(I<$id>)
106
107 =item I<$id>-E<gt>B<cancel>
108
109 Cancels the execution of a delayed command that
110 was previously scheduled.
111 I<$id> indicates which command should be canceled; it must have
112 been the return value from a previous B<after> command.
113 If the command given by I<$id> has already been executed (and
114 is not scheduled to be executed again) then B<afterCancel>
115 has no effect.
116
117 =item I<$widget>-E<gt>B<afterCancel>(I<callback>)
118
119 I<This form is not robust in perl/Tk - its use is deprecated.>
120 This command should also cancel the execution of a delayed command.
121 The I<callback> argument is compared with pending callbacks,
122 if a match is found, that callback is
123 cancelled and will never be executed; if no such callback is
124 currently pending then the B<afterCancel> has no effect.
125
126 =item I<$widget>-E<gt>B<afterIdle>(I<callback>)
127
128 Arranges for I<callback> to be evaluated later as an idle callback.
129 The script will be run exactly once, the next time the event
130 loop is entered and there are no events to process.
131 The command returns an identifier that can be used
132 to cancel the delayed command using B<afterCancel>.
133 If an error occurs while executing the script then the
134 L<Tk::Error|Tk::Error> mechanism is used to report the error.
135
136 =item I<$widget>-E<gt>B<afterInfo>?(I<$id>)?
137
138 This command returns information about existing event handlers. If no
139 I<$id> argument is supplied, the command returns a list of the
140 identifiers for all existing event handlers created by the B<after>
141 and B<repeat> commands for I<$widget>. If I<$id> is supplied, it
142 specifies an existing handler; I<$id> must have been the return value
143 from some previous call to B<after> or B<repeat> and it must not have
144 triggered yet or been cancelled. In this case the command returns a
145 list with three elements. The first element of the list is the
146 callback associated with I<$id>, the second element is either B<idle>
147 or the I<integer> timer millisecond value to indicate what kind of
148 event handler it is, and the third is a string I<once> or I<repeat> to
149 differentiate an B<after> from a B<repeat> event.
150
151 =back
152
153 The B<after>(I<ms>) and B<afterIdle> forms of the command
154 assume that the application is event driven: the delayed commands
155 will not be executed unless the application enters the event loop.
156 In applications that are not normally event-driven,
157 the event loop can be entered with the B<vwait> and B<update> commands.
158
159 =head1 SEE ALSO
160
161 L<Tk::Error|Tk::Error>
162 L<Tk::callbacks|Tk::callbacks>
163
164 =head1 KEYWORDS
165
166 cancel, delay, idle callback, sleep, time
167
168 =cut