Handle exceptions in better way, enable to return to main screen many times.

This commit is contained in:
slush0 2016-04-28 23:48:59 +02:00 committed by Pavol Rusnak
parent ab9141dd95
commit 92eeac3612
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
1 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import sys
import utime
_new_layout = None
_current_layout = None
@ -15,17 +16,18 @@ def set_main(main_layout):
global _new_layout
global _current_layout
_current_layout = main_layout
_current_layout = main_layout()
while True:
try:
_current_layout = yield from _current_layout
except Exception as e:
sys.print_exception(e)
sys.exit()
utime.sleep(1) # Don't produce wall of exceptions
# if _current_layout == main_layout:
# # Main layout thrown exception, what to do?
# _current_layout = main_layout
# continue
# sys.exit()
_current_layout = main_layout()
continue
if _new_layout != None:
print("Switching to new layout %s" % _new_layout)