|
9 | 9 | FILE_LOADING_ERROR_MSG, RestartObjectException |
10 | 10 | ) |
11 | 11 | 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 |
13 | 13 | from paths_cli.compiling.tools import custom_eval |
14 | 14 |
|
15 | 15 | import shutil |
@@ -313,13 +313,33 @@ def run_wizard(self): |
313 | 313 | # TODO: next line is only temporary |
314 | 314 | self.say("Today I'll help you set up a 2-state TPS simulation.") |
315 | 315 | 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 save " |
| 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 |
323 | 343 |
|
324 | 344 |
|
325 | 345 | # FIXED_LENGTH_TPS_WIZARD |
|
0 commit comments