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.

wxsupport.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. #
  4. """Old method of wxPython support for Twisted.
  5. twisted.internet.wxreactor is probably a better choice.
  6. To use::
  7. | # given a wxApp instance called myWxAppInstance:
  8. | from twisted.internet import wxsupport
  9. | wxsupport.install(myWxAppInstance)
  10. Use Twisted's APIs for running and stopping the event loop, don't use
  11. wxPython's methods.
  12. On Windows the Twisted event loop might block when dialogs are open
  13. or menus are selected.
  14. Maintainer: Itamar Shtull-Trauring
  15. """
  16. import warnings
  17. warnings.warn("wxsupport is not fully functional on Windows, wxreactor is better.")
  18. from twisted.python._oldstyle import _oldStyle
  19. from twisted.internet import reactor
  20. @_oldStyle
  21. class wxRunner:
  22. """Make sure GUI events are handled."""
  23. def __init__(self, app):
  24. self.app = app
  25. def run(self):
  26. """
  27. Execute pending WX events followed by WX idle events and
  28. reschedule.
  29. """
  30. # run wx events
  31. while self.app.Pending():
  32. self.app.Dispatch()
  33. # run wx idle events
  34. self.app.ProcessIdle()
  35. reactor.callLater(0.02, self.run)
  36. def install(app):
  37. """Install the wxPython support, given a wxApp instance"""
  38. runner = wxRunner(app)
  39. reactor.callLater(0.02, runner.run)
  40. __all__ = ["install"]