|
|
|
@ -1,5 +1,8 @@ |
|
|
|
|
from asciimatics.exceptions import NextScene |
|
|
|
|
from asciimatics.widgets import Frame, Layout, Divider, Button, Label |
|
|
|
|
from asciimatics.event import KeyboardEvent |
|
|
|
|
from asciimatics.exceptions import NextScene, StopApplication |
|
|
|
|
from asciimatics.screen import Screen |
|
|
|
|
from asciimatics.widgets import Frame, Layout, Divider, Button, Label, \ |
|
|
|
|
PopUpDialog |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CeoFrame(Frame): |
|
|
|
@ -14,6 +17,7 @@ class CeoFrame(Frame): |
|
|
|
|
title=None, |
|
|
|
|
save_data=False, # whether to save widget state for resizing |
|
|
|
|
has_dynamic_layouts=False, # whether layouts are created on load |
|
|
|
|
escape_on_q=False, # whether to quit when 'q' is pressed |
|
|
|
|
): |
|
|
|
|
super().__init__( |
|
|
|
|
screen, |
|
|
|
@ -30,6 +34,9 @@ class CeoFrame(Frame): |
|
|
|
|
self._name = name |
|
|
|
|
self._loaded = False |
|
|
|
|
self._has_dynamic_layouts = has_dynamic_layouts |
|
|
|
|
self._quit_keys = [Screen.KEY_ESCAPE] |
|
|
|
|
if escape_on_q: |
|
|
|
|
self._quit_keys.append(ord('q')) |
|
|
|
|
# sanity check |
|
|
|
|
if save_data: |
|
|
|
|
assert name in model.viewdata |
|
|
|
@ -138,3 +145,24 @@ class CeoFrame(Frame): |
|
|
|
|
|
|
|
|
|
def clear_flash_message(self): |
|
|
|
|
self.flash_message('') |
|
|
|
|
|
|
|
|
|
def process_event(self, event): |
|
|
|
|
if not isinstance(event, KeyboardEvent): |
|
|
|
|
return super().process_event(event) |
|
|
|
|
c = event.key_code |
|
|
|
|
# Stop on 'q' or 'Esc' |
|
|
|
|
if c in self._quit_keys: |
|
|
|
|
self._scene.add_effect(PopUpDialog( |
|
|
|
|
self.screen, |
|
|
|
|
'Are you sure you want to quit?', |
|
|
|
|
['Yes', 'No'], |
|
|
|
|
has_shadow=True, |
|
|
|
|
on_close=self._quit_on_yes, |
|
|
|
|
)) |
|
|
|
|
return super().process_event(event) |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def _quit_on_yes(selected): |
|
|
|
|
# Yes is the first button |
|
|
|
|
if selected == 0: |
|
|
|
|
raise StopApplication("User terminated app") |
|
|
|
|