ActiveState!

ActivePerl Documentation
Table of Contents

(Usage Statistics)
(about this ver)


* Getting Started
    * Welcome To ActivePerl
    * Release Notes
    * Readme
    * ActivePerl Change Log
* Install Notes
    * Linux
    * Solaris
    * Windows
* ActivePerl Components
    * Overview
    * PPM
    * Windows Specifics
       * OLE Browser
       * PerlScript
       * Perl for ISAPI
       * PerlEZ
* ActivePerl FAQ
    * Introduction
    * Availability & Install
    * Using PPM
    * Docs & Support
    * Windows Specifics
       * Perl for ISAPI
       * Windows 9X/NT/2000
       * Quirks
       * Web Server Config
       * Web programming
       * Programming
       * Modules & Samples
       * Embedding & Extending
       * Using OLE with Perl
* Windows Scripting
    * Active Server Pages
    * Windows Script Host
    * Windows Script Components

Core Perl Documentation


* perl
* perlfaq
* perltoc
* perlbook

* perlsyn
* perldata
* perlop
* perlreftut
* perldsc
* perllol

* perllexwarn
* perldebug

* perlrun
* perlfunc
* perlopentut
* perlvar
* perlsub
* perlmod
* perlpod

* perlstyle
* perlmodlib
* perlmodinstall
* perltrap
* perlport
* perlsec

* perlref
* perlre
* perlform
* perllocale
* perlunicode

* perlboot
* perltoot
* perltootc
* perlobj
* perlbot
* perltie

* perlipc
* perlnumber
* perlfork
* perlthrtut

* perldiag
* perlfaq1
* perlfaq2
* perlfaq3
* perlfaq4
* perlfaq5
* perlfaq6
* perlfaq7
* perlfaq8
* perlfaq9

* perlcompile

* perlembed
* perlxstut
* perlxs
* perlguts
* perlcall
* perlfilter
* perldbmfilter
* perlapi
* perlintern
* perlapio
* perltodo
* perlhack

* perlhist
* perldelta
* perl5005delta
* perl5004delta

* perlamiga
* perlcygwin
* perldos
* perlhpux
* perlmachten
* perlos2
* perlos390
* perlvms
* perlwin32

Pragmas


* attributes
* attrs
* autouse
* base
* blib
* bytes
* charnames
* constant
* diagnostics
* fields
* filetest
* integer
* less
* lib
* locale
* lwpcook
* open
* ops
* overload
* perllocal
* re
* sigtrap
* strict
* subs
* utf8
* vars
* warnings

Libraries


* ActivePerl
    * DocTools
        * TOC
            * RDF
* AnyDBM_File
* Archive
    * Tar
* AutoLoader
* AutoSplit
* B
    * Asmdata
    * Assembler
    * Bblock
    * Bytecode
    * C
    * CC
    * Debug
    * Deparse
    * Disassembler
    * Lint
    * Showlex
    * Stackobj
    * Terse
    * Xref
* Benchmark
* Bundle
    * LWP
* ByteLoader
* Carp
    * Heavy
* CGI
    * Apache
    * Carp
    * Cookie
    * Fast
    * Pretty
    * Push
    * Switch
* Class
    * Struct
* Compress
    * Zlib
* Config
* CPAN
    * FirstTime
    * Nox
* Cwd
* Data
    * Dumper
* DB
* Devel
    * DProf
    * Peek
    * SelfStubber
* Digest
    * HMAC
    * HMAC_MD5
    * HMAC_SHA1
    * MD2
    * MD5
    * SHA1
* DirHandle
* Dumpvalue
* DynaLoader
* English
* Env
* Errno
* Exporter
    * Heavy
* ExtUtils
    * Command
    * Embed
    * Install
    * Installed
    * Liblist
    * MakeMaker
    * Manifest
    * Miniperl
    * Mkbootstrap
    * Mksymlists
    * MM_Cygwin
    * MM_OS2
    * MM_Unix
    * MM_VMS
    * MM_Win32
    * Packlist
    * testlib
* Fatal
* Fcntl
* File
    * Basename
    * CheckTree
    * Compare
    * Copy
    * CounterFile
    * DosGlob
    * Find
    * Glob
    * Listing
    * Path
    * Spec
        * Functions
        * Mac
        * OS2
        * Unix
        * VMS
        * Win32
    * stat
