Re: window->close/hide/kill/destroy?
- From: Dermot Musgrove <dermot glade perl connectfree co uk>
- To: "Bogdan M.Maryniuck" <mbm centras lt>, "gtk-perl-list gnome org" <gtk-perl-list gnome org>
- Subject: Re: window->close/hide/kill/destroy?
- Date: Fri, 02 Feb 2001 03:59:47 +0000
"Bogdan M.Maryniuck" wrote:
Hi, all.
Ok, i have one sub:
sub click_for_something {
my $win1=window2->new();
$win1->show;
}
It works ok. But HOW to close this window
from another sub? For example:
[...]
So the question is: perhaps my way to show the windows is WRONG at
least? Thank you.
Hi, as usual, there are at least three ways to approach this - I am
assuming that you are using Glade-Perl generated code.
1) If the handler is for a widget on the form that is to be closed:
sub click_for_anothersomething {
my ($class, $data, $object, $instance, $event) = @_;
# Do whatever you want
$class->TOPLEVEL->hide;
}
or for a quick and dirty 'quit' button - even simpler:
sub click_for_anothersomething { shift->get_toplevel->hide }
2) If the widget is on another form:
Store the constructed $win1 in a global (package level or app level).
This has the disadvantage that you can only have one instance of the
first form at any time. Then you can have:
sub click_for_anothersomething {
my ($class, $data, $object, $instance, $event) = @_;
my $me = __PACKAGE__."->on_scrolledwindow14_button_press_event";
my $form = $__PACKAGE__::all_forms->{$instance};
# Use the global $win1 in class 'Class'
$Class::win1->TOPLEVEL->hide;
}
3) The most flexible way that allows multiple instances and classes.
Pass a ref to the first form ($win1) using the FORM key of the second
form instance.
sub on_scrolledwindow14_button_press_event {
my ($class, $data, $object, $instance, $event) = @_;
my $me = __PACKAGE__."->on_scrolledwindow14_button_press_event";
my $form = $__PACKAGE__::all_forms->{$instance};
my $textbox = $form->{'text4'};
if ($event->{'button'} == 3) {
$html_right_menu ||= new html_right_menu;
$html_right_menu->FORM->{'__FROMFORM'} = $form;
$html_right_menu->TOPLEVEL->popup(undef, undef, 0, 0);
return 0;
} else {
$textbox->set_point($textbox->get_position);
}
} # End of sub on_scrolledwindow14_button_press_event
This passes to the right-click menu a ref to the form that we are on
so that the menu's handlers can update/hide/destroy us.
So in the menu's class 'html_right_menu':
sub on_bold_activate {
my ($class, $data, $object, $instance, $event) = @_;
my $me = __PACKAGE__."->on_bold_activate";
# Get ref to hash of all widgets on our form
my $form = $__PACKAGE__::all_forms->{$instance};
$form->{'__FROMFORM'}{'text4'}->insert(
undef, undef, undef, "<B></B>");
} # End of sub on_bold_activate
Or to hide the form:
$form->{'__FROMFORM'}{'text4'}->get_toplevel->hide;
Just make sure that you choose a key (eg {'__FROMFORM'}) that is __not__
a widget name.
I hope that I have understood your question correctly and this helps.
Regards, Dermot
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]