问题
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.
What is the best util(s) to solve this problem?
回答1:
There is
- dialog (ncurses based)
- xdialog (X11 based)
Other implementations are reported to exist:
- zenity (Gnome)
- kdialog (Kde)
If you use gpm, you can even use the mouse in a console environment. It requires a tty, so it will work over ssh, screen, xterm etc. but not when piping/redirecting.
Both sport more or less the same interface so you can switch depending on whether an X display is available
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
Replacing dialog by xdialog:
回答2:
I've searched what dialog creators are. I found yad and with this I can set my desired options:
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"
And when I choose "2 pages per sheet" and pages "1-12" and after click OK the output will 2|1-12|.
This is what I desired. Zenity or Xdialog can do similar?
回答3:
Whiptail displays user-friendly dialog boxes from shell scripts
Whiptail is a dialog replacement using newt instead 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.
回答4:
matedialog (AKA mate-dialog) uses GTK+. It may also be the only script GUI dialog tool available under Cygwin.
回答5:
You could use gdialog in gnome/ubuntu. I can't find xdialog anymore in 14.10. The answer from @sehe works with it just change dialog for gdialog.
来源:https://stackoverflow.com/questions/8354482/dialog-from-bash-script