1[manpage_begin uevent n 0.2] 2[copyright {2007 Andreas Kupries <andreas_kupries@users.sourceforge.net>}] 3[moddesc {User events}] 4[titledesc {User events}] 5[category {Programming tools}] 6[require Tcl 8.4] 7[require uevent [opt 0.2]] 8[require logger] 9[keywords event bind unbind {generate event}] 10[description] 11 12This package provides a general facility for the handling of user 13events. Allows the binding of arbitrary commands to arbitrary events 14on arbitrary tags, removal of bindings, and event generation. 15 16[para] 17 18The main difference to the event system built into the Tcl/Tk core is 19that the latter can generate only virtual events, and only for 20widgets. It is not possible to use the builtin facilities to bind to 21events on arbitrary (pseudo-)objects, nor is it able to generate 22events for such. 23 24[para] 25 26Here we can, by assuming that each object in question is represented 27by its own tag. Which is possible as we allow arbitrary tags. 28 29[para] 30 31More differences: 32 33[list_begin enumerated] 34[enum] 35 36The package uses only a two-level hierarchy, tags and events, to 37handle everything, whereas the Tcl/Tk system uses three levels, i.e. 38objects, tags, and events, with a n:m relationship between objects and 39tags. 40 41[enum] 42This package triggers all bound commands for a tag/event combination, 43and they are independent of each other. A bound command cannot force 44the event processing core to abort the processing of command coming 45after it. 46 47[list_end] 48 49[section API] 50 51The package exports three commands, as specified below: 52 53[list_begin definitions] 54 55[call [cmd ::uevent::bind] [arg tag] [arg event] [arg command]] 56 57Using this command registers the [arg command] prefix to be triggered 58when the [arg event] occurs for the [arg tag]. The result of the 59command is an opaque token representing the binding. Note that if the 60same combination of <[arg tag],[arg event],[arg command]> is used 61multiple times the same token is returned by every call. 62 63[para] 64 65The signature of the [arg command] prefix is 66 67[list_begin definitions] 68[call [cmd command] [arg tag] [arg event] [arg details]] 69[list_end] 70[para] 71 72where [arg details] contains the argument(s) of the event. Its 73contents are event specific and have to be agreed upon between actual 74event generator and consumer. This package simply transfers the 75information and does not perform any processing beyond that. 76 77 78[call [cmd ::uevent::unbind] [arg token]] 79 80This command releases the event binding represented by the 81[arg token]. The token has to be the result of a call to 82[cmd ::uevent::bind]. The result of the command is the empty string. 83 84 85[call [cmd ::uevent::generate] [arg tag] [arg event] [opt [arg details]]] 86 87This command generates an [arg event] for the [arg tag], triggering 88all commands bound to that combination. The [arg details] argument is 89simply passed unchanged to all event handlers. It is the 90responsibility of the code generating and consuming the event to have 91an agreement about the format and contents of the information carried 92therein. The result of the command is the empty string. 93 94[para] 95 96Note that all bound commands are triggered, independently of each 97other. The event handlers cannot assume a specific order. They are 98also [emph not] called synchronously with the invokation of this 99command, but simply put into the event queue for processing when the 100system returns to the event loop. 101 102[para] 103 104Generating an event for an unknown tag, or for a 105<[arg tag],[arg event]> combination which has no commands bound to it 106is allowed, such calls will be ignored. 107 108 109[call [cmd ::uevent::list]] 110 111In this form the command returns a list containing the names of all 112tags which have events with commands bound to them. 113 114 115[call [cmd ::uevent::list] [arg tag]] 116 117In this format the command returns a list containing the names of all 118events for the [arg tag] with commands bound to them. Specifying an 119unknown tag, i.e. a tag without event and commands, will cause the 120command to throw an error. 121 122 123[call [cmd ::uevent::list] [arg tag] [arg event]] 124 125In this format the command returns a list containing all commands 126bound to the [arg event] for the [arg tag]. Specifying an unknown tag 127or unknown event, will cause the command to throw an error. 128 129[list_end] 130 131[section {BUGS, IDEAS, FEEDBACK}] 132 133This document, and the package it describes, will undoubtedly contain 134bugs and other problems. 135 136Please report such in the category [emph uevent] of the 137[uri {http://sourceforge.net/tracker/?group_id=12883} {Tcllib SF Trackers}]. 138 139Please also report any ideas for enhancements you may have for either 140package and/or documentation. 141 142[manpage_end] 143