Skip to content

Commit

Permalink
Return to initial prompt if the user cancels create/select config dir…
Browse files Browse the repository at this point in the history
…ectory
  • Loading branch information
mporcheron committed Jun 22, 2020
1 parent 560a6aa commit 29a9479
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
12 changes: 9 additions & 3 deletions nottreal/controllers/c_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def ready(self):
choose=WizardOption.CHOOSE_DIRECTORY,
method=self._set_config_directory,
default=str(Path.home()),
extras={'action': WizardOption.FILES_ACTION_OPEN},
restorable=False)
restorable=False,
extras={'action': WizardOption.FILES_ACTION_OPEN})
self.register_option(self._opt_config_dir)

self._opt_slots_on_tab_change = WizardOption(
Expand All @@ -90,6 +90,9 @@ def ready(self):
self.nottreal.view.wizard_window.show()

def init_prompt(self):
self._opt_config_dir_new.extras['on_cancel'] = self.init_prompt
self._opt_config_dir.extras['on_cancel'] = self.init_prompt

button_new_config = (
'new_config',
WizardAlert.Button(
Expand Down Expand Up @@ -127,6 +130,9 @@ def init_prompt(self):

self.router('wizard', 'show_alert', alert=alert)

self._opt_config_dir_new.extras['on_cancel'] = None
self._opt_config_dir.extras['on_cancel'] = None

def _new_config_directory(self, directory):
"""
Create a new configuration directory
Expand Down Expand Up @@ -175,7 +181,7 @@ def _set_config_directory(self, directory, is_initial_load=False):
'cancel',
WizardAlert.DefaultButton.BUTTON_CANCEL,
None)

button_new_config = (
'new_config',
WizardAlert.Button(
Expand Down
15 changes: 13 additions & 2 deletions nottreal/models/m_mvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,25 @@ class WizardOption:
CAT_OUTPUT {int} -- Identifier for options relating to the
visual output
FILES_ACTION_SAVE {int} -- Show a file for saving
FILE_ACTION_OPEN {int} -- Show a file for opening
FILES_ACTION_SAVE {int} -- Show a file for saving, add to
{extras} with key 'action
FILE_ACTION_OPEN {int} -- Show a file for opening, add to
{extras} with key 'action
FILES_IS_CANCELABLE {int} -- Nothing happens on cancel,
add to {extras} with key
'cancel'
FILES_IS_NOT_CANCELABLE {int} -- If a file dialog is
cancelled, reopen it,
add to {extras} with key
'cancel'
appstate {instance}-- App state controller
"""
CHOOSE_BOOLEAN, CHOOSE_SINGLE_CHOICE, CHOOSE_DIRECTORY = range(3)
CAT_CORE, CAT_WIZARD, CAT_VOICE, CAT_INPUT, CAT_OUTPUT = range(5)
FILES_ACTION_SAVE, FILES_ACTION_OPEN = range(10, 12)
FILES_IS_CANCELABLE, FILES_IS_NOT_CANCELABLE = range(12, 14)

appstate = None

Expand Down
23 changes: 19 additions & 4 deletions nottreal/views/v_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,25 @@ def _on_option_directory_triggered(self):
except AttributeError:
pass

response = dialog.exec_()
if response:
directory = dialog.selectedFiles()
option.change(directory[0])
try:
cancellable = option.extras['cancel'] \
== WizardOption.FILES_IS_CANCELABLE
except KeyError:
cancellable = True

while True:
response = dialog.exec_()
if response:
directory = dialog.selectedFiles()
option.change(directory[0])

if cancellable or response != QMessageBox.NoButton:
if response == QMessageBox.NoButton:
try:
option.extras['on_cancel']()
except KeyError:
pass
break

self.parent.disable_enter_press = False

Expand Down

0 comments on commit 29a9479

Please sign in to comment.