Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / internet / gtk3reactor.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 This module provides support for Twisted to interact with the gtk3 mainloop
6 via Gobject introspection. This is like gi, but slightly slower and requires a
7 working $DISPLAY.
8
9 In order to use this support, simply do the following::
10
11     from twisted.internet import gtk3reactor
12     gtk3reactor.install()
13
14 If you wish to use a GApplication, register it with the reactor::
15
16     from twisted.internet import reactor
17     reactor.registerGApplication(app)
18
19 Then use twisted.internet APIs as usual.
20 """
21
22 from twisted.internet import gireactor
23 from twisted.python import runtime
24
25
26 class Gtk3Reactor(gireactor.GIReactor):
27     """
28     A reactor using the gtk3+ event loop.
29     """
30
31     def __init__(self):
32         """
33         Override init to set the C{useGtk} flag.
34         """
35         gireactor.GIReactor.__init__(self, useGtk=True)
36
37
38
39 class PortableGtk3Reactor(gireactor.PortableGIReactor):
40     """
41     Portable GTK+ 3.x reactor.
42     """
43     def __init__(self):
44         """
45         Override init to set the C{useGtk} flag.
46         """
47         gireactor.PortableGIReactor.__init__(self, useGtk=True)
48
49
50
51 def install():
52     """
53     Configure the Twisted mainloop to be run inside the gtk3+ mainloop.
54     """
55     if runtime.platform.getType() == 'posix':
56         reactor = Gtk3Reactor()
57     else:
58         reactor = PortableGtk3Reactor()
59
60     from twisted.internet.main import installReactor
61     installReactor(reactor)
62     return reactor
63
64
65 __all__ = ['install']