Name: clientData Class: ClientData Command-Line Switch: -clientdata
The Archetype class is the basis for all [incr Tk] mega-widgets. It keeps track of component widgets and provides methods like "configure" and "cget" that are used to access the composite configuration options. Each component widget must be registered with the Archetype base class using the "itk_component add" method. When the component is registered, its configuration options are integrated into the composite option list. Configuring a composite option like "-background" causes all of the internal components to change their background color.
It is not used as a widget by itself, but is used as a base class for more specialized widgets. The Widget base class inherits from Archetype, and adds a Tk frame which acts as the "hull" for the mega-widget. The Toplevel base class inherits from Archetype, but adds a Tk toplevel which acts as the "hull".
Each derived class must invoke the itk_initialize method within its constructor, so that all options are properly integrated and initialized in the composite list.
The following methods are provided to support the public interface of the mega-widget.
In this case, option refers to a composite configuration option for the mega-widget. Individual components integrate their own configuration options onto the composite list when they are registered by the "itk_component add" method.
If a symbolic name is specified, this method returns the window path name for that component.
Otherwise, the command and any remaining arg arguments are invoked as a method on the component with the symbolic name name. This provides a well-defined way of accessing internal components without relying on specific window path names, which are really details of the implementation.
In this case, the options refer to composite configuration options for the mega-widget. Individual components integrate their own configuration options onto the composite list when they are registered by the "itk_component add" method.
The following methods are used in derived classes as part of the implementation for a mega-widget.
The createCmds code can contain any number of commands, but it must return the window path name for the new component widget.
The optionCmds script contains commands that describe how the configuration options for the new component should be integrated into the composite list for the mega-widget. It can contain any of the following commands:
If the optionCmds script is not specified, the usual option-handling commands associated with the class of the component widget are used by default.
Note that you can destroy a component using the destroy command, just as you would destroy any Tk widget. Components automatically detach themselves from their mega-widget parent when destroyed, so "itk_component delete" is rarely used.
If any option/value pairs are specified, they override settings determined from the X11 resource database. The arguments to the constructor are usually passed along to this method as follows:
class MyWidget { inherit Widget constructor {args} { . . . eval itk_initialize $args } }
Options are normally integrated into the composite option list when a component widget is first created. This method can be used to add options at a later time. For example, the Widget and Toplevel base classes keep only the bare minimum options for their "hull" component: -background and -cursor. A derived class can override this decision, and add options that control the border of the "hull" component as well:
class MyWidget { inherit Widget constructor {args} { itk_option add hull.borderwidth hull.relief itk_component add label { label $itk_interior.l1 -text "Hello World!" } pack $itk_component(label) eval itk_initialize $args } }
In the following example, a synthetic "-background" option is added to the class, so that whenever the background changes, the new value is reported to standard output. Note that this synthetic option is integrated with the rest of the "-background" options that have been kept from component widgets:
class MyWidget { inherit Widget constructor {args} { itk_component add label { label $itk_interior.l1 -text "Hello World!" } pack $itk_component(label) eval itk_initialize $args } itk_option define -background background Background #d9d9d9 { puts "new background: $itk_option(-background)" } }
Options are normally integrated into the composite option list when a component widget is first created. This method can be used to remove options at a later time. For example, a derived class can override an option defined in a base class by removing and redefining the option:
class Base { inherit Widget constructor {args} { eval itk_initialize $args } itk_option define -foo foo Foo "" { puts "Base: $itk_option(-foo)" } } class Derived { inherit Base constructor {args} { itk_option remove Base::foo eval itk_initialize $args } itk_option define -foo foo Foo "" { puts "Derived: $itk_option(-foo)" } }Without the "itk_option remove" command, the code fragments for both of the "-foo" options would be executed each time the composite "-foo" option is configured. In the example above, the Base::foo option is suppressed in all Derived class widgets, so only the Derived::foo option remains.