On 01/15/13 13:34, Johan Vromans wrote:
Dave Hayes <d...@jetcafe.org> writes:
On 01/15/13 05:18, Johan Vromans wrote:
The Close button of the Help window does not get triggered since the
(other) dialog is modal and stays in control.
So am I to assume that "Modal" means that the entire application is
frozen until the dialog box exits?
That's pretty much the idea behind 'Modal'...
http://en.wikipedia.org/wiki/Modal_dialog
Hm. Thanks for that. I didn't know how defined the idea of 'Modal' was.
Ok...so I had a different idea. I made the help window so it will show
and hide on clicking the button repeatedly. But now...well see the
attached example.
Click the help button repeatedly. The 2nd time you Show() this window,
it goes right over the dialog box. The 1st and Nth times (where N != 2)
it goes where I told it to. What did I do wrong here?
Is there a way to manage a different "tree" of windows that does not
go "modal" when you instantiate a dialog box?
Was Steve's reply useful to you?
Sort of. I'm not trying to use microsoft help file format, and as far as
I can tell his method is only useful when you are doing so. Thus I've
pushed this idea to my stack.
Also I need to be somewhat careful for you folks are at wxWidgets 2.9.*
and I am still using 2.8.12.
I did learn there is an HTML widget, which might be more useful than a
TextCtrl to provide help windows. ;)
--
Dave Hayes - Consultant - Altadena CA, USA - d...@jetcafe.org
>>>> *The opinions expressed above are entirely my own* <<<<
Well, if crime fighters fight crime and fire fighters fight
fire, what do freedom fighters fight? They never mention
that part to us, do they? -George Carlin
#!/usr/local/bin/perl
package MyHelpWindow;
use Wx qw(:everything);
use base qw(Wx::Dialog);
use Wx::Event qw(EVT_BUTTON);
sub new {
my $class = shift;
my $parent = shift;
my $self = $class->SUPER::new(
$parent, -1, "MyHelp",
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxSTAY_ON_TOP
);
my $textwin = Wx::TextCtrl->new(
$self, -1,
"
**************************************
Ostensibly, this is a lot of help text
**************************************
",
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxTE_DONTWRAP|wxTE_AUTO_URL,
);
my $dialogContainer = Wx::BoxSizer->new(wxVERTICAL);
$dialogContainer->Add($textwin, 5, wxEXPAND | wxALL, 4);
my $bottom = Wx::Button->new($self, wxID_CLOSE, "Close");
$dialogContainer->Add($bottom, 1, wxALIGN_CENTER_HORIZONTAL | wxEXPAND |
wxALL, 2);
$bottom->{'dialog'} = $self;
EVT_BUTTON($bottom, $bottom,
sub {
my ($button, $event) = @_;
$button->{'dialog'}->Close();
});
$self->SetSizer($dialogContainer);
$dialogContainer->Fit($self);
$dialogContainer->SetSizeHints($self);
return $self;
}
package MyDialog;
use Wx qw(:everything);
use base qw(Wx::Dialog);
use Wx::Event qw(EVT_BUTTON);
sub new {
my $class = shift;
my $dialogParent = shift;
my $helpParent = shift;
my $self = $class->SUPER::new(
$dialogParent, -1, "MyDialog",
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxSTAY_ON_TOP
);
$helpParent = $self if (defined($helpParent) && !ref($helpParent));
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
my $control = Wx::StaticText->new(
$self, -1, "Hello World!",
wxDefaultPosition, [ 100, 100 ],
);
$sizer->Add($control, 0, wxEXPAND | wxALL, 4);
my $buttonSizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($buttonSizer, 0, wxEXPAND | wxALL, 4);
my $button1 = Wx::Button->new($self, wxID_OK, "OK");
$buttonSizer->Add($button1, 0, wxALL, 4);
my $button2 = Wx::Button->new($self, wxID_CANCEL, "Cancel");
$buttonSizer->Add($button2, 0, wxALL, 4);
my $button3 = Wx::Button->new($self, wxID_HELP, "HELP");
$buttonSizer->Add($button3, 0, wxALL, 4);
$button3->{'parent'} = $helpParent;
EVT_BUTTON($button3, $button3,
sub {
my ($button, $event) = @_;
my $parent = $button->{'parent'};
my ($px, $py) = $parent->GetPositionXY();
my ($pw, $ph) = $parent->GetSizeWH();
my $hx = $px + $pw + 10;
my $hy = $py;
my $help = $button->{'helpwin'};
unless (defined($help)) {
$help = $button->{'helpwin'} = MyHelpWindow->new($helpParent);
$button->{'helpon'} = 0;
}
$help->Move($hx, $hy);
if ($button->{'helpon'} ) {
$button->{'helpon'} = 0;
$help->Hide();
} else {
$button->{'helpon'} = 1;
$help->Show(1);
$help->Raise();
}
});
$self->SetSizer($sizer);
$sizer->Fit($self);
$sizer->SetSizeHints($self);
return $self;
}
package MyApp;
use base qw(Wx::App);
use Wx qw(:everything);
use Wx::Event qw(EVT_BUTTON);
sub new {
my $self = shift;
$self = $self->SUPER::new();
return $self;
}
sub OnInit {
my( $self ) = @_;
Wx::InitAllImageHandlers();
my $topframe = $self->{'topframe'} =
Wx::Frame->new( undef, -1, "MyApp", wxDefaultPosition, wxDefaultSize);
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
if (0) { # dont enable these unless you want the help button to kill the app ;)
my $button = Wx::Button->new( $topframe, -1, "HelpParentTopFrame" );
$button->{'topframe'} = $topframe;
$sizer->Add($button, 1, wxALL, 2);
EVT_BUTTON($topframe, $button,
sub {
my ($button, $event) = @_;
my $dialog = MyDialog->new( $button->{'topframe'},
$button->{'topframe'} );
$dialog->ShowModal();
});
my $button2 = Wx::Button->new( $topframe, -1, "HelpParentUndef" );
$button2->{'topframe'} = $topframe;
$sizer->Add($button2, 1, wxALL, 2);
EVT_BUTTON($topframe, $button2,
sub {
my ($button, $event) = @_;
my $dialog = MyDialog->new( $button->{'topframe'}, undef );
$dialog->ShowModal();
});
}
my $button3 = Wx::Button->new( $topframe, -1, "HelpParentDialog" );
$button3->{'topframe'} = $topframe;
$sizer->Add($button3, 1, wxALL, 2);
EVT_BUTTON($topframe, $button3,
sub {
my ($button, $event) = @_;
my $dialog = MyDialog->new( $button->{'topframe'}, "this uses
dialog as parent");
$dialog->ShowModal();
});
$topframe->SetSizer($sizer);
$sizer->Fit($topframe);
$sizer->SetSizeHints($topframe);
$self->SetTopWindow($topframe);
$topframe->Show(1);
return 1;
}
package main;
my $app = MyApp->new();
$app->MainLoop();
die "Exiting main loop\n";