Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

gtklib: add idle_add_single_call function

Changeset ea119f5700cb

Parent 3423a3c5c0fa

by Adrian Buehlmann

Changes to one file · Browse files at ea119f5700cb Showing diff from parent 3423a3c5c0fa Diff from another changeset...

 
604
605
606
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
@@ -604,3 +604,22 @@
  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))