
Ignore-this: c07ebd286368479de93370a7dbfa765e darcs-hash:20090723203207-bd074-66c4713209814daab11becece91749a4e906dd64.gz
42 lines
1.3 KiB
Python
Executable file
42 lines
1.3 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 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)
|