xml 幻灯片无法像壁纸一样正常工作

xml 幻灯片无法像壁纸一样正常工作

我在 Google 上四处搜索解决方案,并让它工作了一段时间,甚至添加了大量文件/usr/share/backgrounds(jpg、png、webp),并更新了/usr/share/gnome-background-properties/backgrounds.xml文件以包含新添加的文件。

一切运行良好。背景选择器对话框和桌面上显示的每个图像以及提供的幻灯片(如 precise.xml)也都可以正常工作。

好的,很酷。然后,我创建了自己的幻灯片 xml 文件,并将其添加到壁纸中/usr/share/backgrounds/。效果很好!但是,时机不符合我的喜好。

最初,持续时间设置为 300 秒(五分钟),过渡设置为 5 秒。不错,但我想做一些微小的调整。所以我使用我编写的 perl 脚本来做到这一点(其输出如下并被截断),现在......什么都不起作用!

我很确定我的设置是正确的,但就是不明白为什么它不起作用。

这是我的backgrounds.xml(存储在/usr/share/gnome-background-properties/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
  <wallpaper deleted="false">
    <name>Slideshow</name>
    <filename>/usr/share/backgrounds/slideshow.xml</filename>
    <options>zoom</options>
  </wallpaper>
  <wallpaper>
    <_name>OK1</_name>
    <filename>/usr/share/backgrounds/OK1.jpg</filename>
    <options>zoom</options>
    <pcolor>#000000</pcolor>
    <scolor>#000000</scolor>
    <shade_type>solid</shade_type>
  </wallpaper>
  <wallpaper>
    <_name>OK10</_name>
    <filename>/usr/share/backgrounds/OK10.jpg</filename>
    <options>zoom</options>
    <pcolor>#000000</pcolor>
    <scolor>#000000</scolor>
    <shade_type>solid</shade_type>
  </wallpaper>
  <wallpaper>
    <_name>OK100</_name>
    <filename>/usr/share/backgrounds/OK100.jpg</filename>
    <options>zoom</options>
    <pcolor>#000000</pcolor>
    <scolor>#000000</scolor>
    <shade_type>solid</shade_type>
  </wallpaper>
  .
  .
  .
</wallpapers>

和我的slideshow.xml(存储在/usr/share/backgrounds/

<background>
  <starttime>
    <year>2009</year>
    <month>08</month>
    <day>04</day>
    <hour>00</hour>
    <minute>00</minute>
    <second>00</second>
  </starttime>
  <static>
    <duration>10.0</duration>
    <file>/usr/share/backgrounds/OK114.jpg</file>
  </static>
  <transition>
    <duration>3</duration>
    <from>/usr/share/backgrounds/OK114.jpg</from>
    <to>/usr/share/backgrounds/OK165.jpg</to>
  </transition>
  <static>
    <duration>10.0</duration>
    <file>/usr/share/backgrounds/OK165.jpg</file>
  </static>
  <transition>
    <duration>3</duration>
    <from>/usr/share/backgrounds/OK165.jpg</from>
    <to>/usr/share/backgrounds/OK209.jpg</to>
  </transition>
  <static>
    <duration>10.0</duration>
    <file>/usr/share/backgrounds/OK209.jpg</file>
  </static>
  <transition>
    <duration>3</duration>
    <from>/usr/share/backgrounds/OK209.jpg</from>
    <to>/usr/share/backgrounds/OK42.jpg</to>
  </transition>
  .
  .
  .
</background>

这两个 xml 文件都很大,有 2000 多行。

这让我很困惑。当我打开背景图片选择对话框时,我可以看到列出的幻灯片,它甚至显示了一个随机选择的图像。但是,当我双击它作为背景时,我的桌面壁纸仍然全黑。

我是不是打错了什么字,我没注意到?我是不是漏掉了什么关键细节?我就是搞不懂。

任何帮助都会受到赞赏,如果我忘记添加某些内容,请不要责骂我或因为我没有包括它而追着我,而只需提出要求,我会很乐意将其包括在内。

我搜索了很多东西。按照以下站点上的指示进行操作(但不限于): https://help.ubuntu.com/community/SlideshowWallpapers https://opensource.com/article/17/12/create-your-own-wallpaper-slideshow-gnome

现在,我在背景选择对话框中仅看到两张图像。我的幻灯片文件,以及一张应该是幻灯片的图像,等等其他很多图像。

答案1

正确。18.04。似乎简单的重启就可以解决问题,因为现在它可以正常工作了!另外,我刚刚了解到我可以通过按 重新启动 gnome 桌面ALT-F2, type R, and press Enter。但是,为了满足查看生成幻灯片的脚本的请求:

#!/usr/bin/perl

use strict;
use Term::ReadKey; ReadMode 4;
use Term::ANSIColor;
use List::Util 'shuffle';

use lib "/var/www/html/Pm";
use Bc_dir qw(external_files write_text read_text);
use Bc_misc qw(shorten_str);

my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();

my $clear = `clear`;

my $CURRENTDIR = "/usr/share/backgrounds";
my $FILE = "$CURRENTDIR/slideshow.xml";
my $MAX_DURATION = 3600; # maximum display time
my $MIN_DURATION = 10; # minimum display time
my $DURATION = 300.0; # actual display time
my $MAX_TRANSITION = 8.0; # maximum transition time
my $MIN_TRANSITION = 0.25; # minimum transition time
my $TRANSITION = 3.0; # actual transition time
my $DURATION_STEP = 10; # add/minus 10 seconds to/from duration time
my $TRANSITION_STEP = 0.25; # add/minus 0.25 seconds to/from transition time

my $TRANSITION_XML = <<END;
  <static>
    <duration>$DURATION</duration>
    <file>[thisfile]</file>
  </static>
  <transition>
    <duration>$TRANSITION</duration>
    <from>[thisfile]</from>
    <to>[nextfile]</to>
  </transition>
END

my @IMGS = external_files($CURRENTDIR, "jpg");
push @IMGS, external_files($CURRENTDIR, "jpeg");
push @IMGS, external_files($CURRENTDIR, "png");
push @IMGS, external_files($CURRENTDIR, "gif");

{
  my @new;
  foreach my $img (@IMGS) {
    if ($img) { push @new, $img; }
  }
  @IMGS = @new;
}

@IMGS = shuffle(@IMGS);

my $slideshow = "<background>\n";
$slideshow .= <<END;
  <starttime>
    <year>2009</year>
    <month>08</month>
    <day>04</day>
    <hour>00</hour>
    <minute>00</minute>
    <second>00</second>
  </starttime>
END

my $i = 0;
my $line = 0;
foreach my $file (@IMGS) {
  my $thisone = $TRANSITION_XML;
  $thisone =~ s/\[thisfile\]/$CURRENTDIR\/$file/g;

  my $nextfile = "";
  if ($line + $i + 1 < @IMGS)
    { $nextfile = $IMGS[$line + $i + 1]; } else
    { $nextfile = $IMGS[0]; }

  $thisone =~ s/\[nextfile\]/$CURRENTDIR\/$nextfile/g;
  $slideshow .= $thisone;
  $i++;
}

$slideshow .= "</background>\n";

sub hideCursor() { print "\e[?25l"; }
sub showCursor() { print "\e[0H\e[0J\e[?25h"; }

sub txt($;$) {
  my ($txt, $clr) = @_;
  my $rv = "";
  if ($txt) {
    if ($clr) { $rv = color($clr); }
    $rv .= $txt;
    if ($clr) { $rv .= color("reset"); }
  }

  return $rv;
}

sub error($) {
  my ($txt) = @_;
  my $rv = "";
  if ($txt) {
    $rv = color("bold red");
    $rv .= $txt;
    $rv .= color("reset");
  }

  return $rv;
}

sub notice($) {
  my ($txt) = @_;
  my $rv = "";
  if ($txt) {
    $rv = color("bold green");
    $rv .= $txt;
    $rv .= color("reset");
  }

  return $rv;
}

sub warning($) {
  my ($txt) = @_;
  my $rv = "";
  if ($txt) {
    $rv = color("bold yellow");
    $rv .= $txt;
    $rv .= color("reset");
  }

  return $rv;
}

sub end() {
  ReadMode 0;
  print warning("Peace out!\n\n");
  exit 1;
}

my $kbkey = 0;
sub getKeypress() {
  my $rv = undef;
  if (defined($kbkey = ReadKey(-1))) {
    $rv = $kbkey;
  }

  return $rv;
}

sub beep() {
  print chr(7);
}

sub show() {
  hideCursor();
  my $lines = 40;
  my $linelen = $wchar;
  my $page = 0;
  my $line = 0;
  my @slide = split("\n", $slideshow);
  my $displayed = 0;

  my $stop = 0;
  while (not $stop) {
    # display $lines lines, and ask for keypress
    if (not $displayed) {
      print $clear;

      for (my $i = 0; $i < $lines; $i++) {
        my $thisline = "";
        if ($slide[$line + $i]) {
          my $output = shorten_str($line + $i . ": " . $slide[$line + $i], $linelen) . "\n";
          print $output;
        }
      }

      print "\n";
      print warning("note: long lines are truncated to a maximum length of $linelen chars in this display!\n");
      print "press \n";
      print "  " . warning("N") . " for next page\n";
      print "  " . warning("P") . " for previous page\n";
      print "  " . warning("H") . " to jump to first page\n";
      print "  " . warning("E") . " to jump to last page\n";
      print "  " . warning("Q") . " to return to main menu\n";

      $displayed = 1;
    }

    my $key = getKeypress();
    if ($key) {
      lc $key;
      if ($key eq "q") {
        $stop = 1;
      } elsif ($key eq "n") {
        $line += $lines;
        if ($line > @slide - ($lines)) { $line = @slide - ($lines); }
        $displayed = 0;
      } elsif ($key eq "p") {
        $line -= $lines;
        if ($line < 0) { $line = 0; }
        $displayed = 0;
      } elsif ($key eq "h") {
        $line = 0;
        $displayed = 0;
      } elsif ($key eq "e") {
        $line = @slide - $lines;
        $displayed = 0;
      }
    }
  }

  showCursor();
}

sub writefile() {
  write_text($FILE, $slideshow);
}

sub showmenu(;$) {
  my ($msg) = @_;

  print $clear;

  if (ref $msg eq "HASH") {
    if ($msg->{warning})
      { print warning($msg->{warning} . "\n\n"); }
  } elsif ($msg) {
    print txt($msg) . "\n\n";
  }

  print "press\n";
  print "   " . warning("S") . " to display the slideshow data\n";
  print "   " . warning("W") . " to write the slideshow data to " . txt($FILE, "bold white") . "\n";
  print "   " . warning("L") . " to load the slideshow data from " . txt($FILE, "bold white") . "\n";
  print "   " . warning("+") . " to increase display DURATION of each image by 10 seconds\n";
  print "   " . warning("-") . " to decrease display DURATION of each image by 10 seconds\n";
  print "   " . warning("*") . " to increase TRANSITION time by 0.25 seconds\n";
  print "   " . warning("/") . " to decrease TRANSITION time by 0.25 seconds\n";
  print "\n   " . error("Q") . " to quit\n";
  print "\n";
  print "  Display Time: " . warning($DURATION) . "\n";
  print "  Transition Time: " . warning($TRANSITION) . "\n";
  print "\n";

  if (ref $msg eq "HASH") {
    if ($msg->{error})
      { print error($msg->{error} . "\n"); }
  }

  print "Selection: ";
}

sub initSlideshow() {
  $TRANSITION_XML = <<END;
  <static>
    <duration>$DURATION.0</duration>
    <file>[thisfile]</file>
  </static>
  <transition>
    <duration>$TRANSITION</duration>
    <from>[thisfile]</from>
    <to>[nextfile]</to>
  </transition>
END

  @IMGS = external_files($CURRENTDIR, "jpg");
  push @IMGS, external_files($CURRENTDIR, "jpeg");
  push @IMGS, external_files($CURRENTDIR, "png");
  push @IMGS, external_files($CURRENTDIR, "gif");

  {
    my @new;
    foreach my $img (@IMGS) {
      if ($img) { push @new, $img; }
    }
    @IMGS = @new;
  }

  @IMGS = shuffle(@IMGS);

  $slideshow = "<background>\n";
  $slideshow .= <<END;
  <starttime>
    <year>2009</year>
    <month>08</month>
    <day>04</day>
    <hour>00</hour>
    <minute>00</minute>
    <second>00</second>
  </starttime>
END

  my $i = 0;
  foreach my $file (@IMGS) {
    my $thisone = $TRANSITION_XML;
    $thisone =~ s/\[thisfile\]/$CURRENTDIR\/$file/g;

    my $nextfile = "";
    if ($line + $i + 1 < @IMGS)
      { $nextfile = $IMGS[$line + $i + 1]; } else
      { $nextfile = $IMGS[0]; }

    $thisone =~ s/\[nextfile\]/$CURRENTDIR\/$nextfile/g;
    $slideshow .= $thisone;
    $i++;
  }

  $slideshow .= "</background>\n";
}

sub load() {
  $slideshow = read_text($FILE);
}

my $stop = 0;
showmenu();

while (not $stop) {
  my $keypressed = getKeypress();
  if ($keypressed) {
    lc $keypressed;
    if ($keypressed eq "q") {
      print error("Q\n\n");
      $stop = 1;
    } elsif ($keypressed eq "w") {
      print warning("W\n\n");
      writefile();
      my %msg;
      $msg{warning} = "Slideshow Data Written to $FILE";
      showmenu(\%msg);
    } elsif ($keypressed eq "s") {
      print warning("S\n\n");
      show();
      showmenu();
    } elsif ($keypressed eq "l") {
      print warning("L\n\n");
      load();
      my %msg;
      $msg{warning} = "Slideshow Data Read from $FILE";
      showmenu(\%msg);
    } elsif ($keypressed eq "+") {
      print warning("+\n\n");
      $DURATION += $DURATION_STEP;
      if ($DURATION > $MAX_DURATION) { $DURATION = $MAX_DURATION; }
      initSlideshow();
      showmenu();
    } elsif ($keypressed eq "-") {
      print warning("-\n\n");
      $DURATION -= $DURATION_STEP;
      if ($DURATION < $MIN_DURATION) { $DURATION = $MIN_DURATION; }
      initSlideshow();
      showmenu();
    } elsif ($keypressed eq "*") {
      print warning("*\n\n");
      $TRANSITION += $TRANSITION_STEP;
      if ($TRANSITION > $MAX_TRANSITION) { $TRANSITION = $MAX_TRANSITION; }
      initSlideshow();
      showmenu();
    } elsif ($keypressed eq "/") {
      print warning("/\n\n");
      $TRANSITION -= $TRANSITION_STEP;
      if ($TRANSITION < $MIN_TRANSITION) { $TRANSITION = $MIN_TRANSITION; }
      initSlideshow();
      showmenu();
    } else {
      beep();
      showmenu({error=>"invalid key"});
    }
  }
}

end();

相关内容