| Padre documentation | Contained in the Padre distribution. |
Padre::Wx::Role::Dialog - Allow dialogs or frames to host simple common dialogs
package MyDialog;
use Padre::Wx ();
use Padre::Wx::Role::Dialog ();
@ISA = qw{
Padre::Wx::Role::Dialog
Wx::Dialog
};
# ...
sub foo {
my $self = shift;
# Say something
$self->message("Hello World!");
return 1;
}
In a large Wx application with multiple dialogs or windows, many different parts of the application may want to post messages or prompt the user.
The Padre::Wx::Role::Dialog role allows dialog or window classes to
"host" these messages.
Providing these as a role means that each part of your application can post messages and have the positioning of the dialogs be made appropriate for each dialog.
message$parent->message( $text, $title );
Open a dialog box with $text as the main text and $title (title
defaults to Message). There's only one OK button. No return value.
error$parent->error( $text );
Open an error dialog box with $text as main text. There's only one OK
button. No return value.
passwordmy $password = $parent->password( $message, $title );
Generate a standard Wx password dialog, using the internal Wx::PasswordEntryDialog class.
yes_no my $boolean = $parent->yes_no(
$message,
$title,
);
Generates a standard Wx Yes/No dialog.
single_choice my $choice = $parent->single_choice(
$message,
$title,
[
'Option One',
'Option Two',
'Option Three',
],
);
Generates a standard Wx single-choice dialog, using the standard internal Wx::SingleChoiceDialog class.
Returns the selected string, or undef if the user selects Cancel.
multi_choice my @choices = $parent->multi_choice(
$message,
$title,
[
'Option One',
'Option Two',
'Option Three',
],
);
Generates a standard Wx multi-choice dialog, using the internal Wx::MultiChoiceDialog class.
| Padre documentation | Contained in the Padre distribution. |
package Padre::Wx::Role::Dialog;
use 5.008005; use strict; use warnings; use Padre::Wx (); our $VERSION = '0.86';
sub message { my $self = shift; my $message = shift; my $title = shift || Wx::gettext('Message'); Wx::MessageBox( $message, $title, Wx::wxOK | Wx::wxCENTRE, $self, ); return; }
sub error { my $self = shift; my $message = shift || Wx::gettext('Unknown error from ') . caller; Wx::MessageBox( $message, Wx::gettext('Error'), Wx::wxOK | Wx::wxCENTRE | Wx::wxICON_HAND, $self, ); return; }
sub password { my $self = shift; my $dialog = Wx::PasswordEntryDialog->new( $self, @_ ); my $result = undef; $dialog->CenterOnParent; unless ( $dialog->ShowModal == Wx::wxID_CANCEL ) { $result = $dialog->GetValue; } $dialog->Destroy; return $result; }
sub yes_no { my $self = shift; my $message = shift; my $title = shift || Wx::gettext('Message'); my $dialog = Wx::MessageDialog->new( $self, $message, $title, Wx::wxYES_NO | Wx::wxYES_DEFAULT | Wx::wxICON_QUESTION, ); $dialog->CenterOnParent; my $result = ( $dialog->ShowModal == Wx::wxID_YES ) ? 1 : 0; $dialog->Destroy; return $result; }
sub single_choice { my $self = shift; my $dialog = Wx::SingleChoiceDialog->new( $self, @_ ); my $result = undef; $dialog->CenterOnParent; unless ( $dialog->ShowModal == Wx::wxID_CANCEL ) { $result = $_[2]->[ $dialog->GetSelection ]; } $dialog->Destroy; return $result; }
sub multi_choice { my $self = shift; my $dialog = Wx::MultiChoiceDialog->new( $self, @_ ); my @result = (); $dialog->CenterOnParent; unless ( $dialog->ShowModal == Wx::wxID_CANCEL ) { @result = map { $_[2]->[$_] } $dialog->GetSelections; } $dialog->Destroy; return @result; } 1; # Copyright 2008-2011 The Padre development team as listed in Padre.pm. # LICENSE # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl 5 itself.