Gtk2-Ex-WidgetBits
view release on metacpan or search on metacpan
lib/Gtk2/Ex/FreezeChildNotify.pm view on Meta::CPAN
in a C<child_set_property>, or while calculating a value. (Though as of
Glib-Perl 1.222 an invalid argument type to C<child_set_property> generally
only provokes warnings.)
=head2 Operation
FreezeChildNotify works by having C<thaw_child_notify> in the destroy code
of the FreezeChildNotify object.
FreezeChildNotify only holds weak references to its widgets, so the mere
fact they're due for later thawing doesn't keep them alive if nothing else
cares whether they live or die. The effect is that frozen widgets can be
garbage collected within a freeze block at the same point they would be
without any freezing, instead of extending their life to the end of the
block.
It works to have multiple freeze/thaws, done either with FreezeChildNotify
or with explicit C<freeze_child_notify> calls. C<Gtk2::Widget> simply
counts outstanding freezes, which means they don't have to nest, so multiple
freezes can overlap in any fashion. If you're freezing for an extended time
then a FreezeChildNotify object is a good way not to lose track of the
lib/Gtk2/Ex/Statusbar/DynamicContext.pm view on Meta::CPAN
long-running program because a context string and its ID in a Statusbar are
permanent additions to the memory of that widget and to the global quark
table. That means a simple approach like sequentially numbered context
strings is not enough, it would consume ever more memory. With
DynamicContext style re-use the space is capped at the peak number of
contexts used at any one time.
=head2 Weakening
DynamicContext only holds a weak reference to its C<$statusbar>, so the mere
fact a message context exists doesn't keep the Statusbar alive.
=head1 FUNCTIONS
=over 4
=item C<< $dc = Gtk2::Ex::Statusbar::DynamicContext->new ($statusbar) >>
Create and return a new DynamicContext object for C<$statusbar> (a
C<Gtk2::Statusbar> widget).
lib/Gtk2/Ex/Statusbar/MessageUntilKey.pm view on Meta::CPAN
=item C<< Gtk2::Ex::Statusbar::MessageUntilKey->message ($statusbar, $message) >>
Push string C<$message> onto C<$statusbar> (a C<Gtk2::Statusbar>), and setup
to remove it on the next key press or button press.
If another MessageUntilKey is already displayed in C<$statusbar> then it's
replaced by the new C<$message>. The new message goes on the top of the
statusbar stack, even if the old one had been buried under other things.
The MessageUntilKey setups only keep a weak reference to C<$statusbar>, so
the mere fact there's a message displayed doesn't keep it alive.
=item C<< Gtk2::Ex::Statusbar::MessageUntilKey->remove ($statusbar) >>
Remove any MessageUntilKey message displayed in C<$statusbar>. This is
what's done on the next key or button press but you can use this sooner for
explicit removal. If C<$statusbar> has no MessageUntilKey then C<remove()>
does nothing.
=back
lib/Gtk2/Ex/ToolItem/OverflowToDialog/Dialog.pm view on Meta::CPAN
# numbers, not enum strings like 'accept'
$self->signal_connect (response => \&_do_response);
}
sub _do_destroy {
my ($self) = @_;
### OverflowToDialog _do_destroy()
if (my $toolitem = $self->{'toolitem'}) {
# toolitem to create a new dialog next time required, even if someone
# else is keeping the destroyed $self alive for a while
delete $toolitem->{'dialog'};
# put the child_widget back into the toolitem, or if toolitem maybe gone
# then let the child destroy with the dialog
Gtk2::Ex::ToolItem::OverflowToDialog::_update_child_position ($toolitem);
}
$self->signal_chain_from_overridden;
}
sub SET_PROPERTY {
t/FreezeChildNotify.t view on Meta::CPAN
my $label = Gtk2::Label->new;
$vbox->add($label);
my $notified = 0;
$label->signal_connect (child_notify => sub { $notified = 1; });
{
my $freezer = Gtk2::Ex::FreezeChildNotify->new ($label);
ok (! $notified);
$vbox->child_set_property ($label, padding => 1);
$vbox->child_set_property ($label, fill => 1);
ok (! $notified, 'freezer alive, no notify yet');
}
ok ($notified, 'notify goes out after freezer dies');
}
# notify goes out on two widgets when $freezer dies
{
my $vbox = Gtk2::VBox->new;
my $label1 = Gtk2::Label->new;
my $label2 = Gtk2::Label->new;
$vbox->add($label1);
$vbox->add($label2);
my $notified1 = 0;
my $notified2 = 0;
$label1->signal_connect (child_notify => sub { $notified1 = 1; });
$label2->signal_connect (child_notify => sub { $notified2 = 1; });
{
my $freezer = Gtk2::Ex::FreezeChildNotify->new ($label1, $label2);
$vbox->child_set_property ($label1, padding => 10);
$vbox->child_set_property ($label2, padding => 20);
ok (! $notified1, 'freezer alive, no notify label1 yet');
ok (! $notified2, 'freezer alive, no notify label2 yet');
}
ok ($notified1, 'notify label1 goes out after freezer dies');
ok ($notified2, 'notify label2 goes out after freezer dies');
}
{
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new;
$vbox->add($label);
my $notified = 0;
t/FreezeChildNotify.t view on Meta::CPAN
};
eval {
my $freezer = Gtk2::Ex::FreezeChildNotify->new ($label);
$vbox->child_set_property ($label, padding => 1);
ok (! $notified, "notify hasn't gone before the die");
die "an error";
};
ok ($notified, 'notify has gone out after the die');
is ($die_notified, 0,
'SIG{__DIE__} runs inside the eval, so the freezer object is still alive and not yet done its thaw');
}
{
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new;
$vbox->add($label);
my $freezer = Gtk2::Ex::FreezeChildNotify->new ($label);
Scalar::Util::weaken ($label);
$vbox->remove($label);
ok (! defined $label, "doesn't keep a hard reference to its widget");
( run in 1.659 second using v1.01-cache-2.11-cpan-39bf76dae61 )