Zenity
Encyclopedia
Zenity is a cross-platform
Cross-platform
In computing, cross-platform, or multi-platform, is an attribute conferred to computer software or computing methods and concepts that are implemented and inter-operate on multiple computer platforms...

 program that allows the execution of GTK+
GTK+
GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...

 dialog boxes in command-line and shell script
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

s.

Like tools such as whiptail
Newt (programming library)
Newt is a programming library for color text mode, widget-based user interfaces. Newt can be used to add stacked windows, entry widgets, checkboxes, radio buttons, labels, plain text fields, scrollbars, etc., to text user interfaces...

 and dialog
Dialog (software)
Dialog is an application used in shell scripts which displays text user interface widgets. It uses the curses or ncurses library. The latter provides users with the ability to use a mouse, e.g., in an xterm....

, zenity allows for easy creation of GUIs, though it has fewer features than more complex GUI creation tools : "Other scripting languages such as Perl and Python can be used to construct full-scale GUI applications, but the zenity program enables a shell script to interact with a GUI user.... [The] user interface is not as refined as one that could be provided by a full-featured GUI application, but it is perfectly suitable for simple interactions."

Cross-platform compatibility

At the moment Zenity is available for Linux, BSD and Windows. GTK+
GTK+
GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...

, the library on which Zenity is based, is also available for MacOS. It therefore should be possible to port Zenity also to this platform.

Zenity does not possess any built-in scripting capabilities and it must therefore rely on an interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...

 for processing. If it is desired to create a script that runs on more than any one platform, without heavily modifying it, it will be best to use the same interpreter. One such option is Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

in combination with PyZenity as these are available for several platforms.

Cross-platform script example


from PyZenity import InfoMessage
from PyZenity import Question
from PyZenity import ErrorMessage

choice=Question('Please press a button.')

if choice:
InfoMessage('You pressed Yes!')
else:
ErrorMessage('You pressed No!')




Linux Bash shell script example

  1. !/bin/bash


if zenity --question --text="Please press a button."; then
zenity --info --text="You pressed Yes\!"
else
zenity --error --text="You pressed No\!"
fi

Windows example


@echo off
zenity --question --ok-label="Yes" --cancel-label="No" --text="Please press a button."
if %ERRORLEVEL%

1 goto error
zenity --info --text="You pressed Yes!"
goto end
error

zenity --error --text="You pressed No!"

External links
  • http://live.gnome.org/Zenity
  • http://code.google.com/p/yad/ - yad (fork of Zenity that removes dependencies on obsoleted libraries)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK