Skip to content

Commit 5b99df0

Browse files
committed
support for catching QuitWizard exception
1 parent 2b6714b commit 5b99df0

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

‎paths_cli/wizard/wizard.py‎

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
FILE_LOADING_ERROR_MSG, RestartObjectException
1010
)
1111
from paths_cli.wizard.joke import name_joke
12-
from paths_cli.wizard.helper import Helper
12+
from paths_cli.wizard.helper import Helper, QuitWizard
1313
from paths_cli.compiling.tools import custom_eval
1414

1515
import shutil
@@ -313,13 +313,33 @@ def run_wizard(self):
313313
# TODO: next line is only temporary
314314
self.say("Today I'll help you set up a 2-state TPS simulation.")
315315
self._patch() # try to hide the slowness of our first import
316-
for step in self.steps:
317-
req = step.store_name, step.minimum, step.maximum
318-
do_another = True
319-
while do_another:
320-
do_another = self._do_one(step, req)
321-
storage = self.get_storage()
322-
self.save_to_file(storage)
316+
try:
317+
for step in self.steps:
318+
req = step.store_name, step.minimum, step.maximum
319+
do_another = True
320+
while do_another:
321+
do_another = self._do_one(step, req)
322+
except QuitWizard:
323+
do_save = self._ask_save()
324+
else:
325+
do_save = True
326+
327+
if do_save:
328+
storage = self.get_storage()
329+
self.save_to_file(storage)
330+
else:
331+
self.say("Goodbye! 👋")
332+
333+
@get_object
334+
def _ask_save(self):
335+
do_save_char = self.ask("Before quitting, would you like to "
336+
"the objects you've created so far?")
337+
try:
338+
do_save = yes_no(do_save_char)
339+
except Exception:
340+
self.bad_input("Sorry, I didn't understance that.")
341+
return None
342+
return do_save
323343

324344

325345
# FIXED_LENGTH_TPS_WIZARD

0 commit comments

Comments
 (0)