Commit 2c8a9a30 authored by Alon Swartz's avatar Alon Swartz

integrated "form and passwordform support" patch

patch origin:
    author:   Chris Dew - chrisdew at users.sourceforge.net
    url:      http://sourceforge.net/tracker/?atid=486715&group_id=58155&func=browse
    filename: patch_against_pythondialog-2.7.tar.gz
parent 5c57491d
......@@ -11,6 +11,10 @@ Upstream Author: Peter Astrand <peter@cendio.se>
Copyright: (C) 2000 Robb Shecter, Sultanbek Tezadov
(C) 2002, 2003, 2004 Florent Rougon
Patched by Alon Swartz <alon@turnkeylinux.org> and integrated patch
available from http://pythondialog.sourceforge.net authored by
Chris Dew <chrisdew@users.sourceforge.net>
License:
This package is free software; you can redistribute it and/or
......
......@@ -159,6 +159,36 @@ def checklist_demo(d):
return tag
def form_demo(d):
while 1:
(code, tag) = d.form(text="Which are your favourites?",
height=15, width=54, form_height=7,
fields=[("Colour", "", 10, 30),
("Rugby Team", "", 20),
("Car", "", 20),
("Celebrity", "", 20)],
title="A demo of the form dialog.",
backtitle="And now, for something "
"completely different...")
if handle_exit_code(d, code):
break
return tag
def passwordform_demo(d):
while 1:
(code, tag) = d.passwordform(text="Set your password",
height=15, width=54, form_height=7,
fields=[("Admin Password:", "", 10, 20),
(" Confirm:", "", 10, 20)],
title="A demo of the passwordform dialog.",
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(
......@@ -217,8 +247,8 @@ 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,
password):
def scrollbox_demo(d, name, favorite_day, toppings, favourites, passwords,
sandwich, date, password):
day, month, year = date
msg = """\
Here are some vital statistics about you:
......@@ -226,6 +256,8 @@ Here are some vital statistics about you:
Name: %s
Favorite day of the week: %s
Favorite sandwich toppings:%s
Favorites:%s
Passwords:%s
Favorite sandwich: %s
You estimate Debian sarge's release to happen around %04u-%02u-%02u.
......@@ -234,6 +266,8 @@ 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 "),
string.join([] + favourites, ", "),
string.join([] + passwords, ", confirmed "),
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")
......@@ -281,10 +315,12 @@ def demo():
name = inputbox_demo(d)
favorite_day = menu_demo(d)
toppings = checklist_demo(d)
favourites = form_demo(d)
passwords = passwordform_demo(d)
sandwich = radiolist_demo(d)
date = calendar_demo(d)
password = passwordbox_demo(d)
scrollbox_demo(d, name, favorite_day, toppings, sandwich, date, password)
scrollbox_demo(d, name, favorite_day, toppings, favourites, passwords, sandwich, date, password)
d.scrollbox("""\
Haha. You thought it was over. Wrong. Even More fun is to come!
......
......@@ -217,6 +217,7 @@ _common_args_syntax = {
"help": lambda enable: _simple_option("--help", enable),
"help_button": lambda enable: _simple_option("--help-button", enable),
"help_label": lambda string: ("--help-label", string),
"insecure": lambda enable: _simple_option("--insecure", enable),
"ignore": lambda enable: _simple_option("--ignore", enable),
"item_help": lambda enable: _simple_option("--item-help", enable),
"max_input": lambda size: ("--max-input", str(size)),
......@@ -466,6 +467,7 @@ class Dialog:
add_persistent_args
calendar
checklist
form
fselect
gauge_start
......@@ -477,6 +479,7 @@ class Dialog:
menu
msgbox
passwordbox
passwordform
radiolist
scrollbox
tailbox
......@@ -846,6 +849,116 @@ class Dialog:
"""
self._perform_no_options('--clear')
def form(self, text, height=20, width=50, form_height=20, fields=[], **kwargs):
"""Display a form dialog box.
text -- text to display in the box
height -- height of the box (minus the calendar height)
width -- width of the box
form_height -- height of the form
fields -- a list of tuples, each tuple has the form:
(label, item, len) or
(label, item, field_len, input_len)
it returns a tuple of the form (code, results), where results is a
list of the results.
Notable exceptions:
- any exception raised by self._perform()
- UnexpectedDialogOutput
- PythonDialogReModuleError
"""
cmd = ["--form", text, str(height), str(width), str(form_height)]
# find the longest label so we can put the input boxes at the
# correct offset
max_label_len = 0
for t in fields:
if len(t[0]) > max_label_len:
max_label_len = len(t[0]);
print "max_label_len == ", max_label_len
line = 1
for t in fields:
label = t[0]
item = t[1]
field_len = str(t[2])
if len(t) < 4:
input_len = field_len
else:
input_len = str(t[3])
cmd.extend(((label, str(line), "1", item, str(line), str(max_label_len + 2), field_len, input_len)))
line += 1
(code, output) = self._perform(*(cmd,), **kwargs)
if output:
return (code, string.split(output, '\n')[:-1])
else: # empty selection
return (code, [])
def passwordform(self, text, height=20, width=50, form_height=20, fields=[], **kwargs):
"""Display a form dialog box.
text -- text to display in the box
height -- height of the box (minus the calendar height)
width -- width of the box
form_height -- height of the form
fields -- a list of tuples, each tuple has the form:
(label, item, len) or
(label, item, field_len, input_len)
it returns a tuple of the form (code, results), where results is a
list of the results.
Notable exceptions:
- any exception raised by self._perform()
- UnexpectedDialogOutput
- PythonDialogReModuleError
"""
cmd = ["--passwordform", text, str(height), str(width), str(form_height)]
# find the longest label so we can put the input boxes at the
# correct offset
max_label_len = 0
for t in fields:
if len(t[0]) > max_label_len:
max_label_len = len(t[0]);
print "max_label_len == ", max_label_len
line = 1
for t in fields:
label = t[0]
item = t[1]
field_len = str(t[2])
if len(t) < 4:
input_len = field_len
else:
input_len = str(t[3])
cmd.extend(((label, str(line), "1", item, str(line), str(max_label_len + 2), field_len, input_len)))
line += 1
# typing in password without stars is really awkward
kwargs["insecure"] = True
(code, output) = self._perform(*(cmd,), **kwargs)
if output:
return (code, string.split(output, '\n')[:-1])
else: # empty selection
return (code, [])
def calendar(self, text, height=6, width=0, day=0, month=0, year=0,
**kwargs):
"""Display a calendar dialog box.
......
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