cvsimport
[fvwm-themes.git] / devel / bin / gtk-colorize-background
blob1077cf60b3d285256a415eadca92835cb70ef4a8
1 #!/usr/bin/perl -w
3 use Gtk;
4 use Gtk::ColorSelectButton;
6 if (@ARGV != 2) {
7 print "Usage: $0 image_file color_num\n";
8 exit 1;
11 my $imageFile = shift;
12 my $colorNum = shift;
14 unless (-f $imageFile) {
15 print "No image $imageFile found\n";
16 exit 1;
19 unless ($colorNum =~ /^\d+$/ && $colorNum > 2 && $colorNum <= 9) {
20 print "color_num parameter should be in the range [2 .. 9]\n";
21 exit 1;
24 init Gtk;
25 init Gtk::ColorSelectButton;
27 my @colorButtons = ();
28 foreach (0 .. $colorNum - 1) {
29 my $button = new Gtk::ColorSelectButton;
30 my $br = int($_ / $colorNum * 256);
31 $button->set(color => "$br $br $br");
32 push @colorButtons, $button;
35 sub colorizeRoot {
36 my @colors = ();
37 foreach (@colorButtons) {
38 push @colors, sprintf "rgb:%02x/%02x/%02x", split / /, $_->color;
40 my $colorStr = join(',', @colors);
41 print $colorStr, "\n";
42 system(qq(fvwm-themes-images --in-file "$imageFile" --setroot --colorize --colorize-colors "$colorStr"));
45 # -------- main --------
47 my $dialog = new Gtk::Dialog;
48 $dialog->set_title("Colorizing Backround");
49 $dialog->set_border_width(4);
50 $dialog->set_usize(400, 160);
52 my $label = new Gtk::Label("Image: " . substr($imageFile, -60));
53 $dialog->vbox->pack_start($label, 1, 1, 8);
55 my $hbox = new Gtk::HBox(1, 0);
56 $dialog->vbox->pack_end($hbox, 1, 1, 8);
58 foreach (0 .. $colorNum - 1) {
59 $hbox->pack_start($colorButtons[$_], 1, 1, 8);
62 my $button;
64 $button = new Gtk::Button " Set Backgound ";
65 $dialog->action_area->pack_start($button, 0, 0, 8);
66 $button->signal_connect("clicked", sub { colorizeRoot(); });
68 $button = new Gtk::Button " Quit ";
69 $dialog->action_area->pack_start($button, 0, 0, 8);
70 $button->signal_connect("clicked", sub { Gtk->main_quit; });
72 $dialog->show_all;
74 Gtk->main;