Re: Gtk2::SpinButton with blank value
- From: muppet <scott asofyet org>
- To: Jeffrey Ratcliffe <jeffrey ratcliffe gmail com>
- Cc: "gtk-perl-list gnome org List" <gtk-perl-list gnome org>
- Subject: Re: Gtk2::SpinButton with blank value
- Date: Thu, 13 Nov 2008 22:43:44 -0500
On Nov 13, 2008, at 4:15 PM, Jeffrey Ratcliffe wrote:
Still with me?
Looks like Tadej's suggestion of the output signal may pay off.
#!/usr/bin/perl -w
package BlankableSpinButton;
use strict;
use Gtk2;
use Glib::Object::Subclass
Gtk2::SpinButton::,
signals => {
output => \&_do_output,
},
;
sub latch_blank {
my ($spin) = @_;
$spin->{latch_blank} = 1;
$spin->update ();
}
sub unlatch_blank {
my ($spin) = @_;
$spin->{latch_blank} = 0;
$spin->update ();
}
sub _do_output {
my ($self) = @_;
print "_do_output @_\n";
if ($self->{latch_blank}) {
$self->set_text ('');
$self->queue_draw ();
return 1;
} else {
return $self->signal_chain_from_overridden ();
}
}
package main;
use warnings;
use strict;
use Gtk2 -init;
use Glib qw(TRUE FALSE);
use Gtk2::SimpleList;
my $slist = Gtk2::SimpleList->new ('Value' => 'int');
@{ $slist->{data} } = ( 1..10 );
$slist->get_selection ()->set_mode ('multiple');
my $window = Gtk2::Window->new ();
$window->signal_connect (destroy => sub { Gtk2->main_quit () });
my $vbox = Gtk2::VBox->new ();
$window->add ($vbox);
my $adj = Gtk2::Adjustment->new (0, 0, 9999, 1, 10, 1000);
my $spinbutton = BlankableSpinButton -> new (adjustment => $adj);
$spinbutton->set_numeric (FALSE);
$spinbutton->set_text ('');
$vbox->add ($spinbutton);
$vbox->add ($slist);
$window->show_all ();
$slist->get_selection ()->signal_connect (changed => sub {
my @indices = $slist->get_selected_indices ();
if (@indices == 0) {
$spinbutton->latch_blank ();
$spinbutton->set_sensitive (FALSE);
} elsif (@indices == 1) {
$spinbutton->unlatch_blank ();
$spinbutton->set_sensitive (TRUE);
$spinbutton->set_value ($slist->{data}[$indices[0]][0]);
} else {
$spinbutton->set_sensitive (TRUE);
$spinbutton->latch_blank ();
}
});
$slist->get_selection ()->unselect_all ();
Gtk2->main;
__END__
--
Sallah! I said no camels! That's five camels! Can't you count?
-- Indiana Jones
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]