On 01/15/13 02:36, Johan Vromans wrote:
Dave Hayes <d...@jetcafe.org> writes
So I've successfully remapped ENTER by adding the wxTE_PROCESS_ENTER
flag to my Wx::TextCtrl, and used the EVT_TEXT_ENTER
macro to create an event. So far so good. I can even call $event->Skip
to tell other event handlers to process this key if I want.
However, I can't seem to detect modifiers with this method since the
passed in event is a wxCommandEvent not a wxKeyEvent. I'd need the
GetModifiers() method to work, and it doesn't on wxCommandEvents.
How can I detect whether shift is being held down in this particular case?
You may need to use EVT_CHAR on the TextCtrl from where you can inspect
anything.
That makes sense in a direct sort of way.
2) I have added a help button to my dialogs. I'd like a separate help
window to pop up with a close button, which is independent of the
actual dialog window it's attached to.
I'm real unclear as to how to do this.
If I make the new help window a child of the dialog, and call Show()
on it, the close button does not work. If I call ShowModal() then the
help window blocks any action in the dialog.
So if I then make the new help window childless (undef as the parent,
as I understand) it seems to work in reverse. The close button in the
dialog will not work until I close the dialog.
This is puzzling... Do you have example code that shows this behaviour?
Sort of. Code is attached. At the moment, the exact behavior I described
is not working in the test application. I've replicated my architecture
in this code snippet, and I seem to be seeing the same behavior
regardless of the parent window that the help window is created with.
The close button does not work until the original
dialog is closed.
Maybe this will give you insight into what I am missing? I hope so.
--
Dave Hayes - Consultant - Altadena CA, USA - d...@jetcafe.org
>>>> *The opinions expressed above are entirely my own* <<<<
Penitent (adj.) - 1. Someone who has been made incapable of enjoyment.
#!/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);
EVT_BUTTON($button3, $button3,
sub {
my ($button, $event) = @_;
my $help = MyHelpWindow->new($helpParent);
$help->Show(1);
});
$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);
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";