NAME

Tk::Role::Dialog - moose role for enhanced tk dialogs

VERSION

version 1.112380

SYNOPSIS

package Your::Tk::Dialog::Class;

use Moose;
with 'Tk::Role::Dialog';

sub _build_title     { 'window title' }
sub _build_icon      { '/path/to/some/icon.png' }
sub _build_header    { 'big dialog header' }
sub _build_resizable { 0 }
sub _build_ok        { 'frobnize' }     # call $self->_valid
sub _build_cancel    { 'close' }        # close the window

sub _build_gui {
    my ($self, $frame) = @_;
    # build the inner dialog widgets in the $frame
}
sub _valid {
    # called when user clicked the 'ok' button
    $self->close;
}


# in your main program
use Your::Tk::Dialog::Class;
# create & show a new dialog
Your::Tk::Dialog::Class->new( parent => $main_window );

DESCRIPTION

Tk::Role::Dialog is meant to be used as a Moose role to be composed for easy Tk dialogs creation.

It will create a new toplevel with a title, and possibly a header as well as some buttons.

One can create the middle part of the dialog by providing a _build_gui() method, that will receive a Tk::Frame where widgets are supposed to be placed.

The attributes (see below) can be either defined as defaults using the _build_attr() methods, or passed arguments to the constructor call. The only mandatory attribute is parent, but you'd better provide some other attributes if you want your dialog to be somehow usable! :-)

ATTRIBUTES

parent

The parent window of the dialog, required.

hidden

Whether the dialog should popup or stay hidden after creation. Default to false, which means the dialog is shown.

icon

The path to an image to be used as window icon. Default to empty string (meaning no customized window icon), but not required.

title

The dialog title, default to tk dialog.

A header (string) to display at the top of the window. Default to empty string, meaning no header.

image

The path to an image to be displayed alongside the dialog text. Not taken into account if text attribute is empty. Default to empty string, meaning no image.

text

Some text to be displayed, for simple information dialog boxes. Default to empty string, meaning dialog is to be filled by providing a _build_gui() method. Can be combined with an image attribute for enhanced appearance.

resizable

A boolean to control whether the dialog can be resized or not (default).

ok

A string to display as validation button label. Default to empty string, meaning no validation button. The validation action will call $self->_valid().

cancel

A string to display as cancellation button label. Default to empty string, meaning no cancellation button. The cancel action is to just close the dialog.

hide

A string to display as hiding button label. Default to empty string, meaning no hiding button. The hiding action is to just hide the dialog (think withdraw).

METHODS

close

$dialog->close;

Request to destroy the dialog.

SEE ALSO

You can look for information on this module at:

AUTHOR

Jerome Quelin

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Jerome Quelin.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.