From aeb95900f10211f2d3c8ffead154a44121a2d5b5 Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Mon, 20 Aug 2012 13:06:59 +0300 Subject: [PATCH] Implement a WizardExit exception in dialog_wizard This exception can be used by the WizardPage instances to exit the wizard. --- image_creator/dialog_wizard.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/image_creator/dialog_wizard.py b/image_creator/dialog_wizard.py index 693588f..636292e 100644 --- a/image_creator/dialog_wizard.py +++ b/image_creator/dialog_wizard.py @@ -44,6 +44,10 @@ from image_creator.output.cli import OutputWthProgress PAGE_WIDTH = 70 +class WizardExit(Exception): + pass + + class Wizard: def __init__(self, session): self.session = session @@ -56,7 +60,10 @@ class Wizard: def run(self): idx = 0 while True: - idx += self.pages[idx].run(self.session, idx, len(self.pages)) + try: + idx += self.pages[idx].run(self.session, idx, len(self.pages)) + except WizardExit: + return False if idx >= len(self.pages): break @@ -69,7 +76,6 @@ class Wizard: class WizardPage: NEXT = 1 PREV = -1 - EXIT = -255 def run(self, session, index, total): raise NotImplementedError @@ -124,7 +130,7 @@ class WizardYesNoPage(WizardPage): if ret == d.DIALOG_CANCEL: return self.PREV elif ret == d.DIALOG_EXTRA: - return self.EXIT + raise WizardExit elif ret == d.DIALOG_OK: return self.NEXT -- 1.7.10.4