Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gtk3reactor.py 1.5KB

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