[dialogwizard] ajout de la lib dialogwizard
Ignore-this: c07ebd286368479de93370a7dbfa765e darcs-hash:20090723203207-bd074-66c4713209814daab11becece91749a4e906dd64.gz
This commit is contained in:
parent
143558cb0e
commit
63bdff02a0
4 changed files with 1838 additions and 0 deletions
42
lib/dialogwizard/dialogwizard.py
Executable file
42
lib/dialogwizard/dialogwizard.py
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/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 form_step(self, title, enonce, form):
|
||||
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)
|
||||
if rc == 2: really_quit(dico)
|
||||
if rc == 1: raise PreviousStep
|
||||
for field, val in izip (form, res):
|
||||
dico[field[0]] = val
|
||||
return dico
|
||||
return Step(fn)
|
||||
|
||||
def select_step(self, title, enonce, var, choix):
|
||||
def fn(dico, default):
|
||||
rc, res = self.d.menu(enonce, choices = choix, title = title)
|
||||
if rc == 2: really_quit(dico)
|
||||
if rc == 1: raise PreviousStep
|
||||
dico[var] = res
|
||||
return dico
|
||||
return Step(fn)
|
Loading…
Add table
Add a link
Reference in a new issue