Commit 85dccf1e authored by Alon Swartz's avatar Alon Swartz
Browse files

initial import of pythondialog_2.7

Peter Astrand <> (current maintainer)
Robb Shecter <>
Sultanbek Tezadov (
Florent Rougon <>
This diff is collapsed.
# The following lines are useful for debugging: they write the
# full command (with arguments quoted and environment
# variables set) to a file named "command.debug" in the
# current directory. See Dialog.__call_program() in
import commands
envvar_settings_list = []
if new_environ.has_key("DIALOGRC"):
"DIALOGRC='%s'" % new_environ["DIALOGRC"])
for var in _dialog_exit_status_vars.keys():
varname = "DIALOG_" + var
"%s=%s" % (varname, new_environ[varname]))
envvar_settings = string.join(envvar_settings_list, " ")
file("command.debug", "wb").write(
envvar_settings +
string.join(map(commands.mkarg, arglist), ""))
Python 2.2 or newer.
pythondialog is packaged with Distutils (the current standard way to
package Python extensions), so its installation should be as simple as:
- make this file's directory your shell's current directory
- optionally edit setup.cfg to make sure that it fits your needs
(particularly the installation prefix); in the case of the prefix,
you could alternatively specify it later with the --prefix,
--exec-prefix, etc. arguments of are described in
detail in the "Installing Python Modules" chapter of the Python
- a) 1) type:
python ./ build
2) then, as root:
python ./ install --record /path/to/foo
where foo is a file of your choice which will contain the list
of all files installed on your system by the preceding
command. This will make uninstallation easy (you could ommit
the "--record /path/to/foo", but uninstallation could not be
automated, then).
b) type, as root:
python ./ install --record /path/to/foo
This will automatically build the package before installing it.
The observations made in a) also apply here.
If this default installation is not what you wish, please read the
Distutils documentation. In Python 2.1 and above, it is included in the
base Python documentation and the chapter you'll need is most probably
"Installing Python Modules".
Provided you have followed the instructions given in the installation
section, you have a /path/to/foo file that contains all the files the
installation process put on your system. Great! All you have to do is:
while read file; do rm -f "$file"; done < /path/to/foo
under a Bourne-compatible shell and with the appropriate privileges
(maybe root, depending on where you installed pythondialog).
Note: this will handle file names with spaces correctly, unlike the
simpler "rm -f $(cat /path/to/foo)".
# global-exclude *~
Metadata-Version: 1.0
Name: pythondialog
Version: 2.7
Summary: A Python interface to the UNIX dialog utility and mostly-compatible programs
Author: Peter Astrand
License: LGPL
Description: A Python interface to the UNIX dialog utility, designed to provide
an easy, pythonic and as complete as possible way to use the dialog
features from Python code.
Back-end programs that are almost compatible with dialog are also
supported if someone cares about them.
Keywords: dialog,Xdialog,whiptail,text-mode interface
Platform: UNIX
pythondialog is a Python wrapper for the UNIX "dialog" utility written
by Savio Lam and modified by several people, whose home page you should
find at Its purpose is to
provide an easy to use, pythonic and as complete as possible interface
to dialog from Python code.
pythondialog is free software, licensed under the GNU LGPL.
If you want to get a quick idea of what this module allows you to do,
you should run
What is pythondialog good for? What are its limitations?
As you might infer from the name, dialog is a high-level program that
generates dialog boxes. So is pythondialog. They allow you to build nice
interfaces quickly and easily, but you don't have full control over the
widgets, nor can you create new widgets without modifying dialog itself.
If you need to do low-level stuff, you should have a look at ncurses or
slang instead.
pythondialog is fully documented through Python docstrings. Handy ways
to access to this documentation are to use the pydoc standalone program
or Python module.
You can type "pydoc dialog" at the command prompt in pythondialog base
directory. Alternatively, you can type:
- "import dialog; help(dialog)" at at a Python 2.2 command prompt (and
probably any later version)
To browse it in HTML format, you can launch an HTTP server listening on
port 1234 with "pydoc -p 1234 &" (yes, it is damn easy!) and simply
browse on http://localhost:1234/ afterwards.
Alternatively, you can dump the current documentation (as
found by Python if you did "import dialog") as an html file with
"pydoc -w dialog". This will generate dialog.html in the current
See the pydoc module's documentation for more information.
Using Xdialog instead of dialog
Starting with 2.06, there is an "Xdialog" compatibility mode that you
can use if you want pythondialog to run the graphical Xdialog program
(which *should* be found under instead of
dialog (text-mode, based on the ncurses library).
The primary supported platform is still dialog, but as long as only
small modifications are enough to make pythondialog work with Xdialog, I
am willing to support Xdialog if people are interested in it (which
turned out to be the case for Xdialog).
The from pythondialog 2.06 has been tested with Xdialog 2.0.6
and found to work well (barring Xdialog's annoying behaviour with the
file selection dialog box).
* pythondialog seems not to work very well with whiptail. Well, whiptail
is not very compatible with dialog any more. Although you can tell
pythondialog the program you want it to invoke, only programs that are
mostly dialog-compatible are supported.
* It is said that there is a bug in (at least) the Mandrake 7.0 Russian
Edition running on AMD K6-2 3D that causes core dump when `dialog' is run
with the --gauge option; in this case you'll have to recompile the `dialog'
pythondialog was originally written by Robb Shecter. Sultanbek Tezadov
added some features to it (mainly the first gauge implementation, I
guess). Florent Rougon rewrote most parts of the program to make it
more robust and flexible so that it can give access to most features
of the dialog program. Finally, I (Peter Astrand) took over
maintainership for both the original version and Florents updated
* Add code so that the input buffer is flushed before a dialog box is shown.
This would make the UI more predictable for users. This feature could be
turned on and off through an instance method.
-> Unclear to me (Florent).
* Try detecting the terminal window size in order to make reasonable height
and width defaults. Hmmm -- should also then check for terminal resizing...
#! /usr/bin/env python
# --- A simple demonstration program for pythondialog
# Copyright (C) 2000 Robb Shecter, Sultanbek Tezadov
# Copyright (C) 2002, 2004 Florent Rougon
# This program is in the public domain.
"""Demonstration program for pythondialog.
This is a simple program demonstrating the possibilities offered by
the pythondialog module (which is itself a Python interface to the
well-known dialog utility, or any other program compatible with
Please have a look at the documentation for the `handle_exit_code'
function in order to understand the somewhat relaxed error checking
policy for pythondialog calls in this demo.
import sys, os, os.path, time, string, dialog
# XXX We should handle the new DIALOG_HELP and DIALOG_EXTRA return codes here.
def handle_exit_code(d, code):
"""Sample function showing how to interpret the dialog exit codes.
This function is not used after every call to dialog in this demo
for two reasons:
1. For some boxes, unfortunately, dialog returns the code for
ERROR when the user presses ESC (instead of the one chosen
for ESC). As these boxes only have an OK button, and an
exception is raised and correctly handled here in case of
real dialog errors, there is no point in testing the dialog
exit status (it can't be CANCEL as there is no CANCEL
button; it can't be ESC as unfortunately, the dialog makes
it appear as an error; it can't be ERROR as this is handled
in to raise an exception; therefore, it *is* OK).
2. To not clutter simple code with things that are
demonstrated elsewhere.
# d is supposed to be a Dialog instance
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
if code == d.DIALOG_CANCEL:
msg = "You chose cancel in the last dialog box. Do you want to " \
"exit this demo?"
msg = "You pressed ESC in the last dialog box. Do you want to " \
"exit this demo?"
# "No" or "ESC" will bring the user back to the demo.
# DIALOG_ERROR is propagated as an exception and caught in main().
# So we only need to handle OK here.
if d.yesno(msg) == d.DIALOG_OK:
return 0
return 1 # code is d.DIALOG_OK
def infobox_demo(d):
# Exit code thrown away to keey this demo code simple (however, real
# errors are propagated by an exception)
d.infobox("One moment, please. Just wasting some time here to "
"show you the infobox...")
def gauge_demo(d):
d.gauge_start("Progress: 0%", title="Still testing your patience...")
for i in range(1, 101):
if i < 50:
d.gauge_update(i, "Progress: %d%%" % i, update_text=1)
elif i == 50:
d.gauge_update(i, "Over %d%%. Good." % i, update_text=1)
elif i == 80:
d.gauge_update(i, "Yeah, this boring crap will be over Really "
"Soon Now.", update_text=1)
def yesno_demo(d):
# Return the answer given to the question (also specifies if ESC was
# pressed)
return d.yesno("Do you like this demo?")
def msgbox_demo(d, answer):
if answer == d.DIALOG_OK:
d.msgbox("Excellent! Press OK to see the source code.")
d.msgbox("Well, feel free to send your complaints to /dev/null!")
def textbox_demo(d):
d.textbox("", width=76)
def inputbox_demo(d):
# If the user presses Cancel, he is asked (by handle_exit_code) if he
# wants to exit the demo. We loop as long as he tells us he doesn't want
# to do so.
while 1:
(code, answer) = d.inputbox("What's your name?", init="Snow White")
if handle_exit_code(d, code):
return answer
def menu_demo(d):
while 1:
(code, tag) =
"What's your favorite day of the week?",
choices=[("Monday", "Being the first day of the week..."),
("Tuesday", "Comes after Monday"),
("Wednesday", "Before Thursday day"),
("Thursday", "Itself after Wednesday"),
("Friday", "The best day of all"),
("Saturday", "Well, I've had enough, thanks"),
("Sunday", "Let's rest a little bit")])
if handle_exit_code(d, code):
return tag
def checklist_demo(d):
while 1:
# We could put non-empty items here (not only the tag for each entry)
(code, tag) = d.checklist(text="What sandwich toppings do you like?",
height=15, width=54, list_height=7,
choices=[("Catsup", "", 0),
("Mustard", "", 0),
("Pesto", "", 0),
("Mayonaise", "", 1),
("Horse radish","", 1),
("Sun-dried tomatoes", "", 1)],
title="Do you prefer ham or spam?",
backtitle="And now, for something "
"completely different...")
if handle_exit_code(d, code):
return tag
def radiolist_demo(d):
while 1:
(code, tag) = d.radiolist(
"What's your favorite kind of sandwich?",
choices=[("Hamburger", "2 slices of bread, a steak...", 0),
("Hotdog", "doesn't bite any more", 0),
("Burrito", "no se lo que es", 0),
("Doener", "Huh?", 0),
("Falafel", "Erm...", 0),
("Bagel", "Of course!", 0),
("Big Mac", "Ah, that's easy!", 1),
("Whopper", "Erm, sorry", 0),
("Quarter Pounder", 'called "le Big Mac" in France', 0),
("Peanut Butter and Jelly", "Well, that's your own "
"business...", 0),
("Grilled cheese", "And nothing more?", 0)])
if handle_exit_code(d, code):
return tag
def calendar_demo(d):
while 1:
(code, date) = d.calendar("When do you think Debian sarge will be "
"released?", year=0)
if handle_exit_code(d, code):
return date
def passwordbox_demo(d):
while 1:
(code, password) = d.passwordbox("What is your root password, "
"so that I can crack your system "
"right now?")
if handle_exit_code(d, code):
return password
def comment_on_sarge_release_date(day, month, year):
if year < 2004 or (year == 2004 and month <= 3):
return "Mmm... what about a little tour on"
elif year == 2004 and month <= 4:
return """\
Damn, how optimistic! You don't know much about Debian, do you?"""
elif year == 2004 and month <= 7:
return """\
Well, good guess. But who knows what the future reserves to us? ;-)"""
elif year == 2004:
return """\
Oh, well. That's plausible. But please, please don't depress
other people with your pronostics... ;-)"""
return "Hey, you're a troll! (or do you know Debian *so* well? ;-)"
def scrollbox_demo(d, name, favorite_day, toppings, sandwich, date,
day, month, year = date
msg = """\
Here are some vital statistics about you:
Name: %s
Favorite day of the week: %s
Favorite sandwich toppings:%s
Favorite sandwich: %s
You estimate Debian sarge's release to happen around %04u-%02u-%02u.
Your root password is: ************************** (looks good!)""" \
% (name, favorite_day,
string.join([''] + toppings, "\n "),
sandwich, year, month, day,
comment_on_sarge_release_date(day, month, year))
d.scrollbox(msg, height=20, width=75, title="Great Report of the Year")
def fselect_demo(d):
while 1:
root_dir = os.sep # This is OK for UNIX systems
dir = os.getenv("HOME", root_dir)
# Make sure the directory we chose ends with os.sep() so that dialog
# shows its contents right away
if dir and dir[-1] != os.sep:
dir = dir + os.sep
(code, path) = d.fselect(dir, 10, 50,
title="Cute little file to show as "
"in a `tail -f'")
if handle_exit_code(d, code):
if not os.path.isfile(path):
d.scrollbox("Hmm. Didn't I ask you to select a *file*?",
width=50, height=10)
return path
def tailbox_demo(d, file):
d.tailbox(file, 20, 60, title="You are brave. You deserve the "
"right to rest, now." )
def demo():
# If you want to use Xdialog (pathnames are also OK for the 'dialog'
# argument)
# d = dialog.Dialog(dialog="Xdialog", compat="Xdialog")
d = dialog.Dialog(dialog="dialog")
d.add_persistent_args(["--backtitle", "pythondialog demo"])
answer = yesno_demo(d)
msgbox_demo(d, answer)
name = inputbox_demo(d)
favorite_day = menu_demo(d)
toppings = checklist_demo(d)
sandwich = radiolist_demo(d)
date = calendar_demo(d)
password = passwordbox_demo(d)
scrollbox_demo(d, name, favorite_day, toppings, sandwich, date, password)
Haha. You thought it was over. Wrong. Even More fun is to come!
(well, depending on your definition on "fun")
Now, please select a file you would like to see growing (or not...).""",
file = fselect_demo(d)
tailbox_demo(d, file)
Now, you're done. No, I'm not kidding.
So, why the hell are you sitting here instead of rushing on that EXIT
button? Ah, you did like the demo. Hmm... are you feeling OK? ;-)""",
def main():
"""This demo shows the main features of the pythondialog Dialog class.
except dialog.error, exc_instance:
sys.stderr.write("Error:\n\n%s\n" % exc_instance.complete_message())
if __name__ == "__main__": main()
This diff is collapsed.
#! /usr/bin/env python
# --- Setup script for pythondialog
# Copyright (c) 2002, 2003, 2004 Florent Rougon
# This file is part of pythondialog.
# pythondialog is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# pythondialog is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os, string, sys
from distutils.core import setup
# Note:
# The Distutils included in Python 2.1 don't understand the "license" keyword
# argument of setup correctly (they only understand licence); as I don't want
# to mispell it, if you run the Distutils from Python 2.1, you will get
# License: UNKNOWN. This problem does not appear with the version included in
# Python 2.2.
PACKAGE = "pythondialog"
VERSION = "2.7"
def main():
description="A Python interface to the UNIX dialog utility and "
"mostly-compatible programs",
# Doesn't work great with several authors...
author="Robb Shecter, Sultanbek Tezadov, Florent Rougon, Peter Astrand",
maintainer="Peter Astrand",
A Python interface to the UNIX dialog utility, designed to provide
an easy, pythonic and as complete as possible way to use the dialog
features from Python code.
Back-end programs that are almost compatible with dialog are also
supported if someone cares about them.""",
keywords=["dialog", "Xdialog", "whiptail", "text-mode interface"],
if __name__ == "__main__": main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment