The Slab::Widget namespace handles data associated to all BWidgets
and provides commands to easily define a BWidget. It is retained in Slab for
use by the widgets that have not yet been ported to Snit. It also includes
general-purpose Utilities that are used by Slab widgets that have been ported to Snit.
Four commands can be used to define a BWidget:
tkinclude, bwinclude, declare, and addmap.
Here is the definition of ComboBox widget:
namespace eval ComboBox { # We're using ArrowButton, Entry and LabelFrame ArrowButton::use Entry::use LabelFrame::use # Include resources of LabelFrame Slab::Widget::bwinclude ComboBox LabelFrame .labf \ rename {-text -label} \ remove {-focus} \ prefix {label -justify -width -anchor -height -font} \ initialize {-relief sunken -borderwidth 2} # Include resources of Entry Slab::Widget::bwinclude ComboBox Entry .e \ remove {-relief -bd -borderwidth -bg -fg} \ rename {-foreground -entryfg -background -entrybg} # Declare new resources Slab::Widget::declare ComboBox { {-height TkResource 0 0 listbox} {-values String "" 0} {-modifycmd String "" 0} {-postcommand String "" 0} } # Map resources to subwidget Slab::Widget::addmap ComboBox "" :cmd {-background {}} Slab::Widget::addmap ComboBox ArrowButton .a \ {-foreground {} -background {} -disabledforeground {} -state {}} proc use {} {} } |
If rename is false, the path will not be renamed, but the proc will still be created. This is useful when inheriting another BWidget who will already have renamed the widget.
The command returns the widget path. This command is usually the last command executed in the ::create command for the widget.
This command is used to define a new BWidget class. It is usually the first command executed in a new widget definition.
Each class defined after the filename is a class that this widget depends on. The ::use command will be called for each of these classes after the new widget has been defined.
If -classonly option is not given this command does several things to setup the new class. First, it creates an alias in the global namespace for the name of the class that points to the class's ::create subcommand. Second, it defines a ::use subcommand for the class which other classes can use to load this class on the fly. Lastly, it creates a default binding to the <Destroy> event for the class that calls Slab::Widget::destroy on the path. This is the default setup for almost all widgets in the BWidget package.
Make the variable varName relational to path accessible in the current procedure. The variable will be created in the widget namespace for path and can be used for storing widget-specific information. When path is destroyed, any variable accessed in this manner will be destroyed with it.
If myVarName is specified, the variable will be accessible in the current procedure as that name.