add global quit button

pull/20/head
Max Erenberg 1 year ago
parent 4aaf10b687
commit 0bf24230a0
  1. 32
      ceo/tui/CeoFrame.py
  2. 1
      ceo/tui/ConfirmView.py
  3. 1
      ceo/tui/ResultView.py
  4. 12
      ceo/tui/WelcomeView.py

@ -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")

@ -9,6 +9,7 @@ class ConfirmView(CeoFrame):
screen, height, width, model, 'Confirm',
on_load=self._confirmview_on_load, title='Confirmation',
has_dynamic_layouts=True,
escape_on_q=True,
)
def _add_line(self, text: str = ''):

@ -11,6 +11,7 @@ class ResultView(CeoFrame):
screen, height, width, model, 'Result',
on_load=self._resultview_on_load, title='Result',
has_dynamic_layouts=True,
escape_on_q=True,
)
# TODO: deduplicate this from ConfirmView

@ -1,18 +1,18 @@
import functools
from asciimatics.widgets import Frame, ListBox, Layout, Divider, Button, Label
from asciimatics.widgets import ListBox, Layout, Divider, Button, Label
from asciimatics.exceptions import NextScene, StopApplication
from .CeoFrame import CeoFrame
class WelcomeView(Frame):
class WelcomeView(CeoFrame):
def __init__(self, screen, width, height, model):
super().__init__(
screen,
height,
width,
screen, height, width, model, 'Welcome',
title='CSC Electronic Office',
escape_on_q=True,
)
self._model = model
members_menu_items = [
('Add member', 'AddUser'),
('Add club rep', 'AddUser'),

Loading…
Cancel
Save