Gtk2-Ex-DateRange
view release on metacpan or search on metacpan
Revision history for Gtk2-Ex-DateRange
0.01 Sep 29, 2005
First version, released on an unsuspecting world.
0.02 Sep 29, 2005
Fixed issue with clear button in popup
Added a few real tests
0.03 Sep 29, 2005
Fixed the examples.
Bug fix - joinercombo should be insensitive on clear
0.04 Sep 29, 2005
Bug fixes. More tests
0.05 Sep 29, 2005
Changes
MANIFEST
META.yml # Will be created by "make dist"
Makefile.PL
README
lib/Gtk2/Ex/DateRange.pm
t/00.load.t
t/pod-coverage.t
t/pod.t
t/show-range.t
t/show-range-popup.t
examples/show-range.pl
examples/show-range-popup.pl
examples/show-range-with-model-1.pl
examples/show-range-with-model-2.pl
examples/show-range-popup.pl view on Meta::CPAN
my $daterange = Gtk2::Ex::DateRange->new;
$daterange->set_model([ 'after', '1965-03-12', 'and', 'before', '1989-02-14' ]);
$daterange->signal_connect('changed' =>
sub {
print Dumper $daterange->get_model;
}
);
my $label = Gtk2::Label->new('Click-Here');
my $labelbox = _add_button_press($label);
my $popup = $daterange->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);
lib/Gtk2/Ex/DateRange.pm view on Meta::CPAN
$self->{datelabelbox1}->set_sensitive(FALSE);
$self->{joinercombo}->set_active(0);
$self->{joinercombo}->set_sensitive(FALSE);
$self->{commandcombo2}->set_active(-1);
$self->{datelabel2}->set_label('(select a date)');
$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);
$self->{popup} = $popupwindow;
$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/DateRange.pm view on Meta::CPAN
sub _get_widget {
my ($self) = @_;
my $commandchoices = ['before', 'after', 'on or after', 'on or before'];
my $joinerchoices = ['', 'and', 'or'];
my $commandcombo1 = Gtk2::ComboBox->new_text;
my $datelabel1 = Gtk2::Label->new('(select a date)');
my $calendar1 = Gtk2::Calendar->new;
my $datelabelbox1 = $self->_calendar_popup($datelabel1, $calendar1, 1);
foreach my $x (@$commandchoices) {
$commandcombo1->append_text($x);
}
$commandcombo1->signal_connect ( 'changed' =>
sub {
$self->{model}->[0] = $commandchoices->[$commandcombo1->get_active()]
unless $commandcombo1->get_active() < 0;
$self->{datelabelbox1}->set_sensitive(TRUE);
&{ $self->{signals}->{'changed'} }
if $self->{signals}->{'changed'} and !$self->{freezesignals};
}
);
my $commandcombo2 = Gtk2::ComboBox->new_text;
my $datelabel2 = Gtk2::Label->new('(select a date)');
my $calendar2 = Gtk2::Calendar->new;
my $datelabelbox2 = $self->_calendar_popup($datelabel2, $calendar2, 4);
foreach my $x (@$commandchoices) {
$commandcombo2->append_text($x);
}
$commandcombo2->signal_connect ( 'changed' =>
sub {
$self->{model}->[3] = $commandchoices->[$commandcombo2->get_active()]
unless $commandcombo2->get_active() < 0;
$self->{datelabelbox2}->set_sensitive(TRUE);
&{ $self->{signals}->{'changed'} }
if $self->{signals}->{'changed'} and !$self->{freezesignals};
lib/Gtk2/Ex/DateRange.pm view on Meta::CPAN
}
sub _update_date_label {
my ($calendar, $datelabel) = @_;
my ($year, $month, $day) = $calendar->get_date();
$month = _month()->[$month];
my $date_str = "$month $day \, $year";
$datelabel->set_text($date_str);
}
sub _calendar_popup {
my ($self, $datelabel, $calendar, $num) = @_;
my $datelabelbox = _add_button_press(_add_arrow($datelabel));
my $datepopup = Gtk2::Ex::PopupWindow->new($datelabel);
my $okbutton = Gtk2::Button->new_from_stock('gtk-ok');
$okbutton->signal_connect ('button-release-event' =>
sub {
_update_date_label($calendar, $datelabel);
$self->{model}->[$num] = _get_date_string($calendar);
$self->{joinercombo}->set_sensitive(TRUE) if ($num == 1);
$datepopup->hide;
&{ $self->{signals}->{'changed'} }
if $self->{signals}->{'changed'} and !$self->{freezesignals};
}
);
$calendar->signal_connect ( 'day-selected' =>
sub {
_update_date_label($calendar, $datelabel);
$self->{model}->[$num] = _get_date_string($calendar);
$self->{joinercombo}->set_sensitive(TRUE) if ($num == 1);
}
);
my $hbox = Gtk2::HBox->new (TRUE, 0);
$hbox->pack_start ($okbutton, TRUE, TRUE, 0);
my $vbox = Gtk2::VBox->new (FALSE, 0);
$vbox->pack_start ($calendar, TRUE, TRUE, 0);
$vbox->pack_start ($hbox, FALSE, FALSE, 0);
$datepopup->{window}->add($vbox);
$datelabelbox->signal_connect ('button-release-event' =>
sub {
$datepopup->show;
}
);
$datepopup->signal_connect('show' =>
sub {
return unless $self->{popup};
if ($^O =~ /Win32/) {
$self->{popup}->set_move_with_parent(TRUE);
$self->{popup}->show;
}
}
);
$datepopup->signal_connect('hide' =>
sub {
return unless $self->{popup};
if ($^O =~ /Win32/) {
$self->{popup}->set_move_with_parent(FALSE);
}
}
);
if ($self->{popup}) {
$self->{popup}->signal_connect('hide' =>
sub {
$datepopup->hide;
}
);
}
return $datelabelbox;
}
sub _month {
return [
'January',
'February',
lib/Gtk2/Ex/DateRange.pm view on Meta::CPAN
=head2 new;
=head2 set_model($model);
The C<$model> is a ref to a list with 5 parameters;
$daterange->set_model([ 'before', '1965-03-12', 'or', 'after', '1989-02-14' ]);
=head2 get_model;
=head2 attach_popup_to($parent);
This method returns a C<Gtk2::Ex::PopupWindow>. The popup window will contain
a C<Gtk2::Ex::DateRange> widget and two buttons.
=head2 to_sql_condition($datefieldname, $model);
Converts the C<$model> into an SQL condition so that it can be used directly in
and SQL statement. C<$datefieldname> is the fieldname that will be used inside
the SQL condition.
=head2 signal_connect($signal, $callback);
t/show-range-popup.t view on Meta::CPAN
use Data::Dumper;
use Gtk2::Ex::DateRange;
use Gtk2::TestHelper tests => 2;
my $daterange = Gtk2::Ex::DateRange->new;
isa_ok($daterange, "Gtk2::Ex::DateRange");
$daterange->set_model([ 'after', '1965-03-12', 'and', 'before', '1989-02-14' ]);
my $label = Gtk2::Label->new('Click-Here');
my $popup = $daterange->attach_popup_to($label);
isa_ok($popup, "Gtk2::Ex::PopupWindow");
( run in 2.198 seconds using v1.01-cache-2.11-cpan-364913b4093 )