Repository: ipython/ipython

Issue:
Standalone WX GUI support is broken
The example in `docs/lib/gui-wx.py` doesn't currently work, and I've failed in all simple attempts at fixing it.  Since we can't hold the 0.11 release for any longer, I'm marking this as a known bug in the release notes, but we should get to the bottom of it.

The other three examples (Qt, GTK, Tk) do run fine.



Discussion:
When fixing this, don't forget to update the GUI section in the `docs/source/interactive/reference.txt` file that has warnings about this issue.

Not sure what to expect from this example but here's what worked for me. I got the pop-up and the buttons worked.

BTW: what does %gui wx do?

Piotr

```
$ git diff
diff --git a/docs/examples/lib/gui-wx.py b/docs/examples/lib/gui-wx.py
index c55ce4f..a374024 100755
--- a/docs/examples/lib/gui-wx.py
+++ b/docs/examples/lib/gui-wx.py
@@ -105,13 +105,19 @@ class MyApp(wx.App):


 if __name__ == '__main__':
-    raise NotImplementedError(
-        'Standalone WX GUI support is currently broken. '
-        'See https://github.com/ipython/ipython/issues/645 for details')
+    #raise NotImplementedError(
+    #    'Standalone WX GUI support is currently broken. '
+    #    'See https://github.com/ipython/ipython/issues/645 for details')

     app = wx.GetApp()
     if app is None:
         app = MyApp(redirect=False, clearSigInt=False)
+    else:
+        frame = MyFrame(None, "Simple wxPython App")
+        app.SetTopWindow(frame)
+        print "Print statements go to this stdout window by default."
+        frame.Show(True)
+

     try:
         from IPython.lib.inputhook import enable_wx
```

@piotradam : Were you able to continue running commands in IPython while the Wx window was displayed?

Yes. I just tried it. I even imported pylab and made a simple plot. The funny thing is that it showed as Tk window.

@takluyver it event continued to work after I close the window :)

After you close the window is the easy bit ;-). Normally, if you ran a GUI app inside IPython, IPython would lock up until you close the new window. It's keeping both the window and the shell interactive at the same time that takes work.

I imagine matplotlib will just use your default backend.

@fperez : Can you now get this working as well?


Resolving patch:
diff --git a/docs/examples/lib/gui-wx.py b/docs/examples/lib/gui-wx.py
--- a/docs/examples/lib/gui-wx.py
+++ b/docs/examples/lib/gui-wx.py
@@ -1,30 +1,14 @@
 #!/usr/bin/env python
 """
-WARNING: This example is currently broken, see
-https://github.com/ipython/ipython/issues/645 for details on our progress on
-this issue.
-
 A Simple wx example to test IPython's event loop integration.
 
 To run this do:
 
-In [5]: %gui wx
+In [5]: %gui wx  # or start IPython with '--gui wx' or '--pylab wx'
 
 In [6]: %run gui-wx.py
 
 Ref: Modified from wxPython source code wxPython/samples/simple/simple.py
-
-This example can only be run once in a given IPython session because when
-the frame is closed, wx goes through its shutdown sequence, killing further
-attempts.  I am sure someone who knows wx can fix this issue.
-
-Furthermore, once this example is run, the Wx event loop is mostly dead, so
-even other new uses of Wx may not work correctly.  If you know how to better
-handle this, please contact the ipython developers and let us know.
-
-Note however that we will work with the Matplotlib and Enthought developers so
-that the main interactive uses of Wx we are aware of, namely these tools, will
-continue to work well with IPython interactively.
 """
 
 import wx
@@ -105,17 +89,18 @@ def OnInit(self):
 
 
 if __name__ == '__main__':
-    raise NotImplementedError(
-        'Standalone WX GUI support is currently broken. '
-        'See https://github.com/ipython/ipython/issues/645 for details')
 
     app = wx.GetApp()
     if app is None:
         app = MyApp(redirect=False, clearSigInt=False)
+    else:
+        frame = MyFrame(None, "Simple wxPython App")
+        app.SetTopWindow(frame)
+        print "Print statements go to this stdout window by default."
+        frame.Show(True)
 
     try:
         from IPython.lib.inputhook import enable_wx
         enable_wx(app)
     except ImportError:
         app.MainLoop()
-


Test patch: