from asciimatics.widgets import Layout, Label from .CeoFrame import CeoFrame class ConfirmView(CeoFrame): def __init__(self, screen, width, height, model): super().__init__( screen, height, width, model, 'Confirm', on_load=self._confirmview_on_load, title='Confirmation', escape_on_q=True, ) def _add_line(self, text: str = ''): layout = Layout([100]) self.add_layout(layout) layout.add_widget(Label(text, align='^')) def _add_pair(self, key: str, val: str): layout = Layout([10, 1, 10]) self.add_layout(layout) layout.add_widget(Label(key + ':', align='>'), 0) layout.add_widget(Label(val, align='<'), 2) def _confirmview_on_load(self): for _ in range(2): self._add_line() for line in self._model.confirm_lines: if isinstance(line, str): self._add_line(line) else: # assume tuple key, val = line self._add_pair(key, val) # fill the rest of the space self.add_layout(Layout([100], fill_frame=True)) kwargs = { 'back_btn': True, 'back_btn_text': 'No', 'next_btn_text': 'Yes', } if self._model.operations is not None: kwargs['next_scene'] = self._model.txn_view_name or 'Transaction' else: self.add_flash_message_layout() kwargs['on_next_excl'] = self._next self.add_buttons(**kwargs) self.fix() # OK so there's some weird bug somewhere which causes the buttons to be unselectable # if we add a new user, return to the Welcome screen, then try to renew a user. # This is a workaround for that. self.skip_reload = True self.reset() def _next(self): self.flash_message('Sending request...', force_update=True) try: self._model.resp = self._model.deferred_req() finally: self.clear_flash_message() next_scene = self._model.result_view_name or 'Result' self.go_to_next_scene(next_scene)