[lib/dialogwizard] on peut mettre des champs plus élaborés
Ignore-this: 197a121bac23ae72a086535cc612311c darcs-hash:20090906134550-bd074-801938dc1daca12012adb24aeb4bff939ab75728.gz
This commit is contained in:
parent
feaf2215e6
commit
d79f7ec2f0
3 changed files with 80 additions and 97 deletions
|
@ -45,7 +45,7 @@ from ldap_crans import crans_ldap, script_utilisateur#, blacklist_items, ann_sco
|
||||||
sys.path.append('/usr/scripts')
|
sys.path.append('/usr/scripts')
|
||||||
from lib.dialogwizard.wizard import Scenario, Running, step_scenario, unit_scenario
|
from lib.dialogwizard.wizard import Scenario, Running, step_scenario, unit_scenario
|
||||||
from lib.dialogwizard.dialogwizard import DialogStepGenerator
|
from lib.dialogwizard.dialogwizard import DialogStepGenerator
|
||||||
from ldap_crans import Adherent #, AssociationCrans, Club
|
from ldap_crans import Adherent #, AssociationCrans, Club
|
||||||
# from ldap_crans import Machine, MachineFixe, MachineWifi, MachineCrans, BorneWifi
|
# from ldap_crans import Machine, MachineFixe, MachineWifi, MachineCrans, BorneWifi
|
||||||
# import user_tests
|
# import user_tests
|
||||||
|
|
||||||
|
@ -71,16 +71,17 @@ dsgen = DialogStepGenerator(u'Gestion des adhérents et machines du Crans')
|
||||||
|
|
||||||
prompt_new_adher = \
|
prompt_new_adher = \
|
||||||
dsgen.form_step (u"Inscription adhérent", '',
|
dsgen.form_step (u"Inscription adhérent", '',
|
||||||
[('nom', 'Nom :', 20),
|
[{'var': 'nom', 'label': 'Nom :', 'field_len': 20},
|
||||||
('prenom', u'Prénom :', 20),
|
{'var': 'prenom', 'label': u'Prénom :', 'field_len': 20},
|
||||||
('tel', u'Numéro de téléphone', 13),
|
{'var': 'tel', 'label': u'Numéro de téléphone', 'field_len': 13},
|
||||||
('chbre', u'Chambre :', 5) ])
|
{'var': 'chbre', 'label': u'Chambre :', 'field_len': 5} ])
|
||||||
|
|
||||||
prompt_addr_ext = \
|
prompt_addr_ext = \
|
||||||
dsgen.form_step (u"Adresse extérieure de %(nom)s", '',
|
dsgen.form_step (u"Adresse extérieure de %(nom)s", '',
|
||||||
[('addr1', 'Adresse', 40), ('addr2', '', 40),
|
[{'var': 'addr1', 'label': 'Adresse', 'field_len': 40},
|
||||||
('addr3', 'Code Postal :', 6),
|
{'var': 'addr2', 'label': '', 'field_len': 40},
|
||||||
('addr4', 'Ville :', 20)])
|
{'var': 'addr3', 'label': 'Code Postal :', 'field_len': 6},
|
||||||
|
{'var': 'addr4', 'label': 'Ville :', 'field_len': 20}])
|
||||||
|
|
||||||
def prompt_etudes(name):
|
def prompt_etudes(name):
|
||||||
etab_step = \
|
etab_step = \
|
||||||
|
@ -137,7 +138,7 @@ def prompt_etudes(name):
|
||||||
u'Section :',
|
u'Section :',
|
||||||
'etud3')
|
'etud3')
|
||||||
|
|
||||||
section1_step = \
|
section_step = \
|
||||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||||
u'Choisissez la section :',
|
u'Choisissez la section :',
|
||||||
'etud3',
|
'etud3',
|
||||||
|
@ -145,52 +146,24 @@ def prompt_etudes(name):
|
||||||
("A1", "Mathématiques"),
|
("A1", "Mathématiques"),
|
||||||
("A2", "Physique fondamentale"),
|
("A2", "Physique fondamentale"),
|
||||||
("A''2", "Chimie"),
|
("A''2", "Chimie"),
|
||||||
|
{'label': "A'2", 'item': "Physique appliquée",
|
||||||
|
'show_cond': (lambda d: d['etud2'] in ['3','4'])},
|
||||||
("A3", "Biochimie"),
|
("A3", "Biochimie"),
|
||||||
("B123", "Technologie mécanique"),
|
{'label': "B123", 'item':"Technologie mécanique",
|
||||||
|
'show_cond': (lambda d: d['etud2'] == '1') },
|
||||||
|
{'label': "B1", 'item': "Mécanique",
|
||||||
|
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||||
|
{'label': "B2", 'item': "Génie civil",
|
||||||
|
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||||
|
{'label': "B3", 'item': "Génie mécanique",
|
||||||
|
'show_cond': (lambda d: d['etud2'] in ['2','3','4'])},
|
||||||
("EEA", "Électronique, électrotechnique et automatique"),
|
("EEA", "Électronique, électrotechnique et automatique"),
|
||||||
("C", "Art et création industrielle"),
|
("C", "Art et création industrielle"),
|
||||||
("D2", "Economie gestion"),
|
("D2", "Economie gestion"),
|
||||||
("D3", "Sciences sociales"),
|
("D3", "Sciences sociales"),
|
||||||
("E", "Anglais") ])
|
("E", "Anglais") ])
|
||||||
|
|
||||||
section2_step = \
|
labo_step = \
|
||||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
|
||||||
u'Choisissez la section :',
|
|
||||||
'etud3',
|
|
||||||
[ ("A0", "Informatique"),
|
|
||||||
("A1", "Mathématiques"),
|
|
||||||
("A2", "Physique fondamentale"),
|
|
||||||
("A''2", "Chimie"),
|
|
||||||
("A3", "Biochimie"),
|
|
||||||
("B1", "Mécanique"),
|
|
||||||
("B2", "Génie civil"),
|
|
||||||
("B3", "Génie mécanique"),
|
|
||||||
("EEA", "Électronique, électrotechnique et automatique"),
|
|
||||||
("C", "Art et création industrielle"),
|
|
||||||
("D2", "Economie gestion"),
|
|
||||||
("D3", "Sciences sociales"),
|
|
||||||
("E", "Anglais") ])
|
|
||||||
|
|
||||||
section3_step = \
|
|
||||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
|
||||||
u'Choisissez la section :',
|
|
||||||
'etud3',
|
|
||||||
[ ("A0", "Informatique"),
|
|
||||||
("A1", "Mathématiques"),
|
|
||||||
("A2", "Physique fondamentale"),
|
|
||||||
("A'2", "Physique appliquée"),
|
|
||||||
("A''2", "Chimie"),
|
|
||||||
("A3", "Biochimie"),
|
|
||||||
("B1", "Mécanique"),
|
|
||||||
("B2", "Génie civil"),
|
|
||||||
("B3", "Génie mécanique"),
|
|
||||||
("B4", "Génie électrique"),
|
|
||||||
("C", "Art et création industrielle"),
|
|
||||||
("D2", "Economie gestion"),
|
|
||||||
("D3", "Sciences sociales"),
|
|
||||||
("E", "Anglais") ])
|
|
||||||
|
|
||||||
section5_step = \
|
|
||||||
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
dsgen.select_step(u'Études de %(nom)s (3/3)',
|
||||||
u'Choisissez le laboratoire :',
|
u'Choisissez le laboratoire :',
|
||||||
'etud3',
|
'etud3',
|
||||||
|
@ -211,15 +184,9 @@ def prompt_etudes(name):
|
||||||
|
|
||||||
ens_scenar = Scenario()
|
ens_scenar = Scenario()
|
||||||
ens_scenar.nest(year_ens_step)
|
ens_scenar.nest(year_ens_step)
|
||||||
ens_scenar.case((lambda d: d['etud2']),
|
ens_scenar.branch((lambda d: d['etud2'] in ['1','2','3','4']),
|
||||||
{ '1': step_scenario(section1_step),
|
step_scenario(section_step),
|
||||||
'2': step_scenario(section2_step),
|
step_scenario(labo_step))
|
||||||
'3': step_scenario(section3_step),
|
|
||||||
'4': step_scenario(section3_step),
|
|
||||||
'5': step_scenario(section5_step),
|
|
||||||
'6': step_scenario(section5_step),
|
|
||||||
'7': step_scenario(section5_step) },
|
|
||||||
fallback = step_scenario(section_step))
|
|
||||||
|
|
||||||
other_etab_scenar = Scenario()
|
other_etab_scenar = Scenario()
|
||||||
other_etab_scenar.nest(year_step)
|
other_etab_scenar.nest(year_step)
|
||||||
|
@ -234,16 +201,16 @@ def prompt_etudes(name):
|
||||||
|
|
||||||
return etudes_scenar
|
return etudes_scenar
|
||||||
|
|
||||||
prompt_connexion = \
|
# prompt_connexion = \
|
||||||
dsgen.form_step (u"Type de connexion",
|
# dsgen.form_step (u"Type de connexion",
|
||||||
u'Inscription adhérent',
|
# u'Inscription adhérent',
|
||||||
'typ', [('1', 'Adhésion'),
|
# 'typ', [('1', 'Adhésion'),
|
||||||
('2', 'Inscription gratuite')])
|
# ('2', 'Inscription gratuite')])
|
||||||
|
|
||||||
prompt_papiers = \
|
prompt_papiers = \
|
||||||
dsgen.checklist_step('', u'État administratif de %(nom)s',
|
dsgen.checklist_step('', u'État administratif de %(nom)s',
|
||||||
[('carte', u"Carte d'étudiant %s fourniee" % ann_scol),
|
[('carte', u"Carte d'étudiant %s-%s fourniee" % (ann_scol, ann_scol+1)),
|
||||||
('paiement%s' % this_year, u'Cotisation %s réglée et charte signée' % ann_scol),
|
('paiement%s' % ann_scol, u'Cotisation %s réglée et charte signée' % ann_scol),
|
||||||
('chartema', u'Charte des membres actifs signée')])
|
('chartema', u'Charte des membres actifs signée')])
|
||||||
|
|
||||||
prompt_login = \
|
prompt_login = \
|
||||||
|
@ -252,7 +219,7 @@ prompt_login = \
|
||||||
|
|
||||||
prompt_mailaddress = \
|
prompt_mailaddress = \
|
||||||
dsgen.input_step(u'Addresse mail extérieure de %(nom)s',
|
dsgen.input_step(u'Addresse mail extérieure de %(nom)s',
|
||||||
'')
|
'', 'mail')
|
||||||
|
|
||||||
dummy_scenar = Scenario()
|
dummy_scenar = Scenario()
|
||||||
dummy_scenar.nest(prompt_new_adher)
|
dummy_scenar.nest(prompt_new_adher)
|
||||||
|
|
|
@ -845,16 +845,16 @@ class Dialog:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._perform_no_options('--clear')
|
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.
|
"""Display a form dialog box.
|
||||||
|
|
||||||
text -- text to display in the box
|
text -- text to display in the box
|
||||||
height -- height of the box
|
height -- height of the box
|
||||||
width -- width of the box
|
width -- width of the box
|
||||||
form_height -- height of the form
|
form_height -- height of the form
|
||||||
fields -- a list of tuples, each tuple has the form:
|
fields -- a list of dict, each dict must have the fields
|
||||||
(label, item, field_len, [input_len, lpos, ipos])
|
label, item, field_len, and may have the fields
|
||||||
where lpos, ipos are two two-tuples containing y and x positions for label and item
|
input_len, xlpos, ylpos, xipos, yipos
|
||||||
auto_place -- boolean allowing automatic placement of items
|
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
|
||||||
|
@ -864,36 +864,32 @@ class Dialog:
|
||||||
- any exception raised by self._perform()
|
- any exception raised by self._perform()
|
||||||
- UnexpectedDialogOutput
|
- UnexpectedDialogOutput
|
||||||
- PythonDialogReModuleError
|
- PythonDialogReModuleError
|
||||||
|
"""
|
||||||
"""
|
if form_height == 'auto':
|
||||||
|
form_height = len (fields)
|
||||||
cmd = ["--form", text, str(height), str(width), str(form_height)]
|
cmd = ["--form", text, str(height), str(width), str(form_height)]
|
||||||
|
|
||||||
# find the longest label so we can put the input boxes at the
|
# find the longest label so we can put the input boxes at the
|
||||||
# correct offset
|
# correct offset
|
||||||
max_label_len = 0
|
max_label_len = 0
|
||||||
for t in fields:
|
for t in fields:
|
||||||
if len(t[0]) > max_label_len:
|
if len(t['label']) > max_label_len:
|
||||||
max_label_len = len(t[0]);
|
max_label_len = len(t['label']);
|
||||||
|
|
||||||
line = 1
|
line = 1
|
||||||
for t in fields:
|
for t in fields:
|
||||||
label = t[0]
|
try:
|
||||||
item = t[1]
|
l = [ t['label'] ]
|
||||||
field_len = str(t[2])
|
if auto_place:
|
||||||
if len(t) < 4:
|
l += [line, 1, t.get('item',''), line, max_label_len + 2]
|
||||||
input_len = field_len
|
|
||||||
else:
|
else:
|
||||||
input_len = str(t[3])
|
l += [ t['ylpos'], t['xlpos'], t.get('item', ''), t['yipos'], t['xipos'] ]
|
||||||
if auto_place or len(t) < 6:
|
l += [ t['field_len'], t.get('input_len', '') ]
|
||||||
ylpos = line
|
l = [ unicode(f) for f in l ]
|
||||||
xlpos = 1
|
except Exception, e:
|
||||||
yipos = line
|
raise e
|
||||||
xipos = max_label_len + 2
|
|
||||||
else:
|
|
||||||
ylpos, xlpos = t[4]
|
|
||||||
yipos, xipos = t[5]
|
|
||||||
|
|
||||||
cmd.extend(((label, str(ylpos), str(xlpos), item, str(yipos), str(xipos), field_len, input_len)))
|
cmd += l
|
||||||
line += 1
|
line += 1
|
||||||
|
|
||||||
(code, output) = self._perform(*(cmd,), **kwargs)
|
(code, output) = self._perform(*(cmd,), **kwargs)
|
||||||
|
|
|
@ -25,19 +25,33 @@ class DialogStepGenerator():
|
||||||
if rc == 2: really_quit(dico)
|
if rc == 2: really_quit(dico)
|
||||||
if rc == 1: raise PreviousStep
|
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 form_step(self, title, enonce, form, **kw):
|
||||||
def fn(dico, default):
|
def fn(dico, default):
|
||||||
fields = [ ( field[1], default.get(field[0], dico.get(field[0], ''))) + field[2:] for field in form ]
|
sform = self._skim_choices(form, dico)
|
||||||
rc, res = self.d.form(enonce, fields = fields, title=title, **kw)
|
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)
|
self._check_rc(rc)
|
||||||
for field, val in izip (form, res):
|
for field, val in izip (sform, res):
|
||||||
dico[field[0]] = val
|
dico[field['var']] = val
|
||||||
return dico
|
return dico
|
||||||
return Step(fn)
|
return Step(fn)
|
||||||
|
|
||||||
def select_step(self, title, enonce, var, choix, **kw):
|
def select_step(self, title, enonce, var, choix, **kw):
|
||||||
def fn(dico, default):
|
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)
|
self._check_rc(rc)
|
||||||
dico[var] = res
|
dico[var] = res
|
||||||
return dico
|
return dico
|
||||||
|
@ -53,8 +67,14 @@ class DialogStepGenerator():
|
||||||
|
|
||||||
def checklist_step(self, title, enonce, liste):
|
def checklist_step(self, title, enonce, liste):
|
||||||
def fn(dico, default):
|
def fn(dico, default):
|
||||||
choix = [var, txt, dico.get(var, 'off') for var, txt in liste]
|
sliste = []
|
||||||
rc, res = self.d.checklist(enonce, title = title, choices = choix, **kw)
|
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)
|
self._check_rc(rc)
|
||||||
for tag, item, status in liste:
|
for tag, item, status in liste:
|
||||||
if tag in res:
|
if tag in res:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue