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

initial import of pythondialog_2.7

parents
Peter Astrand <peter@cendio.se> (current maintainer)
Robb Shecter <robb@acm.org>
Sultanbek Tezadov (http://sultan.da.ru/)
Florent Rougon <flo@via.ecp.fr>
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 dialog.py.
import commands
envvar_settings_list = []
if new_environ.has_key("DIALOGRC"):
envvar_settings_list.append(
"DIALOGRC='%s'" % new_environ["DIALOGRC"])
for var in _dialog_exit_status_vars.keys():
varname = "DIALOG_" + var
envvar_settings_list.append(
"%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), ""))
REQUIREMENTS
------------
Python 2.2 or newer.
INSTALLATION
------------
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 setup.py---these are described in
detail in the "Installing Python Modules" chapter of the Python
documentation.
- a) 1) type:
python ./setup.py build
2) then, as root:
python ./setup.py 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).
OR
b) type, as root:
python ./setup.py 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".
UNINSTALLATION
--------------
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)".
include COPYING INSTALL AUTHORS TODO DEBUGGING demo.py
include MANIFEST.in
# global-exclude *~
Metadata-Version: 1.0
Name: pythondialog
Version: 2.7
Summary: A Python interface to the UNIX dialog utility and mostly-compatible programs
Home-page: http://pythondialog.sourceforge.net/
Author: Peter Astrand
Author-email: peter@cendio.se
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
Overview
--------
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 http://dickey.his.com/dialog/dialog.html. 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 demo.py:
python demo.py
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.
Documentation
-------------
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 dialog.py 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
directory.
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 http://xdialog.free.fr/) 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 demo.py 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).
Troubleshooting
---------------
* 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'
program.
History
-------
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
version.
* 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
# demo.py --- 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
dialog).
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
FAST_DEMO = 0
# 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 dialog.py 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?"
else:
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:
sys.exit(0)
return 0
else:
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...")
if FAST_DEMO:
time.sleep(0.5)
else:
time.sleep(3)
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)
else:
d.gauge_update(i)
if FAST_DEMO:
time.sleep(0.01)
else:
time.sleep(0.1)
d.gauge_stop()
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.")
else:
d.msgbox("Well, feel free to send your complaints to /dev/null!")
def textbox_demo(d):
d.textbox("demo.py", 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):
break
return answer
def menu_demo(d):
while 1:
(code, tag) = d.menu(
"What's your favorite day of the week?",
width=60,
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):
break
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):
break
return tag
def radiolist_demo(d):
while 1:
(code, tag) = d.radiolist(
"What's your favorite kind of sandwich?",
width=65,
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):
break
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):
break
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):
break
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 http://www.debian.org/?"
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... ;-)"""
else:
return "Hey, you're a troll! (or do you know Debian *so* well? ;-)"
def scrollbox_demo(d, name, favorite_day, toppings, sandwich, date,
password):
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.
%s
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)
else:
break
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"])
infobox_demo(d)
gauge_demo(d)
answer = yesno_demo(d)
msgbox_demo(d, answer)
textbox_demo(d)
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)
d.scrollbox("""\
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...).""",
width=75)
file = fselect_demo(d)
tailbox_demo(d, file)
d.scrollbox("""\
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? ;-)""",
width=75)
def main():
"""This demo shows the main features of the pythondialog Dialog class.
"""
try:
demo()
except dialog.error, exc_instance:
sys.stderr.write("Error:\n\n%s\n" % exc_instance.complete_message())
sys.exit(1)
sys.exit(0)
if __name__ == "__main__": main()
This diff is collapsed.
[sdist]
formats=bztar,gztar,zip
[bdist]
formats=bztar,gztar,zip
[install]
prefix=/usr/local
#! /usr/bin/env python
# setup.py --- 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# 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():
setup(name=PACKAGE,
version=VERSION,
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",
author_email="robb@acm.org, http://sultan.da.ru/, flo@via.ecp.fr",
maintainer="Peter Astrand",
maintainer_email="peter@cendio.se",
url="http://pythondialog.sourceforge.net/",
license="LGPL",
platforms="UNIX",
long_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"],
py_modules=["dialog"])
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