Create attractive VASL scenarios, with loads of useful information embedded to assist with game play.
https://vasl-templates.org
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
""" Miscellaneous utilities. """
|
|
|
|
import functools
|
|
import logging
|
|
import traceback
|
|
|
|
# ---------------------------------------------------------------------
|
|
|
|
def catch_exceptions( caption="EXCEPTION", retval=None ):
|
|
"""Decorator that handles exceptions thrown by the wrapped function.
|
|
|
|
We have to wrap every callback fuction that the front-end invokes with this,
|
|
otherwise an exception will cause the program to crash and die :-/
|
|
"""
|
|
def decorator( func ):
|
|
"""The real decorator function."""
|
|
@functools.wraps( func )
|
|
def wrapper( *args, **kwargs ):
|
|
"""Wrapper around the function being decorated."""
|
|
try:
|
|
return func( *args, **kwargs )
|
|
except Exception as ex: #pylint: disable=broad-except
|
|
logging.critical( "%s: %s", caption, ex )
|
|
logging.critical( traceback.format_exc() )
|
|
from vasl_templates.main_window import MainWindow #pylint: disable=cyclic-import
|
|
MainWindow.showErrorMsg( "Unexpected callback error:\n\n{}".format( str(ex) ) )
|
|
return retval
|
|
return wrapper
|
|
return decorator
|
|
|