The Slate tutorial ran quickly through creation of a class to implement a new complex item on the Slate. This page list the steps you need to take in more detail. (Of course, the best way is to make a copy of an existing class that is close to what you need, but this page should help you make sure that you don't miss anything.)
::tycho::Picture
or one of its subclasses.
construct
with the above three arguments, followed
by a list of tags to be attached to components, followed by two or more
coordinates, followed by option-value pairs. Unless the class has
no options, it must start with this code:
foreach {option value} [concat [array get optiondefault] $args] { set _[string trimleft $option -]($id) $value }The construction procedure does not automatically call its superclass "constructors": if your class needs that, you have to do it yourself. The destructor is optional, and is needed only if the class needs to do something other than destroy its components.
common methodtable(Do not change the name!) The class must (in the class body) initialize the table with the contents of the table in its superclass; assuming that the superclass is
Picture
, the class body
then contains:
array set methodtable [array get ::tycho::Picture::methodtable]The class must then "override" superclass "methods" with its own. The
construct
method is compulsory; others are
optional. Suppose your class overrides coords
(which many
classes do), your class body contains:
set methodtable(construct) ::tycho::Bar::construct set methodtable(coords) ::tycho::Bar::coordswhere "Bar" is the name of your class. If your class adds options, you must also add the option update procedures (see below).
-foo
, the class must contain:
_foo
.
_foo
.
The common variable must be an array, indexed by item ID,
containing the value of each item's -foo
. The procedure
must take, in addition to the usual three arguments, one argument that
it assigns to _foo($id)
; it can then perform any actions
that would normally (in a regular [incr Tcl] object) be done by the
configuration body of a public variable or itk_option
.
common optiondefaultEach option defined in this class must have its default value added to this array:
set optiondefault(-foo) bloo
array set optiondefault [array get ::tycho::Picture::optiondefault]
Each option must have its update procedure added to the "virtual method table":
set methodtable(_foo) ::tycho::Bar::_foo
common shape rectanglewhere instead of rectangle you could have oval, point, line, or polygon.