glib2reactor.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. This module provides support for Twisted to interact with the glib mainloop.
  5. This is like gtk2, but slightly faster and does not require a working
  6. $DISPLAY. However, you cannot run GUIs under this reactor: for that you must
  7. use the gtk2reactor instead.
  8. In order to use this support, simply do the following::
  9. from twisted.internet import glib2reactor
  10. glib2reactor.install()
  11. Then use twisted.internet APIs as usual. The other methods here are not
  12. intended to be called directly.
  13. """
  14. from incremental import Version
  15. from ._deprecate import deprecatedGnomeReactor
  16. deprecatedGnomeReactor("glib2reactor", Version("Twisted", 23, 8, 0))
  17. from twisted.internet import gtk2reactor
  18. class Glib2Reactor(gtk2reactor.Gtk2Reactor):
  19. """
  20. The reactor using the glib mainloop.
  21. """
  22. def __init__(self):
  23. """
  24. Override init to set the C{useGtk} flag.
  25. """
  26. gtk2reactor.Gtk2Reactor.__init__(self, useGtk=False)
  27. def install():
  28. """
  29. Configure the twisted mainloop to be run inside the glib mainloop.
  30. """
  31. reactor = Glib2Reactor()
  32. from twisted.internet.main import installReactor
  33. installReactor(reactor)
  34. __all__ = ["install"]