From 0d44a363eb5a0f54abdb3808a81e97d29bfdac80 Mon Sep 17 00:00:00 2001 From: Antoine Durand-Gasselin Date: Tue, 25 Aug 2009 16:42:04 +0200 Subject: [PATCH] [dialogwizard/dialogwizard] on prefere utiliser une methode generique pour verifier que l'appel a dialog s'est bien effectue Ignore-this: 4323b4c019e56d8381587b82e183908d darcs-hash:20090825144204-bd074-c765bda3efeedadc05914be0937530b27025cb33.gz --- lib/dialogwizard/dialog.py | 4 ++-- lib/dialogwizard/dialogwizard.py | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/dialogwizard/dialog.py b/lib/dialogwizard/dialog.py index 641e15b0..78c75f46 100644 --- a/lib/dialogwizard/dialog.py +++ b/lib/dialogwizard/dialog.py @@ -847,7 +847,7 @@ class Dialog: self._perform_no_options('--clear') def form(self, text, height=0, width=0, form_height=20, 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 @@ -874,7 +874,7 @@ class Dialog: for t in fields: if len(t[0]) > max_label_len: max_label_len = len(t[0]); - + line = 1 for t in fields: label = t[0] diff --git a/lib/dialogwizard/dialogwizard.py b/lib/dialogwizard/dialogwizard.py index 682ac690..95fe81f1 100755 --- a/lib/dialogwizard/dialogwizard.py +++ b/lib/dialogwizard/dialogwizard.py @@ -21,12 +21,15 @@ class DialogStepGenerator(): self.d = dialog.Dialog() self.d.add_persistent_args(["--backtitle", backtitle]) - def form_step(self, title, enonce, form): + 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) - if rc == 2: really_quit(dico) - if rc == 1: raise PreviousStep + 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 @@ -34,9 +37,8 @@ class DialogStepGenerator(): 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 + 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)