Widget
The Widget class is a subclass of Class that
forms the basis of all widgets in ClassyTk.
Widget provides the functionality to produce objects that behave like
Tk widgets. However it will normally not be used by itself to
create objects.
Subclasses of Widget are used to produce widgets with extra functionality.
All these "object widgets" are based on a Tk base widget, which by default
is a frame, but can be different.
Widget redefines the Tk destroy and bgerror commands to incorporate
proper destruction of object widgets.
If SomeWidgetClass is a subclass of Widget, and objectName starts with a dot,
the command
SomeWidgetClass objectName
creates an object (a widget) and a new Tcl command
whose name is objectName. This command may be used
to invoke various operations on the widget by using commands of the form:
objectName method ?...?
Widget methods
The Widget methods are available to all instances of Widget or one
of its subclasses.
-
init
-
The Widget init method will normally be called using the "super init"
command in the init classmethod of one of its subclasses.
By default the Widget init method will create an object
with a frame as Tk base widget.
If one argument is given, it will be used as the type of the base
widget of the new object, where the class (if possible) or bindtags
are adapted to the class name.
If more than one argument is given, the args will be evaluated to
create the base widget of the object. In this case getting the class
and bindtags of the Tk widget right is the resonsability of the caller.
-
objectName configure ?option? ?value? ?option value ...?
-
Query or modify the configuration options of an widget (object).
If no option is specified, returns a list
describing all of the available options for the widget.
If option is specified with
no value, then the command returns a list describing
the option (this list will be identical to
the corresponding sublist of the value
returned if no option is specified). If one or
more option-value pairs are specified, then the
command modifies the given class option(s) to have
the given value(s)
eg.:
SomeWidgetClass configure -try yes
-
objectName cget option
-
get the value of the option option
-
objectName component ?componentname? ?widget?
-
If no componentname is given, the names of all accessible
components are returned.
If componentname is given, the component widget associated with
componentname is returned.
If componentname and widget are given, widget
will be associated as a component with componentname.
-
objectName destroy
-
destroys an instance of Widget or one of its subclasses.
The Widget class also redefines the Tk destroy command, so
that objects can also be properly destroyed by the command
destroy objectName
eg.:
objectName destroy
Widget classmethods
The Widget classmethods are only available to Widget or one
of its subclasses, not to its instances.
-
className addoption option defaultlist ?body?
-
addoption is used to add an option to a class. The value of these options
can be changed or queried for each object (Widget) using the configure
and cget commands.
If body is given, it will be executed every time the option is changed.
In body, the special variables class and object are available.
Also available is a variable named value. This contains the new
value for the option on entry. The option value will be set to the
the return value of command. If no explicit return command is given in
command, the option value will be set to the value of the variable
value at exit.
defaultlist must be a list containing three elements:
databasename databaseclass defaultvalue
The values of options for each object are stored in the private
array options, and can be accessed by methods this way.
eg.:
SomeWidgetClass addoption -try {try Try 1} {return [true $value]}
-
className configure ?option? ?value? ?option value ...?
-
Query or modify the class specific configuration options.
If no option is specified, returns a list
describing all of the available options for the class.
If option is specified with
no value, then the command returns a list describing
the option (this list will be identical to
the corresponding sublist of the value
returned if no option is specified). If one or
more option-value pairs are specified, then the
command modifies the given class option(s) to have
the given value(s)
eg.:
SomeWidgetClass configure -try yes
-
className chainmethods list widget
-
chainmethods is a convenience to make commands of the Tk base widget
or subwidgets available to your class. It will
chain all methods given in list to widget. You can use the variable
object in the name; note that if you do this, you must put the $object
between braces, to delay substitution to when the actual object
calls the chained method!
eg.:
SomeWidgetClass chainmethods {set get} {$object}
SomeWidgetClass chainmethods {action} {$object.subwidget}
-
className chainallmethods widget widgettype
-
chain all commands of widgettype to a Tk widget widget.
The Tk widgets should be of type widgettype.
However, commands with the same name of several basic Class methods
are ignored (configure, config, cget, destroy, class, private, component).
eg.:
SomeWidgetClass chainallmethods {$object} text
-
className chainoptions widget
-
chainoptions is a convenience to make all options of the base widget
or a subwidget available to your class. It will
add all options that widget has to the options
of the class. Changing one of these options will change the option
of the chained widget. The options of only one base widget can
be chained this way!
eg.:
SomeWidgetClass chainoptions {$object}
-
className chainoption option widget widgetoption ?widget widgetoption? ...
-
chainoption is a convenience to make options of component widgets
available to your class. One option can be linked to several component
widgets. Changing the option will change the given widgetoptions for
all chained widgets. Querying the option will return the value
of the first chained option.
eg.:
SomeWidgetClass chainoption -bg {$object} -bg {$object.sub} -fg
-
className synonym_option option fulloption
-
synonym_option is a convenience to make synonymous options
using option will give the same results as using fulloption
eg.:
SomeWidgetClass chainoption -bg background
-
Widget destroy
-
When class Widget is destroyed, it tries to clean up after itself:
It undoes the redefinition of the destroy and bgerror command
eg.:
SomeWidgetClass addoption -try {try Try 1} {return [true $value]}