Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
53880edd
by Philipp Hörist at 2019-04-14T20:32:47Z
1 changed file:
Changes:
| ... | ... | @@ -50,9 +50,11 @@ from datetime import datetime, timedelta |
| 50 | 50 |
from distutils.version import LooseVersion as V
|
| 51 | 51 |
from encodings.punycode import punycode_encode
|
| 52 | 52 |
from string import Template
|
| 53 |
+from functools import wraps
|
|
| 53 | 54 |
|
| 54 | 55 |
import nbxmpp
|
| 55 | 56 |
from nbxmpp.stringprepare import nameprep
|
| 57 |
+from gi.repository import GLib
|
|
| 56 | 58 |
import precis_i18n.codec # pylint: disable=unused-import
|
| 57 | 59 |
|
| 58 | 60 |
from gajim.common import app
|
| ... | ... | @@ -1532,3 +1534,21 @@ class Singleton(type): |
| 1532 | 1534 |
cls._instances[cls] = super(Singleton, cls).__call__(
|
| 1533 | 1535 |
*args, **kwargs)
|
| 1534 | 1536 |
return cls._instances[cls]
|
| 1537 |
+ |
|
| 1538 |
+ |
|
| 1539 |
+def delay_execution(milliseconds):
|
|
| 1540 |
+ # Delay the first call for `milliseconds`
|
|
| 1541 |
+ # ignore all other calls while the delay is active
|
|
| 1542 |
+ def delay_execution_decorator(func):
|
|
| 1543 |
+ @wraps(func)
|
|
| 1544 |
+ def func_wrapper(*args, **kwargs):
|
|
| 1545 |
+ def timeout_wrapper():
|
|
| 1546 |
+ func(*args, **kwargs)
|
|
| 1547 |
+ delattr(func_wrapper, 'source_id')
|
|
| 1548 |
+ |
|
| 1549 |
+ if hasattr(func_wrapper, 'source_id'):
|
|
| 1550 |
+ return
|
|
| 1551 |
+ func_wrapper.source_id = GLib.timeout_add(
|
|
| 1552 |
+ milliseconds, timeout_wrapper)
|
|
| 1553 |
+ return func_wrapper
|
|
| 1554 |
+ return delay_execution_decorator
|