2012-10-14 17:22:52 +00:00
|
|
|
"""
|
2013-08-01 18:17:12 +00:00
|
|
|
Module containing various decorators
|
2012-10-14 17:22:52 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
class RefreshWrapper(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.core = None
|
|
|
|
|
|
|
|
def conditional(self, func):
|
|
|
|
"""
|
|
|
|
Decorator to refresh the UI if the wrapped function
|
|
|
|
returns True
|
|
|
|
"""
|
|
|
|
def wrap(*args, **kwargs):
|
|
|
|
ret = func(*args, **kwargs)
|
|
|
|
if self.core and ret:
|
|
|
|
self.core.refresh_window()
|
|
|
|
return ret
|
|
|
|
return wrap
|
|
|
|
|
|
|
|
def always(self, func):
|
|
|
|
"""
|
|
|
|
Decorator that refreshs the UI no matter what after the function
|
|
|
|
"""
|
|
|
|
def wrap(*args, **kwargs):
|
|
|
|
ret = func(*args, **kwargs)
|
|
|
|
if self.core:
|
|
|
|
self.core.refresh_window()
|
|
|
|
return ret
|
|
|
|
return wrap
|
|
|
|
|
2014-03-22 23:15:01 +00:00
|
|
|
def update(self, func):
|
2012-10-14 17:22:52 +00:00
|
|
|
"""
|
|
|
|
Decorator that only updates the screen
|
|
|
|
"""
|
|
|
|
def wrap(*args, **kwargs):
|
|
|
|
ret = func(*args, **kwargs)
|
|
|
|
if self.core:
|
|
|
|
self.core.doupdate()
|
|
|
|
return ret
|
|
|
|
return wrap
|
|
|
|
|
|
|
|
refresh_wrapper = RefreshWrapper()
|