# HG changeset patch
# User Adrian Buehlmann <adr...@cadifra.com>
# Date 1255194364 -7200
# Node ID ea119f5700cb01bcb8a5029cc3be4c0cfa671dda
# Parent  3423a3c5c0fa09b976e299cfa3a9b20c94630a94
gtklib: add idle_add_single_call function

diff --git a/tortoisehg/hgtk/gtklib.py b/tortoisehg/hgtk/gtklib.py
--- a/tortoisehg/hgtk/gtklib.py
+++ b/tortoisehg/hgtk/gtklib.py
@@ -604,3 +604,22 @@ def hasspellcheck():
         return True
     except ImportError:
         return False
+
+def idle_add_single_call(f, *args):
+    '''wrap function f for gobject.idle_add, so that f is guaranteed to be
+    called only once, independent of its return value'''
+
+    class single_call(object):
+        def __init__(self, f, args):
+           self.f = f
+           self.args = args
+        def __call__(self):
+           self.f(*args)  # ignore return value of f
+           return False   # return False to signal: don't call me again
+
+    # functions passed to gobject.idle_add must return False, or they
+    # will be called repeatedly. The single_call object wraps f and always
+    # returns False when called. So the return value of f doesn't matter,
+    # it can even return True (which would lead to gobject.idle_add
+    # calling the function again, if used without single_call).
+    gobject.idle_add(single_call(f, args))

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to