* FileCache
* FileHandle
* FindBin
* Font
    * AFM
* Getopt
    * Long
    * Std
* HTML
    * AsSubs
    * Element
    * Entities
    * Filter
    * Form
    * FormatPS
    * Formatter
    * FormatText
    * HeadParser
    * LinkExtor
    * Parse
    * Parser
    * TokeParser
    * TreeBuilder
* HTTP
    * Cookies
    * Daemon
    * Date
    * Headers
        * Util
    * Message
    * Negotiate
    * Request
        * Common
    * Response
    * Status
* I18N
    * Collate
* IO
    * Dir
    * File
    * Handle
    * Pipe
    * Poll
    * Seekable
    * Select
    * Socket
        * INET
        * UNIX
* IPC
    * Msg
    * Open2
    * Open3
    * Semaphore
    * SysV
* LWP
    * Debug
    * MediaTypes
    * MemberMixin
    * Protocol
    * RobotUA
    * Simple
    * UserAgent
* Math
    * BigFloat
    * BigInt
    * Complex
    * Trig
* MD5
* MIME
    * Base64
    * QuotedPrint
* NDBM_File
* Net
    * Cmd
    * Config
    * Domain
    * DummyInetd
    * FTP
    * hostent
    * libnetFAQ
    * netent
    * Netrc
    * NNTP
    * PH
    * Ping
    * POP3
    * protoent
    * servent
    * SMTP
    * SNPP
    * Time
* O
* ODBM_File
* Opcode
* Pod
    * Checker
    * Find
    * Html
    * InputObjects
    * Man
    * Parser
    * ParseUtils
    * Plainer
    * Select
    * Text
        * Color
        * Termcap
    * Usage
* POSIX
* PPM
    * SOAPClient
    * SOAPServer
* Safe
* SDBM_File
* Search
    * Dict
* SelectSaver
* SelfLoader
* SHA
* Shell
* SOAP
    * Defs
    * Envelope
    * EnvelopeMaker
    * GenericHashSerializer
    * GenericInputStream
    * GenericScalarSerializer
    * Lite
    * OutputStream
    * Packager
    * Parser
    * Transport
        * HTTP
            * Apache
            * CGI
            * Client
            * Server
        * LOCAL
        * MAILTO
        * POP3
        * TCP
    * TypeMapper
* Socket
* Symbol
* Sys
    * Hostname
    * Syslog
* Term
    * ANSIColor
    * Cap
    * Complete
    * ReadLine
* Test
    * Harness
* Text
    * Abbrev
    * ParseWords
    * Soundex
    * Tabs
    * Wrap
* Thread
    * Queue
    * Semaphore
    * Signal
    * Specific
* Tie
    * Array
    * Handle
    * Hash
    * RefHash
    * Scalar
    * SubstrHash
* Time
    * gmtime
    * Local
    * localtime
    * tm
* UDDI
    * Lite
* UNIVERSAL
* URI
    * data
    * Escape
    * file
    * Heuristic
    * ldap
    * URL
    * WithBase
* User
    * grent
    * pwent
* Win32
    * AuthenticateUser
    * ChangeNotify
    * Clipboard
    * Console
    * Event
    * EventLog
    * File
    * FileSecurity
    * Internet
    * IPC
    * Mutex
    * NetAdmin
    * NetResource
    * ODBC
    * OLE
        * Const
        * Enum
        * NEWS
        * NLS
        * TPJ
        * Variant
    * PerfLib
    * Pipe
    * Process
    * Registry
    * Semaphore
    * Service
    * Sound
    * TieRegistry
* Win32API
    * File
    * Net
    * Registry
* WWW
    * RobotRules
        * AnyDBM_File
* XML
    * Element
    * Parser
        * Expat
    * PPD
    * PPMConfig
    * ValidatingElement
* XSLoader

 Tk::mega - perl/Tk support to write widgets in perl


NAME

Tk::mega - perl/Tk support to write widgets in perl


SUPPORTED PLATFORMS

  • Linux
  • Solaris
  • Windows
