Gtk2-Ex-ComboBox

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/ComboBox.pm  view on Meta::CPAN

sub new {
	my ($class, $parent, $type) = @_;
	my $self  = {};
	bless ($self, $class);
	my $slist = Gtk2::Ex::Simple::List->new (
		'flag'		=> 'bool',
		''			=> 'text',
	);
	$self->{slist} = $slist;
	$self->{type} = $type;	
	my $popup = Gtk2::Ex::PopupWindow->new($parent);
	$self->{popup} = $popup;
	$self->{signals} = undef;
	my $frame = Gtk2::Frame->new;
	$type = 'with-buttons' unless $type;
	unless ($type eq 'with-buttons' or $type eq 'with-checkbox' or $type eq 'no-checkbox') {
		carp "Error: Expecting 'with-buttons' or 'with-checkbox'. Got $type\n";
		$type = 'with-buttons'; #default
	}
	if ($type eq 'with-buttons') {
		my $vbox = $self->_make_selectable;
		$frame->add($vbox);

lib/Gtk2/Ex/ComboBox.pm  view on Meta::CPAN

				my @sel = $slist->get_selected_indices;
				foreach my $line (@{$slist->{data}}) {
					$line->[0] = FALSE;
				}
				foreach my $x (@sel) {
					$slist->{data}->[$x]->[0] = TRUE;
				}
			}
		);
	}
	$popup->{window}->add($frame);
	$popup->{window}->set_default_size(200, 200);
	return $self;
}

sub signal_connect {
	my ($self, $signal, $callback) = @_;
	$self->{signals}->{$signal} = $callback;
	my $slist = $self->{slist};
	my $type = $self->{type};
	if ( $type eq 'with-buttons' or $type eq 'with-checkbox') {
		$slist->get_model()->signal_connect ('row-changed' =>

lib/Gtk2/Ex/ComboBox.pm  view on Meta::CPAN

	my @temp;
	foreach my $x (@$list) {
		push @temp, [0, $x];
	}
	$self->set_list_preselected(\@temp);
	return 0;
}

sub show {
	my ($self) = @_;
	$self->{popup}->show;
}

sub hide {
	my ($self) = @_;
	$self->{popup}->hide;
}

sub _make_selectable {
	my ($self) = @_;
	my $slist = $self->{slist};
	$slist->set_headers_visible(FALSE);
	my $label = Gtk2::Label->new('Select');
	my $allbutton = Gtk2::Button->new_from_stock('Select All');
	my $nonebutton = Gtk2::Button->new_from_stock('Select None');
	my $okbutton = Gtk2::Button->new_from_stock('gtk-ok');

lib/Gtk2/Ex/ComboBox.pm  view on Meta::CPAN

	);
	$nonebutton->signal_connect ('button-release-event' => 
		sub {
			foreach my $line (@{$slist->{data}}) {
				$line->[0] = FALSE;
			}
		}
	);
	$okbutton->signal_connect ('button-release-event' => 
		sub {
			$self->{popup}->hide;
		}
	);
	
	my $scrolledwindow = Gtk2::ScrolledWindow->new;
	$scrolledwindow->set_policy('automatic', 'automatic');
	$scrolledwindow->add($slist);
	my $hbox = Gtk2::HBox->new (TRUE, 0);
	$hbox->pack_start ($allbutton, FALSE, TRUE, 0);    
	$hbox->pack_start ($nonebutton, FALSE, TRUE, 0);    
	my $vbox = Gtk2::VBox->new (FALSE, 0);



( run in 1.255 second using v1.01-cache-2.11-cpan-364913b4093 )