Initial checkin
[ejpi] / src / libraries / recipes / gtk_utils.py
1 #!/usr/bin/env python
2
3
4 from __future__ import with_statement
5
6 import contextlib
7 import functools
8 import math
9
10 import gobject
11 import gtk
12 import gtk.glade
13
14
15 def make_idler(func):
16         """
17         Decorator that makes a generator-function into a function that will continue execution on next call
18
19         >>> import misc
20         >>> misc.validate_decorator(make_idler)
21
22         """
23         a = []
24
25         @functools.wraps(func)
26         def decorated_func(*args, **kwds):
27                 if not a:
28                         a.append(func(*args, **kwds))
29                 try:
30                         a[0].next()
31                         return True
32                 except StopIteration:
33                         del a[:]
34                         return False
35
36         return decorated_func
37
38
39 @contextlib.contextmanager
40 def gtk_critical_section():
41         #The API changed and I hope these are the right calls
42         gtk.gdk.threads_enter()
43         yield
44         gtk.gdk.threads_leave()
45
46
47 if __name__ == "__main__":
48         #gtk.gdk.threads_init()
49         pass