Gtk2-Ex-DBITableFilter
view release on metacpan or search on metacpan
lib/Gtk2/Ex/DBITableFilter/FilterWidget.pm view on Meta::CPAN
my $col = $slist->get_column($columnnumber);
my $title = $col->get_title;
my $label = Gtk2::Label->new ($title);
my $labelbox = _add_arrow($label);
$col->set_widget ($labelbox);
$labelbox->show_all;
my $button = $col->get_widget; # not a button
do {
$button = $button->get_parent;
} until ($button->isa ('Gtk2::Button'));
my $combobox = Gtk2::Ex::ComboBox->new($labelbox, 'with-buttons');
$combobox->set_list_preselected($list);
$button->signal_connect ('button-release-event' =>
sub {
my ($self, $event) = @_;
$combobox->show;
}
);
$parent->{params}->{columnfilter}->{$columnnumber}
= combine($combobox->get_selected_values->{'selected-values'});
$combobox->signal_connect( 'changed' =>
sub {
$parent->{params}->{columnfilter}->{$columnnumber}
= combine($combobox->get_selected_values->{'selected-values'});
}
);
$parent->{combobox}->{$columnnumber} = $combobox;
}
sub combine {
my ($list) = @_;
my $str = join '\',\'', @$list;
$str = '(\''.$str.'\')';
return $str;
}
sub add_date_filter {
lib/Gtk2/Ex/DBITableFilter/FilterWidget.pm view on Meta::CPAN
my $parent = $self->{parent};
my $button = $self->_get_column_header_button($columnnumber);
my $popupwindow = Gtk2::Ex::PopupWindow->new($button);
$popupwindow->set_move_with_parent(TRUE);
my $choices = ['before', 'after'];
my $joiner = [ '', 'and', 'or'];
my $datelabel1 = Gtk2::Label->new;
my $datelabelbox1 = _calendar_popup($datelabel1, $date1);
my $combobox1 = Gtk2::ComboBox->new_text;
$combobox1->append_text($choices->[0]);
$combobox1->append_text($choices->[1]);
my $index1 = 1;
if ($command1) {
my $i = 0;
$index1 = { map { $_ => $i++ } @$choices }->{$command1};
}
$combobox1->set_active($index1);
my $datelabel2 = Gtk2::Label->new;
my $datelabelbox2 = _calendar_popup($datelabel2, $date2);
my $combobox2 = Gtk2::ComboBox->new_text;
$combobox2->append_text($choices->[0]);
$combobox2->append_text($choices->[1]);
my $index2 = 0;
if ($command1) {
my $i = 0;
$index2 = { map { $_ => $i++ } @$choices }->{$command2};
}
$combobox2->set_active($index2);
my $and_or_combobox = Gtk2::ComboBox->new_text;
$and_or_combobox->append_text($joiner->[0]);
$and_or_combobox->append_text($joiner->[1]);
$and_or_combobox->append_text($joiner->[2]);
my $index = 0;
if ($joiner1) {
my $i = 0;
$index = { map { $_ => $i++ } @$joiner }->{$joiner1};
}
$and_or_combobox->set_active($index);
$and_or_combobox->signal_connect ( 'changed' =>
sub {
my $choice = $and_or_combobox->get_active();
if ($choice == 0) {
$combobox2->hide_all;
$datelabelbox2->hide_all;
} else {
$combobox2->show;
$datelabelbox2->show_all;
}
}
);
my $refreshparams = sub {
my $params;
$params->[0]->{command} = $choices->[$combobox1->get_active()];
$params->[0]->{date} = $datelabel1->get_text();
return $params unless $and_or_combobox->get_active();;
$params->[1]->{joiner} = $joiner->[$and_or_combobox->get_active()];
$params->[1]->{command} = $choices->[$combobox2->get_active()];
$params->[1]->{date} = $datelabel2->get_text();
return $params;
};
my $table = Gtk2::Table->new(3,3,FALSE);
$table->attach($combobox1,0,1,0,1, 'expand', 'expand', 0, 0);
$table->attach($datelabelbox1,1,2,0,1, 'expand', 'expand', 0, 0);
$table->attach($and_or_combobox,2,3,0,1, 'expand', 'expand', 0, 0);
$table->attach($combobox2,0,1,1,2, 'expand', 'expand', 0, 0);
$table->attach($datelabelbox2,1,2,1,2, 'expand', 'expand', 0, 0);
my $apply = Gtk2::Button->new_from_stock('gtk-apply');
$parent->{params}->{columnfilter}->{$columnnumber} = &$refreshparams if $preselected;
$apply->signal_connect ('button-release-event' =>
sub {
$parent->{params}->{columnfilter}->{$columnnumber}
= &$refreshparams;
$popupwindow->hide;
}
);
my $clear = Gtk2::Button->new_from_stock('gtk-clear');
$clear->signal_connect ('button-release-event' =>
sub {
$parent->{params}->{columnfilter}->{$columnnumber} = undef;
$and_or_combobox->set_active(0);
$datelabel1->set_text('none');
$popupwindow->hide;
}
);
my $hbox = Gtk2::HBox->new (TRUE, 0);
$hbox->pack_start ($apply, TRUE, TRUE, 0);
$hbox->pack_start ($clear, TRUE, TRUE, 0);
my $vbox = Gtk2::VBox->new (FALSE, 0);
$vbox->pack_start ($table, TRUE, TRUE, 0);
$vbox->pack_start ($hbox, FALSE, FALSE, 0);
$popupwindow->{window}->add($vbox);
$button->signal_connect ('button-release-event' =>
sub {
my ($self, $event) = @_;
$popupwindow->show;
unless ($and_or_combobox->get_active()) {
$combobox2->hide;
$datelabelbox2->hide;
}
}
);
}
sub process_dates {
my ($self, $fieldname, $list) = @_;
print Dumper $list;
my $str = '';
( run in 2.526 seconds using v1.01-cache-2.11-cpan-8dfa8b56332 )