diff options
author | mathieui <mathieui@mathieui.net> | 2012-10-14 19:22:52 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2012-10-14 19:22:52 +0200 |
commit | 15dea2f3e82d535f58ddc0527e9ddb41a57f2a48 (patch) | |
tree | a1e6ff6912ab95ce662e2dd55cf4426896be25f0 | |
parent | d0545fb02167a28db04ce229b6dfa2d7283edeac (diff) | |
download | poezio-15dea2f3e82d535f58ddc0527e9ddb41a57f2a48.tar.gz poezio-15dea2f3e82d535f58ddc0527e9ddb41a57f2a48.tar.bz2 poezio-15dea2f3e82d535f58ddc0527e9ddb41a57f2a48.tar.xz poezio-15dea2f3e82d535f58ddc0527e9ddb41a57f2a48.zip |
Also add the decorators module
-rw-r--r-- | src/decorators.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/decorators.py b/src/decorators.py new file mode 100644 index 00000000..6eaac018 --- /dev/null +++ b/src/decorators.py @@ -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() |