tk::Megawidget

tk::Megawidget is a system for megawidgets that is used internally inside Tk. It's main purpose is to clean up the guts of the Unix file dialogs by making the icon list "widget" more widget-like, but it is gradually being extended to be able to be used by code external to Tk.

THIS CODE IS EXPERIMENTAL

It's not yet ready for proper use by anyone who isn't intimately tracking the Tk implementation; when it is, it will be documented.

Interim Documentation

The following TclOO classes are defined:

tk::Megawidget
The factory metaclass. Must be used to make megawidget classes; does not exactly follow the usual TclOO syntax for doing so due to the critical extra bits and pieces it injects.
tk::MegawidgetClass
The root class of the widget hierarchy. Not normally explicitly talked about. Defines the configure and cget methods as well as a number of utilities for handling idle events and widget destruction.
tk::SimpleWidget
A simple wrapper class for ttk widgets. Uses a ttk::frame as the internal hull widget and defines the state and instate methods.
tk::FocusableWidget
An extension of SimpleWidget that can support the Tk focus protocol.

To learn how to use these classes, please see the implementation of the iconlist widget in the Tk 8.6 source code.

FWIW, the class hierarchy for the iconlist looks like:

  oo::object -> tk::MegawidgetClass -> tk::SimpleWidget -> tk::FocusableWidget -> tk::IconList

Note also that all the above classes in that hierarchy (except for oo::object) are instances of tk::Megawidget itself.

dzach 2018-03-29. For some reason changing bindtags for a Megawidget creates an error to "bind $hull <Destroy> {...}" in the MegawidgetClass constructor, because it can't find the relevant "oo::Objxx my destroy" command. A workaround is to catch the bind script after it is created, which I'd assume would also work in the original code.