peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

When do play() my Effect, I cant exit the program on KeyboardEvent #295

Closed remort closed 3 years ago

remort commented 3 years ago

Describe the bug If I run program throgh screen.play([Scene(effects=[Surface(screen=screen)])], repeat=False), I can't exit the program by catching the specific keyboardEvent.

Surface implements Effect interface.

To Reproduce Handling the button press in Surface I tried to do:

It seems that my effect (Surface) stops, and Screen got blank, but program never exits. Pressing any other key once more seems to complete screen.play(), and my program exits then.

Expected behavior Expected behavior is to finish play() after screen is close()d or scene is exit()ed and let program continue to the next command.

I can exit with sys.exit() right from my keyboard handler method of Surface effect, but it looks dirty.

Am I miss something?

System details (please complete the following information):

Additional context

peterbrittain commented 3 years ago

In order to stop the loop, you need to tell the Screen to stop playing, not the Scene. The way to do that is through Exceptions. See https://asciimatics.readthedocs.io/en/stable/widgets.html#exceptions for more info and contact_list.py for an example.

remort commented 3 years ago

Ok, got it. Works for me. Thank you.