Tk::ObjectHandler

Perl extension for Tk
Download

Tk::ObjectHandler Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Simon Parsons
  • Publisher web site:
  • http://search.cpan.org/~caillte/

Tk::ObjectHandler Tags


Tk::ObjectHandler Description

Perl extension for Tk Tk::ObjectHandler is a Perl extension for Tk.SYNOPSIS use Tk::ObjectHandler; my $tk = Tk::ObjectHandler->new(); $tk->add_widget("Button","but1", -text, "Press Me", -command => sub{ $tk->destroy(); }); $tk->but1->pack(-fill => "both"); $tk->Loop;ABSTRACTTk::ObjectHandler provides an automated method for creating, ordering and cataloging the variables used to hold Tk widgets. Rather than having to use a confusing number of individual holders ObjectHandler arranges the widgets so that widgets that are packed onto a parent widget are called via the parent widget.Creating a program in Tk can sometimes become confusing due to the number of variables needed to hold pointers to widgets. Tk::ObjectHandler is an attempt to provide a generic method for providing a logical heirarchy for widgets, allowing easy reference through one entrance point.When created, the Tk::ObjectHandler object sets up a Tk::Toplevel widget and wraps it in it's own administration code. This code allows you to set up a heirarchy of widgets all accessable through one entry point. For example, imagine a simple report window, say with a couple of labels and a close button. In traditional Tk you would create these like the following: my $mw = new MainWindow(); my $label1 = $mw->Label(-text => 'Title text'); my $label2 = $mw->Label(-text => 'Body text of the message window'); my $button = $mw->Button(-text => 'Close', -command => sub { $mw->destroy; }); $label1->pack(); $label2->pack(); $button->pack();Using ObjectHandler, there is only one variable used: my $mw = Tk::ObjectHandler->new(); $mw->add_widget('Label', 'Label1', -text => 'Title text'); $mw->add_widget('Label', 'Label2', -text => 'Body text of the message window'); $mw->add_widget('Button', 'button', -text => 'Close', -command => sub { $mw->destroy; }); $mw->Label1->pack(); $mw->Label2->pack(); $mw->button->pack();So, what is the difference? Well, in the example above, not much really, but in larger programs the number of variables required can become hard to keep track of leading to duplication and slowing development time while you play 'hunt the variable'. ObjectHandler overcoes this problem in two ways. First, objects are refered to in a structured format, you can only refer to a widget through its parent, like below: $mw->frame->label1->configure(...) ...would configure the widget label1 that is attatched to the frame that is attatched to the main window.Using this heirarcal method of naming means that you can use the following as valid widget names: $mw->frame1->label1... $mw->frame2->label1... $mw->frame3->label1... $mw->frame4->label1......which can save wear and tear on the brain when thinking of variable names ;)The second method in which ObjectHandler helps is with it's self-documenting code. Using the report method you can automatically generate reports on the widgets and sub widgets (and sub-sub widgets etc) of the whole program or any section thereof. As well as names and widget types, ObjectHandler also allows you to inser comments into the tree. Requirements: · Perl


Tk::ObjectHandler Related Software