B<Tk> - An overview of an Object Oriented Tk8.0 extension for perl5 |
Tk - An overview of an Object Oriented Tk8.0 extension for perl5
use Tk;
$main = MainWindow->new();
$widget = $main->Widget(...);
$widget->pack(...);
...
MainLoop;
In writing the perl Tk extension, the goals were to provide a complete interface to the latest production version of John Ousterhout's Tk, while providing an Object Oriented interface to perl code.
The package is composed of three loosely connected parts:
The ``major'' widgets such as Tk::Text are actually in separate directories at the top level (e.g. Text/* for Tk::Text) and are dynamically loaded as needed on platforms which support perl5's DynaLoader.
Tk::Widget provides various functions and interfaces which are common to all Widgets.
A widget is represented to perl as a blessed reference to a hash. There are some members of the hash which are private to Tk and its tkGlue code. Keys starting with '.' and of the form /_[A-Z][A-Za-z_]+_/ (i.e. starting and ending in _ and with first char after _ being upper case) should be considered reserved to Tk.
Other classes, Tk::Text for example, provide a lot of methods used with Tk's ``bind'' to provide a rich keyboard/mouse interface to the widgets' data.
These widget classes also include conversions of the Tcl code for event bindings, keyboard focus traversal, menu bars, and menu keyboard traversal. All the Tcl functions have been converted, but the names have changed (systematically) and they have been split up between the various classes in what I hope is an appropriate manner. Name changes are normally: dropping initial tk_ as the Tk-ness is implicit in the Tk:: prefix, and similarly dropping say Menu from the name if it has been moved the Tk::Menu class. Thus 'proc tkMenuNextEntry' becomes 'sub NextEntry' in the Tk::Menu package.
There are three sub-classes Tk::Bitmap, Tk::Pixmap and Tk::Photo.
It is expected that Tk::Image hierarchy will evolve during the ``beta'' phase of Tk to allow dynamic or auto-loaded image types or photo formats (e.g. support for JPEG format for photos).
Composite widgets are implemented via Tk::Frame and multiple inheritance. The two 'frame' base classes Tk::Frame and Tk::Toplevel include the additional class Tk::Derived in their inheritance. Tk::Derived provides methods to allow additional configure options to be defined for a widget.
A Composite widget is typically defined as derived from Tk::Frame or Tk::Toplevel (e.g. Tk::Dialog).
B<Tk> - An overview of an Object Oriented Tk8.0 extension for perl5 |