Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

tk::callbacks(3) [centos man page]

callbacks(3)						User Contributed Perl Documentation					      callbacks(3)

NAME
Tk::callbacks - Specifying code for Tk to call. SYNOPSIS
One can specify a callback in one of the following ways: Without arguments: ... => &subname, ... ... => sub { ... }, ... ... => 'methodname', ... or with arguments: ... => [ &subname, args ... ], ... ... => [ sub { ... }, args... ], ... ... => [ 'methodname', args... ], ... DESCRIPTION
Perl/Tk has a callback, where Tcl/Tk has a command string (i.e. a fragment of Tcl to be executed). A perl/Tk callback can take one of the following basic forms: o Reference to a subroutine "&subname" o Anonymous subroutine (closure) "sub { ... }" o A method name 'methodname' Any of these can be provided with arguments by enclosing them and the arguments in []. Here are some examples: $mw->bind($class, "<Delete>" => 'Delete'); This will call $widget->Delete, the $widget being provided (by bind) as the one where the Delete key was pressed. While having bind provide a widget object for you is ideal in many cases it can be irritating in others. Using the list form this behaviour can be modified: $a->bind("<Delete>",[$b => 'Delete']); because the first element $b is an object bind will call $b->Delete. Note that method/object ordering only matters for "bind" callbacks, the auto-quoting in perl5.001 makes the first of these a little more readable: $w->configure(-yscrollcommand => [ set => $ysb]); $w->configure(-yscrollcommand => [ $ysb => 'set' ]); but both will call $ysb->set(args provided by Tk) Another use of arguments allows you to write generalized methods which are easier to re-use: $a->bind("<Next>",['Next','Page']); $a->bind("<Down>",['Next','Line']); This will call $a->Next('Page') or $a->Next('Line') respectively. Note that the contents of the "[]" are evaluated by perl when the callback is created. It is often desirable for the arguments provided to the callback to depend on the details of the event which caused it to be executed. To allow for this callbacks can be nested using the "Ev(...)" "constructor". "Ev(...)" inserts callback objects into the argument list. When perl/Tk glue code is preparing the argument list for the callback it is about to call it spots these special objects and recursively applies the callback process to them. EXAMPLES
$entry->bind('<Return>' => [$w , 'validate', Ev(['get'])]); $toplevel->bind('all', '<Visibility>', [&unobscure, Ev('s')]); $mw->bind($class, '<Down>', ['SetCursor', Ev('UpDownLine',1)]); SEE ALSO
Tk::bind Tk::after Tk::options Tk::fileevent KEYWORDS
callback, closure, anonymous subroutine, bind perl v5.16.3 2014-06-10 callbacks(3)

Check Out this Related Man Page

after(3)						User Contributed Perl Documentation						  after(3)

NAME
Tk::after - Execute a command after a time delay SYNOPSIS
$widget->after(ms) $id = $widget->after(ms?,callback?) $id = $widget->repeat(ms?,callback?) $widget->afterCancel($id) $id = $widget->afterIdle(callback) $widget->afterInfo?($id)? $id->time(?delay?) 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 $widget->after is implemented via the class "Tk::After", and callbacks are associated with $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. Internal Details The internal Tk::After class has the following synopsis: $id = Tk::After->new($widget, tid, $time, 'once', callback); $id = Tk::After->new($widget, tid, $time, 'repeat', callback); $id->cancel; $id->time(?delay?); $id is a Tk::After object, an array of 5 elements: $widget is the parent widget reference. tid is the internal timer id, a unique string. $time is the string 'idle', representing an idle queue timer, or a integer millisecond value. once or repeat specifies whether the timer is a one-time after event, or a repeating repeat event. callback specifies a Perl/Tk Tk::Callback object. Changing a repeat timer interval It's posible to change a repeat timer's delay value, or even cancel any timer, using the time method. If delay is specified and non-zero, a new timer delay is established. If delay is zero the timer event is canceled just as if $id->cancel were invoked. In all cases the current millisecond timer delay is returned. Note: the new timer delay will take effect on the subsequent timer event - this command will not cancel the pending timer event and re- issue it with the new delay time. The after() method has several forms as follows: $widget->after(ms) The value ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to events. $widget->after(ms,callback) In this form the command returns immediately, but it arranges for callback be executed ms 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 $widget. If an error occurs while executing the delayed command then the Tk::Error mechanism is used to report the error. The after command returns an identifier (an object in the perl/Tk case) that can be used to cancel the delayed command using afterCancel. $widget->repeat(ms,callback) In this form the command returns immediately, but it arranges for callback be executed ms milliseconds later as an event handler. After callback has executed it is re-scheduled, to be executed in a futher ms, and so on until it is cancelled. $widget->afterCancel($id) $id->cancel Cancels the execution of a delayed command that was previously scheduled. $id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by $id has already been executed (and is not scheduled to be executed again) then afterCancel has no effect. $widget->afterCancel(callback) This form is not robust in perl/Tk - its use is deprecated. This command should also cancel the execution of a delayed command. The callback 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 afterCancel has no effect. $widget->afterIdle(callback) Arranges for callback 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 afterCancel. If an error occurs while executing the script then the Tk::Error mechanism is used to report the error. $widget->afterInfo?($id)? This command returns information about existing event handlers. If no $id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the after and repeat commands for $widget. If $id is supplied, it specifies an existing handler; $id must have been the return value from some previous call to after or repeat and it must not have triggered yet or been cancelled. In this case the command returns a list with three elements. The first element of the list is the callback associated with $id, the second element is either idle or the integer timer millisecond value to indicate what kind of event handler it is, and the third is a string once or repeat to differentiate an after from a repeat event. The after(ms) and afterIdle 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 vwait and update commands. SEE ALSO
Tk::Error Tk::callbacks KEYWORDS
cancel, delay, idle callback, sleep, time perl v5.12.1 2007-05-05 after(3)
Man Page