Glib-Ex-ConnectProperties
view release on metacpan or search on metacpan
devel/run.pl view on Meta::CPAN
#!/usr/bin/perl -w
# Copyright 2007, 2008, 2009, 2010 Kevin Ryde
# This file is part of Glib-Ex-ConnectProperties.
#
# Glib-Ex-ConnectProperties is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your option) any
# later version.
#
# Glib-Ex-ConnectProperties is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>.
use 5.008;
use strict;
use warnings;
use Glib::Ex::ConnectProperties;
use Gtk2 '-init';
use FindBin;
my $progname = $FindBin::Script;
my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });
my $vbox = Gtk2::VBox->new (0,0);
$toplevel->add ($vbox);
my $label = Gtk2::Label->new ('Hello');
$vbox->add ($label);
my $label2 = Gtk2::Label->new ('');
$vbox->add ($label2);
my $sensitive_button = Gtk2::CheckButton->new_with_label ('Sensitive');
$vbox->add ($sensitive_button);
$sensitive_button->signal_connect
('notify::active' => sub {
print "$progname: press_button active now ",
$sensitive_button->get('active'),"\n"; });
my $conn = Glib::Ex::ConnectProperties->new ([$label,'sensitive'],
[$sensitive_button,'active'],
[$label2,'label']);
require Data::Dumper;
print Data::Dumper->new([$conn],['conn'])->Sortkeys(1)->Dump;
require Scalar::Util;
Scalar::Util::weaken ($conn);
{
my $button = Gtk2::CheckButton->new_with_label ('Another Sensitive');
$vbox->add ($button);
Glib::Ex::ConnectProperties->new ([$label,'sensitive'],
[$button,'active']);
}
if (1) {
my $disp = Gtk2::Label->new ('Unset');
$vbox->add ($disp);
Glib::Ex::ConnectProperties->new ([$label,'sensitive'],
[$disp, 'label',
map_in => { 1 => 'Sens',
0 => 'Not Sens' }]);
}
{
my $button = Gtk2::Button->new_with_label ('Disconnect');
$vbox->add ($button);
$button->signal_connect (clicked => sub { $conn->disconnect });
}
{
my $button = Gtk2::Button->new_with_label ('Freeze');
$vbox->add ($button);
$button->signal_connect (clicked => sub {
print "$progname: freeze\n";
$sensitive_button->freeze_notify;
});
}
{
my $button = Gtk2::Button->new_with_label ('Thaw');
$vbox->add ($button);
$button->signal_connect (clicked => sub {
print "$progname: thaw\n";
$sensitive_button->thaw_notify;
});
}
{
my $label3 = Gtk2::Label->new;
$vbox->add ($label3);
sub my_Xtransform {
my ($value, $object, $propertyname) = @_;
return "the name is $value";
}
Glib::Ex::ConnectProperties->new
([$toplevel, 'name', map_out => \&my_Xtransform ],
[$label3, 'label']);
}
{
my $spin1 = Gtk2::SpinButton->new_with_range (0, 100, 1);
my $spin2 = Gtk2::SpinButton->new_with_range (10, 210, 1);
$vbox->add ($spin1);
$vbox->add ($spin2);
sub my_transform {
( run in 1.646 second using v1.01-cache-2.11-cpan-364913b4093 )