Also add the decorators module
This commit is contained in:
parent
d0545fb021
commit
15dea2f3e8
1 changed files with 46 additions and 0 deletions
46
src/decorators.py
Normal file
46
src/decorators.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
"""
|
||||||
|
Module containing the decorators
|
||||||
|
"""
|
||||||
|
|
||||||
|
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()
|
||||||
|
self.core.doupdate()
|
||||||
|
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()
|
||||||
|
self.core.doupdate()
|
||||||
|
return ret
|
||||||
|
return wrap
|
||||||
|
|
||||||
|
def update(self, funct):
|
||||||
|
"""
|
||||||
|
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()
|
Loading…
Reference in a new issue