如何创建带有多个进度条的 wget GUI?

Rey*_*ato 21 zenity wget

我正在编写自己的脚本来下载多个项目(同时,每个命令一个项目)wget,我需要一个进度条。我目前zenity --progress用于我的进度条,但问题是它在下载时会产生多个进度条。

我想要实现的是类似于 Nautilus 中的文件传输对话框:

Ubuntu 的文件传输对话框

任何人都可以向我指出正确的方向,哪些程序或语言将实现这一目标。

注意: 我只有 shell 脚本的基本知识,其他的不多。

Glu*_*ate 28

使用 YAD 的解决方案


概述

Zenity 好久没有更新了。幸运的是,有一个名为YAD的分支,具有许多附加功能。它尚未到达官方存储库,但您可以从 webupd8 PPA 安装它:

sudo add-apt-repository ppa:webupd8team/y-ppa-manager
sudo apt-get update
sudo apt-get install yad
Run Code Online (Sandbox Code Playgroud)

添加到 YAD 的功能之一是多​​进度条对话框。以下是 YAD 手册中有关多个进度条的摘录:

Multi progress bars dialog options
--bar=LABEL[:TYPE]
  Add progress bar. LABEL is a text label for progress bar. TYPE is a progress bar type. Types are:
  NORM for normal progress bar, RTL for inverted progress bar and PULSE for pulsate progress bar.
--vertical
  Set vertical orientation of progress bars.
--align=TYPE
  Set alignment of bar labels. Possible types are left, center or right. Default is left.

Initial values for bars set as extra arguments. Each lines with progress data passed to stdin must be started
from N: where N is a number of progress bar. Rest is the same as in progress dialog.
Run Code Online (Sandbox Code Playgroud)

因此,一个非常简单的带有多个进度条的脚本可能如下所示:

sudo add-apt-repository ppa:webupd8team/y-ppa-manager
sudo apt-get update
sudo apt-get install yad
Run Code Online (Sandbox Code Playgroud)

这就是结果的样子:

简单的 yad 多进程脚本


我们可以使用#以下命令向条形添加描述:

Multi progress bars dialog options
--bar=LABEL[:TYPE]
  Add progress bar. LABEL is a text label for progress bar. TYPE is a progress bar type. Types are:
  NORM for normal progress bar, RTL for inverted progress bar and PULSE for pulsate progress bar.
--vertical
  Set vertical orientation of progress bars.
--align=TYPE
  Set alignment of bar labels. Possible types are left, center or right. Default is left.

Initial values for bars set as extra arguments. Each lines with progress data passed to stdin must be started
from N: where N is a number of progress bar. Rest is the same as in progress dialog.
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明


如果我们想在 wget 下载脚本中实现这一点,我们必须先做一些事情:

  • 找到一种方法从 wget 输出中提取下载进度和其他有趣的数据
  • 找到迭代多个文件的方法
  • 找到一种方法将我们拥有的所有信息传递给一个单独的对话

我发现这个项目很有趣,所以我坐下来编写了一个脚本,可以完成上述所有操作。


yad_wget

这是我想出的:

for i in {1..100}; do
   printf "1:$i\n2:$i\n3:$i\n"
   sleep 0.2
done | yad --multi-progress --bar="Bar 1":NORM --bar="Bar 2":NORM --bar="Bar 3":NORM
Run Code Online (Sandbox Code Playgroud)

这就是它的样子:

在此处输入图片说明

           在此处输入图片说明

请务必通读所有评论以了解脚本的工作原理,如果您有任何问题,请随时在下面的评论中提问。


编辑:

我添加了对设置最大同时下载数的支持。例如MAXDLS="5"

在此处输入图片说明

  • 要获得更多控件,您需要升级到 [GtkDialog](http://code.google.com/p/gtkdialog/),它可以让您执行几乎任何操作。然而,它涉及更多。[PuppyLinux](http://puppylinux.org) 社区广泛使用它。 (2认同)