summaryrefslogtreecommitdiff
path: root/src/leap/gui/utils.py
blob: f91ac3ef685f16ca5d4e4c14ee61c4a63d48830a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
utility functions to work with gui objects
"""
from PyQt4 import QtCore


def layout_widgets(layout):
    """
    return a generator with all widgets in a layout
    """
    return (layout.itemAt(i) for i in range(layout.count()))


DELAY_MSECS = 50


def delay(obj, method_str=None, call_args=None):
    """
    Triggers a function or slot with a small delay.
    this is a mainly a hack to get responsiveness in the ui
    in cases in which the event loop freezes and the task
    is not heavy enough to setup a processing queue.
    """
    if callable(obj) and not method_str:
        fun = lambda: obj()

    if method_str:
        invoke = QtCore.QMetaObject.invokeMethod
        if call_args:
            fun = lambda: invoke(obj, method_str, call_args)
        else:
            fun = lambda: invoke(obj, method_str)

    QtCore.QTimer().singleShot(DELAY_MSECS, fun)