Glib::ParamSpec->enum or boxed
- From: "Jeffrey Ratcliffe" <jeffrey ratcliffe gmail com>
- To: "gtk2-perl List" <gtk-perl-list gnome org>
- Subject: Glib::ParamSpec->enum or boxed
- Date: Wed, 23 Jan 2008 10:32:35 +0100
Below is some demo code for composite widget. At the moment, it used
Glib::ParamSpec->string for the property, but as only three values are
possible, enum or boxed I assume would be better - but I can't see how
to do it.
Any hints?
Thanks
Jeff
#!/usr/bin/perl
package Foo::PageRange;
use strict;
use warnings;
use Gtk2;
use Glib qw(TRUE FALSE); # To get TRUE and FALSE
use Glib::Object::Subclass
Gtk2::Frame::,
signals => {
changed => {},
},
properties => [
Glib::ParamSpec->string (
'range', # name
'Range', # nickname
'Either current, selected, or all', #blurb
'all', # default
[qw/readable writable/] #flags
),
]
;
sub INIT_INSTANCE {
my ($self, $range) = @_;
$range = 'all' if (!$range);
$self->{range} = $range;
my $frame = Gtk2::Frame->new;
$self->add ($frame);
my $vbox = Gtk2::VBox -> new;
# $vboxp -> set_border_width($border_width);
$frame -> add ($vbox);
#the first radio button has to set the group,
#which is undef for the first button
# All button
my $buttona = Gtk2::RadioButton -> new(undef, 'All');
$vbox -> pack_start($buttona, TRUE, TRUE, 0);
my @group = $buttona -> get_group;
# Current button
my $buttonc = Gtk2::RadioButton -> new(@group, 'Current');
$vbox -> pack_start($buttonc, TRUE, TRUE, 0);
# Selected button
my $buttons = Gtk2::RadioButton -> new(@group, 'Selected');
$vbox -> pack_start($buttons, TRUE, TRUE, 0);
# Set default
if ($self->{range} eq 'current') {
$buttonc -> set_active(TRUE);
}
elsif ($self->{range} eq 'selected') {
$buttons -> set_active(TRUE);
}
else {
$buttona -> set_active(TRUE);
}
$buttona -> signal_connect ('toggled' => sub {
$self->set_active('all') if ($buttona -> get_active);
});
$buttonc -> signal_connect ('toggled' => sub {
$self->set_active('current') if ($buttonc -> get_active);
});
$buttons -> signal_connect ('toggled' => sub {
$self->set_active('selected') if ($buttons -> get_active);
});
}
sub get_active {
my ($self) = @_;
return $self->get ('range');
}
sub set_active {
my ($self, $range) = @_;
$self->{range} = $range;
$self->signal_emit ('changed');
}
package main;
use strict;
use warnings;
use Glib qw(TRUE FALSE); # To get TRUE and FALSE
use Gtk2 -init;
my $window = Gtk2::Window->new;
$window->set_title ('Page Range');
$window->signal_connect (delete_event => sub { Gtk2->main_quit; TRUE });
my $vbox = Gtk2::VBox->new;
$window->add ($vbox);
my $pr = Foo::PageRange->new;
$vbox->pack_start ($pr, TRUE, TRUE, 0);
$pr->signal_connect (changed => sub {
warn $_[0]->get_active, "\n";
});
$window->show_all;
Gtk2->main;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]