• [^] # Re: En Gtk2 Perl

    Posté par . En réponse au message Gnome 2.6 : rotation de fond d'écran. Évalué à 2.

    Bon voici une version qui fonctionne. Il faut lui donner en parametre un intervalle de temps et la repertoire de tes backgrounds. Il va aller les chercher au hasard et te changer ton fond d'écran ;) Exemple :
    ./change_background.pl 10000 /home/g-remy/Wallpaper
    
    Et le code :
    #!/usr/bin/perl -w
    use	strict;
    use	Gtk2 -init;
    use	Gnome2::GConf;
    die("Usage: ./change_background.pl time wallpapers_path\n") if (scalar(@ARGV) != 2); 
    my	$directory = $ARGV[1];
    opendir(DIR, $directory) || die "can’t opendir $directory: $!";
    my	@background = grep { !/^\./ && (/\.png$/ || /\.jpg$/ || /\.bmp$/) } readdir(DIR);
    closedir DIR;
    my	$client = Gnome2::GConf::Client->get_default;
    my	$key = "/desktop/gnome/background/picture_filename";
    my	$idx;
    srand();
    sub	change_background
    {
     $idx = int(rand(scalar(@background)));
     $client->set($key, { type => 'string',
    			 value => $directory."/".$background[$idx] }); 
     print "Changing background to: $background[$idx]\n";
    }
    my $timer= Glib::Timeout->add($ARGV[0] ,\&change_background);
    Gtk2->main;