uevent(3tcl) | User events | uevent(3tcl) |
uevent - User events
package require Tcl 8.4
package require uevent ?0.3.1?
package require logger
::uevent::bind tag event command
command tag event details
::uevent::unbind token
::uevent::generate tag event ?details?
::uevent::list
::uevent::list tag
::uevent::list tag event
::uevent::watch::tag::add pattern command
{*}command bound tag
{*}command unbound tag
::uevent::watch::tag::remove token
::uevent::watch::event::add tag_pattern event_pattern command
{*}command bound tag event
{*}command unbound tag event
::uevent::watch::event::remove token
This package provides a general facility for the handling of user events. Allows the binding of arbitrary commands to arbitrary events on arbitrary tags, removal of bindings, and event generation.
The main difference to the event system built into the Tcl/Tk core is that the latter can generate only virtual events, and only for widgets. It is not possible to use the builtin facilities to bind to events on arbitrary (pseudo-)objects, nor is it able to generate events for such.
Here we can, by assuming that each object in question is represented by its own tag. Which is possible as we allow arbitrary tags.
More differences:
The package exports eight commands, as specified below. Note that when the package is used from within Tcl 8.5+ all the higher commands are ensembles, i.e. the :: separators can be replaceed by spaces.
The signature of the command prefix is
where details contains the argument(s) of the event. Its contents are event specific and have to be agreed upon between actual event generator and consumer. This package simply transfers the information and does not perform any processing beyond that.
Note that all bound commands are triggered, independently of each other. The event handlers cannot assume a specific order. They are also not called synchronously with the invokation of this command, but simply put into the event queue for processing when the system returns to the event loop.
Generating an event for an unknown tag, or for a <tag,event> combination which has no commands bound to it is allowed, such calls will be ignored.
Note that the command prefix is only invoked twice per tag, first when the first command is bound to any event of the tag, and second when the last command bound to the tag is removed.
The signature of the command prefix is
The result of the command is a token representing the watcher.
The result of the command is the empty string.
Note that the command prefix is only invoked twice per tag/event combination, first when the first command is bound to it, and second when the last command bound to the it is removed.
The signature of the command prefix is
The result of the command is a token representing the watcher.
The result of the command is the empty string.
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category uevent of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.
hook(3tcl)
bind, event, generate event, hook, unbind
Programming tools
Copyright (c) 2007-2012 Andreas Kupries <andreas_kupries@users.sourceforge.net>
0.3.1 | tcllib |