Gtk2-Ex-NumberRange

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

META.yml # Will be created by "make dist"
Makefile.PL
README
lib/Gtk2/Ex/NumberRange.pm
t/00.load.t
t/pod-coverage.t
t/pod.t
t/show-range.t
t/show-range-visible.t
examples/number-range.pl
examples/number-range-popup.pl

examples/number-range-popup.pl  view on Meta::CPAN

$numberrange->signal_connect('changed' =>
	sub {
		print Dumper my $model = $numberrange->get_model;
		my $sql_condition = $numberrange->to_sql_condition('mynumber', $model);
		print "$sql_condition\n" if $sql_condition;
	}
);

my $label = Gtk2::Label->new('Click-Here');
my $labelbox = _add_button_press($label);
my $popup = $numberrange->attach_popup_to($label);
$labelbox->signal_connect('button-press-event' => 
	sub {
		$popup->show;
		return TRUE; # Very Important...
		             # If you don't return true, then the popup will get closed
	}
);
my $window = Gtk2::Window->new;
$window->signal_connect('destroy' => sub { Gtk2->main_quit });
my $hbox = Gtk2::HBox->new (FALSE);
$hbox->pack_start (Gtk2::Label->new, TRUE, TRUE, 0); 
$hbox->pack_start ($labelbox, TRUE, TRUE, 0); 
$hbox->pack_start (Gtk2::Label->new('Outside Label'), TRUE, TRUE, 0); 

my $vbox = Gtk2::VBox->new (FALSE);

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

	$self->{entry1}->set_sensitive(FALSE);
	$self->{joinercombo}->set_active(0);
	$self->{joinercombo}->set_sensitive(FALSE);
	$self->{commandcombo2}->set_active(-1);
	$self->{entry2}->set_text('');
	$self->{model} = undef;
	$self->{freezesignals} = FALSE;
	&{ $self->{signals}->{'changed'} } if $self->{signals}->{'changed'};
}

sub attach_popup_to {
	my ($self, $parent) = @_;
	my $popupwindow = Gtk2::Ex::PopupWindow->new($parent);
	$popupwindow->set_move_with_parent(TRUE);
	my $okbutton = Gtk2::Button->new_from_stock('gtk-ok');
	$okbutton->signal_connect ('button-release-event' => 
		sub {
			$popupwindow->hide;
		}
	);
	my $clearbutton = Gtk2::Button->new_from_stock('gtk-clear');
	$clearbutton->signal_connect ('button-release-event' => 
		sub {
			$self->_clear;
		}
	);
	my $hbox = Gtk2::HBox->new(TRUE, 0);
	$hbox->pack_start ($clearbutton, TRUE, TRUE, 0); 	
	$hbox->pack_start ($okbutton, TRUE, TRUE, 0); 	
	my $vbox = Gtk2::VBox->new (FALSE, 0);
	$vbox->pack_start ($self->{widget}, TRUE, TRUE, 0);
	$vbox->pack_start ($hbox, FALSE, FALSE, 0); 	
	my $frame = Gtk2::Frame->new;
	$frame->add($vbox);
	$popupwindow->{window}->add($frame);
	return $popupwindow;	
}

sub signal_connect {
	my ($self, $signal, $callback) = @_;
	$self->{signals}->{$signal} = $callback;
}

sub _model_error_check {
	my ($commandhash, $joinerhash, $model) = @_;
	return warn "Model should contain 2 or 5 parameters" 

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

	$numberrange->set_model(['>', 10, 'and', '<=', 20]);

Will also accept a list with 2 parameters.

	$numberrange->set_model(['>', 10]);

=head2 get_model;

Returns the model.

=head2 attach_popup_to($parent);

This method returns a C<Gtk2::Ex::PopupWindow>. The popup window will contain
a C<Gtk2::Ex::NumberRange> widget and two buttons.

=head2 to_sql_condition($numberfieldname, $model);

Converts the C<$model> into an SQL condition so that it can be used directly in
and SQL statement. C<$numberfieldname> is the fieldname that will be used inside
the SQL condition.

=head2 signal_connect($signal, $callback);

t/show-range-visible.t  view on Meta::CPAN

use Gtk2::TestHelper tests => 2;

my $numberrange = Gtk2::Ex::NumberRange->new;
$numberrange->set_model(['>', 10, 'and', '<=', 20]);

my $outsidelabel = Gtk2::Label->new('Outside Label');
my $outsidelabelbox = _add_button_press($outsidelabel);

my $label = Gtk2::Label->new('Click-Here');
my $labelbox = _add_button_press($label);
my $popup = $numberrange->attach_popup_to($label);
$labelbox->signal_connect('button-press-event' => 
	sub {
		$popup->show;
		return TRUE; # Very Important...
		             # If you don't return true, then the popup will get closed
	}
);
my $window = Gtk2::Window->new;
$window->signal_connect('destroy' => sub { Gtk2->main_quit });
my $hbox = Gtk2::HBox->new (FALSE);
$hbox->pack_start (Gtk2::Label->new, TRUE, TRUE, 0); 
$hbox->pack_start ($labelbox, TRUE, TRUE, 0); 
$hbox->pack_start (Gtk2::Label->new, TRUE, TRUE, 0); 

my $vbox = Gtk2::VBox->new (FALSE);



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