This module is not included with the standard ActivePerl distribution. It is available as a separate download using PPM.

SYNOPSIS

    package Tk::Whatever;

    Construct Tk::ValidFor 'Whatever';

    sub ClassInit { my ($mega, $args) = @_; ... }

For composite widget classes:

    sub Populate { my ($composite, $args) = @_; ... }

For derived widget classes:

    sub InitObject { my ($derived, $args) = @_; ... }


DESCRIPTION

The goal of the mega widget support of perl/Tk is to make it easy to write mega widgets that obey the same protocol and interface that the Tk core widgets support. There are two kinds of mega widgets:

  • Composite Widgets
    A composite widget is composed with one or more existing widgets. The composite widget looks to the user like a simple single widget. A well known example is the file selection box.

  • Derived Widgets
    A derived widget adds/modifies/removes properties and methods from a single widget (this widget may itself be a mega widget).


MEGA WIDGET SUPPORT

Advertise

Give a subwidget a symbolic name.

Usage:

    $cw->Advertise(name=>$widget);

Gives a subwidget $widget of the composite widget $cw the name name. One can retrieve the reference of an advertised subwidget with the Subwidget method.

Comment: Mega Widget Writers: Please make sure to document the advertised widgets that are intended for public use. If there are none, document this fact, e.g.:

        =head1 ADVERTISED WIDGETS
        None.

Callback

Invoke a callback specified with an option.

Usage:

    $mega->Callback(-option ?,args ...?);

Callback executes the callback defined with $mega->ConfigSpecs(-option, [CALLBACK, ...]); If args are given they are passed to the callback. If -option is not defined it does nothing.

ClassInit

Initialization of the mega widget class.

Usage:

    sub ClassInit { my ($class, $mw) = @_; ... }

ClassInit is called once for each MainWindow just before the first widget instance of a class is created in the widget tree of MainWindow.

ClassInit is often used to define bindings and/or other resources shared by all instances, e.g., images.

Examples:

 $mw->bind($class,"<Tab>", sub { my $w = shift; $w->Insert("\t"); $w->focus; $w->break});
 $mw->bind($class,"<Return>", ['Insert',"\n"]);
 $mw->bind($class,"<Delete>",'Delete');

Notice that $class is the class name (e.g. Tk::MyText) and $mw is the mainwindow.

Don't forget to call $class->SUPER::ClassInit($mw) in ClassInit.

Component

Convenience function to create subwidgets.

Usage:

    $cw->Component('Whatever', 'AdvertisedName',
                   -delegate => ['method1', 'method2', ...],
                   ... Whatever widget options ...,
                  );

Component does several things for you with one call:

o Creates the widget

o Advertises it with a given name (overridden by 'Name' option)

o Delegates a set of methods to this widget (optional)

Example:

    $cw->Component('Button', 'quitButton', -command => sub{$mw->'destroy'});

ConfigSpecs

Defines options and their treatment

Usage:

    $cw->ConfigSpecs(
            -option => [ where, dbname, dbclass, default],
            ...,
            DEFAULT => [where],
            );

Defines the options of a mega widget and what actions are triggered by configure/cget of an option (see the Tk::ConfigSpecs manpage and the Tk::Derived manpage for details).

Construct

Make the new mega widget known to Tk.

Usage:

    Construct baseclass 'Name';

Construct declares the new widget class so that your mega widget works like normal Perl/Tk widgets.

Examples:

    Construct Tk::Widget 'Whatever';     Construct Tk::Menu 'MyItem';

First example lets one use $widget->Whatever to create new Whatever widget.

The second example restricts the usage of the MyItem constructor method to widgets that are derived from Menu: $isamenu->MyItem.

CreateArgs

Mess with options before any widget is created

    sub CreateArgs { my ($package, $parent, $args) = @_; ...; return @newargs; }

