
Ignore-this: a5ea5b8b8ef3e7c22c853c99c5acb0fb darcs-hash:20090825144326-bd074-675a61c9635905883d3a91cabd59fd8be82f67c0.gz
65 lines
2.1 KiB
Python
Executable file
65 lines
2.1 KiB
Python
Executable file
#!/usr/bin/env python
|
|
#
|
|
# DIALOGWIZARD.PY--
|
|
#
|
|
# Copyright (C) 2009 Antoine Durand-Gasselin
|
|
# Author: Antoine Durand-Gasselin <adg@crans.org>
|
|
#
|
|
|
|
from wizard import Step, PreviousStep, EndScenario
|
|
from itertools import izip
|
|
import dialog, time
|
|
|
|
def really_quit(dico):
|
|
raise EndScenario("game over!", data = dico)
|
|
|
|
class DialogStepGenerator():
|
|
u"""This class defines a step, that will prompt the user for various
|
|
fields."""
|
|
|
|
def __init__(self, backtitle):
|
|
self.d = dialog.Dialog()
|
|
self.d.add_persistent_args(["--backtitle", backtitle])
|
|
|
|
def _check_rc(self, rc):
|
|
if rc == 2: really_quit(dico)
|
|
if rc == 1: raise PreviousStep
|
|
|
|
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)
|
|
self._check_rc(rc)
|
|
for field, val in izip (form, res):
|
|
dico[field[0]] = 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)
|
|
self._check_rc(rc)
|
|
dico[var] = res
|
|
return dico
|
|
return Step(fn)
|
|
|
|
def input_step(self, title, enonce, var, **kw):
|
|
def fn(dico, default):
|
|
rc, res = self.d.inputbox(enonce, title = title, init = dico.get(var, ''), **kw)
|
|
self._check_rc(rc)
|
|
dico[var] = res
|
|
return dico
|
|
return Step(fn)
|
|
|
|
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)
|
|
self._check_rc(rc)
|
|
for tag, item, status in liste:
|
|
if tag in res:
|
|
dico[tag] = 'on'
|
|
else:
|
|
dico[tag] = 'off'
|
|
return dico
|
|
return Step(fn)
|