Professional Documents
Culture Documents
Glynn Foster
GNOME Documentation Project
Edited by
File selection dialog. List options dialog. Progress dialog. Text dialog.
2. Basic Use
Zenity creates simple dialogs. You can use Zenity to create a script that interacts graphically with the user. When the user closes the dialog, Zenity prints text produced by the dialog to standard error.
Zenity Manual Ensure that all arguments to Zenity are surrounded by quotes. For example, use zenity --calender --title="Holiday Planner" instead of zenity --calender --title=Holiday Planner. If you do not use quotes, you can get unexpected results.
NOTE: Some dialogs support the use of keyboard mnemonics. To specify the character to use as the mnemonic, place an underscore before that character in the text of the dialog. For example, to specify the P as the keyboard mnemonic in the following sentence, use "_Please choose a name".
The user has pressed either Cancel or closed the dialog through the window functions.
-1
3. General Options
All dialogs have the following general options:
--title=TITLE
Species the icon that should appear in the window frame of the dialog.
--width=WIDTH
4. Calendar Dialog
Use --calender to create a Calender dialog. Zenity returns the date selected to standad error. The current date will be used by the dialog if no date is given on the command line. The Calender dialog has the following options:
Zenity Manual
--text=TEXT
Species the day to be pre-selected in the Calendar dialog. The day ust be a number between 1 and 31.
--month=MONTH
Species the day to be pre-selected in the Calendar dialog. The day must be a number between 1 and 12.
--year=YEAR
Species the format to be returned from the Calendar dialog after the selection has been made. The default format depends on your locale. The format must be of strftime style, for example "%A %d/%m%y". The following script is an example of how to use the Calendar dialog:
#!/bin/sh
if zenity --calendar --title="Calendar selection" --text="Select a date from below" --day=18 --mo then echo $? else echo "No date selected" fi
Species the text to appear in the entry eld of the Text Entry dialog.
--hide-text
Species that the text in the entry eld of the Text Entry dialog be hidden.
Zenity Manual The following script is an example of how to use the Text Entry dialog:
#!/bin/sh if zenity --entry --title="Add a new entry" --text="Enter your _Password" --hide-text then echo $? else echo "No password entered" fi
Figure 2. Text Entry dialog example Zenity Text Entry dialog example
6. Message Dialogs
Zenity can create four types of message dialog. Use the --text option to set the text shown in the dialog.
Zenity Manual Figure 4. Error dialog example Zenity Error dialog example
Species the le or directory to be selected in the File Selection dialog when the dialog is rst shown.
--multiple
Species the string used to divide the returned list of lenames. The following script is an example of how to use the File Selection dialog:
#!/bin/sh FILE=zenity --file-selection --title="Select a file"
Zenity Manual
case $? in 0) echo "\"$FILE\" selected.";; 1) echo "No file selected.";; -1) echo "No file selected.";; esac
Figure 7. File Selection dialog example Zenity File Selection dialog example
8. List Dialog
Use --list to create a list dialog. Zenity returns the entries in the rst column of text of selected rows to standard error. Every column must be specied by the --column option. Data for the dialog must specied column by column, row by row. Data can be provided to the dialog through standard input. Each entry must be separated by a newline. If you use the --checklist or --radiolist options, each row must start with either TRUE or FALSE. The List dialog has the following options:
--column=COLUMN
Species the column headers to appear in the List dialog. You must call the --column option for each column you want to appear in the dialog.
--checklist
Species that the rst column should contain check boxes in the List dialog.
--radiolist
Species that the rst column should contain radio boxes in the List dialog.
--editable
Species what string should be used when the List dialog returns the selected entries. The following commandline is an example of how to use the List dialog:
zenity --list --title="Choose bugs you wish to view" \
Zenity Manual
--text="Select items from the list below." \ --column="Bug Number" --column="Severity" --column="Description" \ 992383 Normal "GtkTreeView crashes on multiple selections" \ 293823 High "GNOME Dictionary does not handle proxy" \ 393823 Critical "Menu editing does not work in GNOME 2.0"
9. Progress Dialog
Use --progress to create a Progress dialog. Zenity reads data from standard input line by line. If a line is prexed with a hash (#), the text is updated with the text on that line. If a line contains only a number, the percentage is updated with that number. The Progress dialog has the following options:
--text=TEXT
Species the initial percentage that should be set in the Progress dialog.
--auto-close
Species that the Progress dialog should pulsate until an EOF character is read from standard input. The following script is an example of how to use the Progress dialog:
#!/bin/sh ( echo "10" ; sleep 1 echo "# Updating mail logs" ; sleep 1 echo "20" ; sleep 1 echo "# Resetting cron jobs" ; sleep 1 echo "50" ; sleep 1 echo "This line will just be ignored" ; sleep 1 echo "75" ; sleep 1 echo "# Rebooting system" ; sleep 1 echo "100" ; sleep 1 ) | zenity --progress --title="Update System Logs" --text="Scanning mail logs..." --percentage=0
Zenity Manual
Allows the displayed text to be edited. The edited text is returned to standard error when the dialog is closed. The following script is an example of how to use the Text Infomation dialog:
#!/bin/sh FILE=zenity --file-selection --title="Select a file" case $? in 0) zenity --text-info --title=$FILE --editable 2>/tmp/tmp.txt 1) echo "No file selected.";; -1) echo "No file selected.";; esac
Figure 10. Text Information dialog example Zenity Text Information dialog example
Zenity Manual
12. License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (gnome-help:gpl) as published by the Free Software Foundation; either version 2 of the License, of (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License is included as an appendix to the GNOME Users Guide . You may also obtain a copy of the GNU General Public License from the Free Software Foundation by visiting their Web site (http://www.fsf.org) or by writing to Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307 USA