[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)

View file

@ -25,19 +25,33 @@ class DialogStepGenerator():
if rc == 2: really_quit(dico)
if rc == 1: raise PreviousStep
def _skim_choices(self, choices, dico):
return [ f for f in choices if f.get('show_cond', lambda x : True)(dico) ]
def form_step(self, title, enonce, form, **kw):
def fn(dico, default):
fields = [ ( field[1], default.get(field[0], dico.get(field[0], ''))) + field[2:] for field in form ]
rc, res = self.d.form(enonce, fields = fields, title=title, **kw)
sform = self._skim_choices(form, dico)
for field in sform:
item = default.get(field['var'], dico.get(field['var'], ''))
field['item'] = item
rc, res = self.d.form(enonce, fields = sform, title=title, **kw)
self._check_rc(rc)
for field, val in izip (form, res):
dico[field[0]] = val
for field, val in izip (sform, res):
dico[field['var']] = val
return dico
return Step(fn)
def select_step(self, title, enonce, var, choix, **kw):
def fn(dico, default):
rc, res = self.d.menu(enonce, choices = choix, title = title, **kw)
schoix = []
for c in choix:
try:
schoix.append((c[0], c[1]))
except Exception,e:
if c.get('show_cond', lambda x : True)(dico):
schoix.append((c['label'], c['item']))
print schoix
rc, res = self.d.menu(enonce, choices = schoix, title = title, **kw)
self._check_rc(rc)
dico[var] = res
return dico
@ -53,8 +67,14 @@ class DialogStepGenerator():
def checklist_step(self, title, enonce, liste):
def fn(dico, default):
choix = [var, txt, dico.get(var, 'off') for var, txt in liste]
rc, res = self.d.checklist(enonce, title = title, choices = choix, **kw)
sliste = []
for c in liste:
try:
sliste.append((c[0], c[1], dico.get(c[0], 'off')))
except Exception,e:
if c.get('show_cond', lambda x : True)(dico):
sliste.append((c['var'], c['item'], dico.get(c['var'], 'off')))
rc, res = self.d.checklist(enonce, title = title, choices = sliste, **kw)
self._check_rc(rc)
for tag, item, status in liste:
if tag in res: