X-Git-Url: http://git.maemo.org/git/?p=watersofshiloah;a=blobdiff_plain;f=src%2Futil%2Fgo_utils.py;h=515041d795577aa713e7a53ef4927b07da2fc478;hp=ba66f26c9243b4dce03e9d148221abb127131652;hb=48391603fc793625843346917737373b891212a9;hpb=b7912838b8e1095f16da52b3fd590b8e110b2ae4 diff --git a/src/util/go_utils.py b/src/util/go_utils.py index ba66f26..515041d 100644 --- a/src/util/go_utils.py +++ b/src/util/go_utils.py @@ -95,16 +95,20 @@ class Async(object): class Timeout(object): - def __init__(self, func): + def __init__(self, func, once = True): self.__func = func self.__timeoutId = None + self.__once = once def start(self, **kwds): assert self.__timeoutId is None + callback = self._on_once if self.__once else self.__func + assert len(kwds) == 1 timeoutInSeconds = kwds["seconds"] assert 0 <= timeoutInSeconds + if timeoutInSeconds == 0: self.__timeoutId = gobject.idle_add(self._on_once) else: @@ -248,6 +252,23 @@ class AsyncLinearExecution(object): ) +class AutoSignal(object): + + def __init__(self, toplevel): + self.__disconnectPool = [] + toplevel.connect("destroy", self.__on_destroy) + + def connect_auto(self, widget, *args): + id = widget.connect(*args) + self.__disconnectPool.append((widget, id)) + + @misc.log_exception(_moduleLogger) + def __on_destroy(self, widget): + for widget, id in self.__disconnectPool: + widget.disconnect(id) + del self.__disconnectPool[:] + + def throttled(minDelay, queue): """ Throttle the calls to a function by queueing all the calls that happen