Created
January 25, 2021 22:30
-
-
Save awksedgreep/5791fcaf73239fd84c89ecbe1188c7d4 to your computer and use it in GitHub Desktop.
Multi frame asciimatics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asciimatics.event import KeyboardEvent | |
from asciimatics.widgets import Frame, Layout, MultiColumnListBox, Widget, Label, TextBox | |
from asciimatics.scene import Scene | |
from asciimatics.screen import Screen | |
from asciimatics.exceptions import ResizeScreenError, StopApplication, NextScene | |
import sys | |
class MainFrame(Frame): | |
def __init__(self, screen, has_border=True, name='MainFrame'): | |
super(MainFrame, self).__init__(screen, screen.height, screen.width, has_border=has_border, | |
name=name, can_scroll=False) | |
def process_event(self, event): | |
if isinstance(event, KeyboardEvent): | |
print(f"Processing key press {event.key_code}") | |
if event.key_code in [ord('q'), ord('Q'), Screen.ctrl("c")]: | |
raise StopApplication("User quit") | |
elif event.key_code in [ord('f'), ord('F')]: | |
raise NextScene('First') | |
elif event.key_code in [ord('s'), ord('S')]: | |
raise NextScene('Second') | |
class FirstFrame(MainFrame): | |
def __init__(self, screen): | |
super(FirstFrame, self).__init__(screen, | |
screen.height, | |
screen.width) | |
layout = Layout([1], fill_frame=True) | |
self.add_layout(layout) | |
layout.add_widget(Label("Header")) | |
layout.add_widget(Label("Body First Frame")) | |
layout.add_widget(Label("Footer")) | |
self.fix() | |
class SecondFrame(MainFrame): | |
def __init__(self, screen): | |
super(SecondFrame, self).__init__(screen, | |
screen.height, | |
screen.width) | |
layout = Layout([1], fill_frame=True) | |
self.add_layout(layout) | |
layout.add_widget(Label("Header")) | |
layout.add_widget(Label("Body Second Frame")) | |
layout.add_widget(Label("Footer")) | |
self.fix() | |
def demo(screen, scene): | |
scenes = [ | |
Scene([FirstFrame(screen)], -1, name="First"), | |
Scene([SecondFrame(screen)], -1, name="Second") | |
] | |
screen.play(scenes, stop_on_resize=True, start_scene=scene, allow_int=True) | |
last_scene = None | |
while True: | |
try: | |
Screen.wrapper(demo, catch_interrupt=True, arguments=[last_scene]) | |
sys.exit(0) | |
except ResizeScreenError as e: | |
last_scene = e.scene |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment