uevent(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

uevent β€” literally just User events, bestie πŸ’–

It's the uevent page from the Tcl manual pages (section 3tcl), and yes we're gonna get into it.


✨ SYNOPSIS ✨

package require Tcl 8.5 9

package require uevent ?0.3.2?

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

πŸ’… DESCRIPTION πŸ’…

Okay so this package is a whole general-purpose facility for handling user events. You can bind arbitrary commands to arbitrary events on arbitrary tags πŸŽ€, remove bindings, and generate events. It's giving very flexible, no cap.

The main difference from the event system built into the Tcl/Tk core? That one can only generate virtual events, and only for widgets 😭. You literally cannot use the builtin stuff to bind to events on arbitrary (pseudo-)objects, and it can't generate events for those either. Not it.

Here we can, because we just assume that each object in question is represented by its own tag πŸ¦‹. Which works out perfectly since we allow arbitrary tags. Iconic.

More differences, because there's always more:

  1. This package uses only a two-level hierarchy β€” tags and events β€” to handle everything 🌸. Meanwhile the Tcl/Tk system uses three levels, i.e. objects, tags, and events, with a n:m relationship between objects and tags. Different vibes entirely.
  2. This package triggers all bound commands for a tag/event combination, and they're fully independent of each other πŸ’«. A bound command cannot force the event processing core to abort the processing of commands coming after it. No main character behavior allowed, everyone gets their moment.

πŸ‘‘ API πŸ‘‘

The package exports eight commands, as specified below ⭐. Also, note that when the package is used from within Tcl 8.5+ all the higher commands are ensembles, i.e. the :: separators can be swapped out for spaces πŸ’–.

  • ::uevent::bind tag event command β€” Using this command registers the command prefix to be triggered when the event occurs for the tag πŸŽ€. The result of the command is an opaque token representing the binding. Heads up bestie: if the same combination of <tag,event,command> is used multiple times, the same token is returned by every call. Same token, every time, fr fr.

The signature of the command prefix is

command tag event details

where details contains the argument(s) of the event. Its contents are event specific and have to be agreed upon between the actual event generator and the consumer. This package simply transfers the information and does not perform any processing beyond that. It's a courier, not a translator, iykyk πŸ’…

  • ::uevent::unbind token β€” This command releases the event binding represented by the token πŸ¦‹. The token has to be the result of a call to ::uevent::bind. The result of the command is the empty string.
  • ::uevent::generate tag event ?details? β€” This command generates an event for the tag, triggering all commands bound to that combination πŸ”₯. The details argument is simply passed unchanged to all event handlers. It is the responsibility of the code generating and consuming the event to have an agreement about the format and contents of the information carried therein. The result of the command is the empty string.

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 invocation of this command, but simply put into the event queue for processing when the system returns to the event loop. So like, they're on read, not on call. Got it?

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 just be ignored πŸ’€. No error, no drama.

  • ::uevent::list β€” In this form the command returns a list containing the names of all tags which have events with commands bound to them 🌈.
  • ::uevent::list tag β€” In this format the command returns a list containing the names of all events for the tag with commands bound to them. Specifying an unknown tag, i.e. a tag without event and commands, will cause the command to throw an error 😭.
  • ::uevent::list tag event β€” In this format the command returns a list containing all commands bound to the event for the tag. Specifying an unknown tag or unknown event, will cause the command to throw an error πŸ’€.
  • ::uevent::watch::tag::add pattern command β€” This command sets up a sort of reverse events ✨. Events generated, i.e. the command prefix invoked, when observers bind to and unbind from specific tags.

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

{*}command bound tag

{*}command unbound tag

The result of the command is a token representing the watcher πŸŽ€.

  • ::uevent::watch::tag::remove token β€” This command removes a watcher for (un)bind events on tags πŸ¦‹.

The result of the command is the empty string.

  • ::uevent::watch::event::add tag_pattern event_pattern command β€” This command sets up a sort of reverse events ✨. Events generated, i.e. the command prefix invoked, when observers bind to and unbind from specific combinations of tags and events.

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 it is removed πŸ’….

The signature of the command prefix is

{*}command bound tag event

{*}command unbound tag event

The result of the command is a token representing the watcher πŸŽ€.

  • ::uevent::watch::event::remove token β€” This command removes a watcher for (un)bind events on tag/event combinations 🌸.

The result of the command is the empty string.


πŸ› BUGS, IDEAS, FEEDBACK πŸ›

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 at 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. Left-most button. Don't miss it bestie πŸ’….


🌈 SEE ALSO 🌈


πŸŽ€ KEYWORDS πŸŽ€

bind, event, generate event, hook, unbind


πŸ’œ CATEGORY πŸ’œ

Programming tools


Copyright (c) 2007-2012 Andreas Kupries <andreas_kupries@users.sourceforge.net>


That's the whole thing, bestie 🫢 this was tcllib version 0.3.2 of the uevent(3tcl) page, and honestly? She ate. Periodt πŸ’…βœ¨

πŸ“¦ where this page comes from