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', ) 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)) if self._model.operations is not None: next_scene = 'Transaction' else: next_scene = 'Result' self.add_buttons( back_btn=True, back_btn_text='No', next_scene=next_scene, next_scene_text='Yes') self.fix()