[lib/dialogwizard] on peut mettre des champs plus élaborés

Ignore-this: 197a121bac23ae72a086535cc612311c

darcs-hash:20090906134550-bd074-801938dc1daca12012adb24aeb4bff939ab75728.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-09-06 15:45:50 +02:00
parent feaf2215e6
commit d79f7ec2f0
3 changed files with 80 additions and 97 deletions

View file

@ -845,55 +845,51 @@ class Dialog:
"""
self._perform_no_options('--clear')
def form(self, text, height=0, width=0, form_height=20, fields=[], auto_place=True, **kwargs):
def form(self, text, height=0, width=0, form_height='auto', fields=[], auto_place=True, **kwargs):
"""Display a form dialog box.
text -- text to display in the box
height -- height of the box
width -- width of the box
form_height -- height of the form
fields -- a list of tuples, each tuple has the form:
(label, item, field_len, [input_len, lpos, ipos])
where lpos, ipos are two two-tuples containing y and x positions for label and item
fields -- a list of dict, each dict must have the fields
label, item, field_len, and may have the fields
input_len, xlpos, ylpos, xipos, yipos
auto_place -- boolean allowing automatic placement of items
it returns a tuple of the form (code, results), where results is a
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
"""
"""
if form_height == 'auto':
form_height = len (fields)
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]);
if len(t['label']) > max_label_len:
max_label_len = len(t['label']);
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])
if auto_place or len(t) < 6:
ylpos = line
xlpos = 1
yipos = line
xipos = max_label_len + 2
else:
ylpos, xlpos = t[4]
yipos, xipos = t[5]
try:
l = [ t['label'] ]
if auto_place:
l += [line, 1, t.get('item',''), line, max_label_len + 2]
else:
l += [ t['ylpos'], t['xlpos'], t.get('item', ''), t['yipos'], t['xipos'] ]
l += [ t['field_len'], t.get('input_len', '') ]
l = [ unicode(f) for f in l ]
except Exception, e:
raise e
cmd.extend(((label, str(ylpos), str(xlpos), item, str(yipos), str(xipos), field_len, input_len)))
cmd += l
line += 1
(code, output) = self._perform(*(cmd,), **kwargs)