Skip to content

Commit

Permalink
Make replay pause at each user PATE command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-carciofini committed Feb 28, 2024
1 parent 30c470c commit c71fc9c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pate_binja/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ def ask_user(self, prompt: str, choices: list[str], replay: bool):
for i, e in enumerate(choices):
query += '\n {}'.format(e)
self.output_field.appendPlainText(query)
if not replay:
self.cmd_field.setText('')
self.cmd_field.setEnabled(True)
self.cmd_field.setFocus()
self.cmd_field.setText('')
self.cmd_field.setEnabled(True)
self.cmd_field.setFocus()


class GuiUserInteraction(pate.PateUserInteraction):
Expand All @@ -127,17 +126,20 @@ def __init__(self, pate_widget: PateWidget):
def ask_user(self, prompt: str, choices: list[str], replay_choice: Optional[str] = None) -> Optional[str]:
execute_on_main_thread_and_wait(lambda: self.pate_widget.ask_user(prompt, choices, replay_choice is not None))
if replay_choice:
execute_on_main_thread_and_wait(lambda: self.pate_widget.output_field.appendPlainText(f'Pate Command (replay): {replay_choice}\n'))
return replay_choice
# Wait for user to respond to prompt. This happens on the GUI thread.
execute_on_main_thread_and_wait(lambda: self.pate_widget.cmd_field.setText(replay_choice + ' (replay)'))
#Wait for user to respond to prompt. This happens on the GUI thread.
urc = self.pate_widget.user_response_condition
with urc:
while self.pate_widget.user_response is None:
urc.wait()
choice = self.pate_widget.user_response
self.pate_widget.user_response = None
execute_on_main_thread_and_wait(lambda: self.pate_widget.output_field.appendPlainText(f'Pate Command: {choice}\n'))
return choice
if replay_choice:
execute_on_main_thread_and_wait(lambda: self.pate_widget.output_field.appendPlainText(f'Pate Command: {replay_choice} (replay)\n'))
return replay_choice
else:
execute_on_main_thread_and_wait( lambda: self.pate_widget.output_field.appendPlainText(f'Pate Command: {choice}\n'))
return choice

def show_message(self, msg: str) -> None:
execute_on_main_thread_and_wait(lambda: self.pate_widget.output_field.appendPlainText(msg))
Expand Down

0 comments on commit c71fc9c

Please sign in to comment.