来自 bash 脚本的对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8354482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:16:34  来源:igfitidea点击:

Dialog from bash script

bashuser-interfacedialog

提问by uzsolt

I want create a simple graphical (Qt, Gtk, ...) dialog, concretly a simple print dialog, as a "frontend" to lpr, in bash. What I want? How many pages per page, printing interval. It's (at least) two options.

我想在 bash 中创建一个简单的图形(Qt,Gtk,...)对话框,具体来说是一个简单的打印对话框,作为 lpr 的“前端”。我想要的是?每页多少页,打印间隔。这是(至少)两种选择。

What is the best util(s) to solve this problem?

解决此问题的最佳实用程序是什么?

采纳答案by uzsolt

I've searched what dialog creators are. I found yadand with this I can set my desired options:

我搜索了对话创建者是什么。我找到了yad,有了这个,我可以设置我想要的选项:

yad --skip-taskbar --center --title="Print dialog" {--image,--window-icon}=/usr/share/icons/Tango/72x72/devices/printer1.png --form --item-separator=, --field="Pages per sheet":CB 1,2,4,6,8 --field="Pages"

Dialog

对话

And when I choose "2 pages per sheet" and pages "1-12" and after click OKthe output will 2|1-12|.

当我选择“每张纸 2 页”和“1-12 页”时,单击后OK输出将2|1-12|.

This is what I desired. Zenity or Xdialog can do similar?

这就是我想要的。Zenity 或 Xdialog 可以做类似的事情吗?

回答by sehe

There is

Other implementations are reported to exist:

据报道存在其他实现:

If you use gpm, you can even use the mouse in a console environment. It requires a tty, so it willwork over ssh, screen, xterm etc. but not when piping/redirecting.

如果使用gpm,您甚至可以在控制台环境中使用鼠标。它需要一个 tty,所以它可以在 ssh、screen、xterm 等上工作,但在管道/重定向时不能。

Both sport more or less the same interface so you can switch depending on whether an X display is available

两者都具有或多或少相同的界面,因此您可以根据 X 显示器是否可用进行切换

Here is a dialog script that displays a simple YES/NO box:

这是一个对话框脚本,显示一个简单的“是/否”框:

#!/bin/bash
DIALOG=${DIALOG=dialog}

$DIALOG --title " My first dialog" --clear \
        --yesno "Hello , this is my first dialog program" 10 30

case $? in
  0)
    echo "Yes chosen.";;
  1)
    echo "No chosen.";;
  255)
    echo "ESC pressed.";;
esac

enter image description here

在此处输入图片说明

Replacing dialogby xdialog:

替换dialogxdialog

enter image description here

在此处输入图片说明

回答by Serge Stroobandt

Whiptail displays user-friendly dialog boxes from shell scripts

Whiptail 从 shell 脚本显示用户友好的对话框

Whiptailis a dialogreplacement using newtinstead of ncurses. It provides a method for displaying several different types of dialogue boxes from shell scripts. This allows a script developer to interact with the user in a much friendlier manner.

Whiptaildialog使用newt而不是 ncurses的替代品。它提供了一种从 shell 脚本显示几种不同类型对话框的方法。这允许脚本开发人员以更友好的方式与用户交互。

whiptail example

鞭尾示例

回答by BobC

matedialog(AKA mate-dialog) uses GTK+. It may also be the only script GUI dialog tool available under Cygwin.

matedialog(AKA mate-dialog) 使用 GTK+。它也可能是Cygwin下唯一可用的脚本 GUI 对话框工具。

回答by TheNano

You could use gdialogin gnome/ubuntu. I can't find xdialoganymore in 14.10. The answer from @sehe works with it just change dialog for gdialog.

你可以gdialoggnome/ubuntu. 我xdialog在 14.10找不到了。来自@sehe 的答案仅适用于更改gdialog.