$package is the package of the mega widget (e.g., Tk::MyText, $parent the parent of the widget to be created and $args the hash reference to the options specified in the widget constructor call.

Don't forget to call $package->SUPER::CreateArgs($parent, $args) in CreateArgs.

Delegates

Redirect a method of the mega widget to a subwidget of the composite widget

Usage:

    $cw->Delegates(
                'method1' => $subwidget1,
                'method2' => 'advertived_name',
                ...,
                'Construct' => $subwidget2,
                'DEFAULT'   => $subwidget3,
                );

The 'Construct' delegation has a special meaning. After 'Construct' is delegated all Widget constructors are redirected. E.g. after

    $mega->Delegates('Construct'=>$subframe);

a $mega->Button does really a $subframe->Button so the created button is a child of $subframe and not $mega.

Comment: Delegates works only with methods that $cw does not have itself.

InitObject

Defines construction and interface of derived widgets.

Usage:

    sub InitObject {
        my ($derived, $args) = @_;
        ...
    }

where $derived is the widget reference of the already created baseclass widget and $args is the reference to a hash of -option-value pairs.

InitObject is almost identical to Populate method. Populate does some more 'magic' things useful for mega widgets with several widgets.

Don't forget to call $derived->SUPER::InitObject($args) in InitObject.

OnDestroy

Define callback invoked when widget is destroyed.

Usage:

    $widget->OnDestroy(callback);

OnDestroy installs a callback that's called when a widget is going to to be destroyed. Useful for special cleanup actions. It differs from a normal destroy in that all the widget's data structures are still intact.

Comment: This method could be used with any widgets not just for mega widgets. It's listed here because of it's usefulness.

Populate

Defines construction and interface of the composite widget.

Usage:

    sub Populate {
        my ($mega, $args) = @_;
        ...
    }

where $mega is the widget reference of the already created baseclass widget and $args is the reference to a hash of -option-value pairs.

Most the other support function are normally used inside the Populate subroutine.

Don't forget to call $cw->SUPER::Populate($args) in Populate.

privateData

Set/get a private hash of a widget to storage composite internal data

Usage:

    $hashref = $mega->privateData();

    $another = $mega->privateData(unique_key|package);

Subwidget

Get the widget reference of an advertised subwidget.

    $subwidget = $cw->Subwidget(name);

    @subwidget = $cw->Subwidget(name ?,...?);

Returns the widget reference(s) of the subwidget known under the name name. See Advertise method how to define name for a subwidget.

Comment: Mega Widget Users: Use Subwidget to get only documented subwidgets.


PITFALLS

  • Resource DB class name
    Some of the standard options use a resource date base class that is not equal to the resource database name. E.g.,
      Switch:            Name:             Class:
      -padx              padX              Pad
      -activerelief      activeRelief      Relief
      -activebackground  activeBackground  Foreground
      -status            undef             undef

    One should do the same when one defines one of these options via ConfigSpecs.

  • Method delegation
    Redirecting methods to a subwidget with Delegate can only work if the base widget itself does have a method with this name. Therefore one can't ``delegate'' any of the methods listed in Tk::Widget. A common problematic method is bind. In this case one as to explicitely redirect the method.
      sub bind
        {
          my $mega = shift;
          my $to = $mega->privateData->{'my_bind_target'};
          $to->bind(@_);
        }

  • privateData
    Graham Barr wrote: ... It is probably more private than most people think. Not all calls to privateData will return that same HASH reference. The HASH reference that is returned depends on the package it was called from, a different HASH is returned for each package. This allows a widget to hold private data, but then if it is sub-classed the sub-class will get a different HASH and so not cause duplicate name clashes.

    But privateData does take an optional argument if you want to force which HASH is returned.

  • Scrolled and Composite
    Scrolled(Kind,...) constructor can not be used with Composite. One has to use $cw->Composite(ScrlKind => 'name', ...);


MISSING

Of course perl/Tk does not define support function for all necessities. Here's a short list of things you have to handle yourself:

  • no support to define construction-time only options.

  • no support to remove an option that is known to the base widget.

  • it's hard to define undef as fallback for an widget option that is not already undef.

  • Frame in perl/Tk carries magic and overhead not needed for composite widget class definition.

  • No support methods for bindings that are shared between all widgets of a composite widget (makes sense at all?)


KEYWORDS

mega, composite, derived, widget


SEE ALSO

Tk::composite Tk::ConfigSpecs Tk::option Tk::callbacks Tk::bind

 Tk::mega - perl/Tk support to write widgets in perl