fabioz/Pydev — pull request #62 by jonahkichwacoders (2013-08-24 20:43:58+00:00)
Title: GUI Event Loop Integration

This pull request adds GUI Event Loop Integration for many Python GUI frameworks. It is based on some of the code used in IPython to achieve the same effect. However, with IPython the event loop is kept up to date with the special PyOS_InputHook, while with PyDev console the event loop is run while polling the XML-RPC server for new requests.

The following toolkits are now available and can be selected in the Interactive Console preference page (See new option at the bottom "Enable GUI event loop integration"):
- wxPython (wx)
- PyQt (qt/qt4)
- PyGTK (gtk)
- PyGI (gtk3)
- Tkinter (tk)
- OpenGL (glut)
- pyglet (pyglet)
- OS X (osx)
- alternatively none can be selected to have no event loop integration.

When running with Python 2 < 2.6 or Python 3 < 3.2 or Jython the event loop integration has no effect and a message will be displayed in the console if a selection other than "none" is selected. There are no new dependencies on third-party packages.

Various notes:
- This new code reverts some recent work that did event loop integration a different way. See the "Revert" commits on this branch. The two key differences between the previous approach and this approach are:
- No new threads are created
- the GUI is explicity selected via preferences (Note that IPython has a %gui magic, I am now working on connecting that magic to the same functionality. That would mean that you can start with no gui selected in preferences and then choose %gui . This will be part of a future pull request.)
- I have done some cleanup on createConsole so that it is more manageable to understand where the GUI is first initialised and the setting passed from Eclipse to the console.
- I have tested this primarily on Linux (Ubuntu 12.04 with stock packages) and all the applicable toolkits work in both Python 2 and Python 3. On Windows I was able to test the wx and tk tool kits, but I have not been able to set up other tool kits successfully. I don't have access to OS X so I have not verified any of the tool kits work there (in particular, I don't know if the osx tool kit handling is correct at all because in IPython it is a no-op at the moment, is osx handle the event loop separately all the time?). For the untested ones, as I have heavily based this on the IPython work I don't expect issues, but please raise them with me if there are any.
- There is a manual test suite to run, see 1bf9572
- IPython's pylab works well with the new features. Simply type %pylab and then plot away.

Outstanding issues:
- When input is being requested in the console (e.g. raw_input is called) the event loops do not run. This is the same as the version of the event loops that this code replaces. I have not decided on the best approach for this yet.
- The manual test suite is based on the IPython suite for the same functionality. One of the biggest differences between how the PyDev console behaves vs. an IPython or standard Python interactive terminal behaves is that output is displayed immediately. Many of the tests in the test suite do a "print" when you press a button, but you can't see the print output until you request a new prompt in the PyDev console. This issue is not specific to the new code, however the new code happens to highlight this issue a bit more. For anyone unaware, to replicate without GUI stuff run this code in a console and then press enter every few seconds to see "slowly" appear:

```python
import time
import threading
def printslowly():
while True:
print "slowly"
time.sleep(1)

threading.Thread(target=printslowly).start()
```

I look forward to feedback and review comments with the hope of eventual inclusion of these new features.

Thanks,
Jonah