[IPython-dev] What is the status of iPython+wx?

Brian Granger ellisonbg at gmail.com
Mon Mar 29 13:23:03 EDT 2010


> I'm really confused as to how you can start an event loop without an App
> -- but I guess I'll dig into the code to figure that out.

It is a bit subtle - it took us years to understand that this was
possible.  Here is a sketch of how it works:

* The C API of Python has a hook called PyOS_InputHook.  It is a
pointer to a function.
* The function get called when Python enters raw_input.  When
raw_input is called, Python enters into its own mini event loop.  This
is where readline interactions take place.
* While this mini-event loop is running, Python calls the
PyOS_InputHook function.  The sole purpose of this call is to enable
other event loops to integrate with Python.
* This is how the event loop integration with tk works in regular Python.
* We have implemented a hook for wx.  If you look at our hook though,
it checks to see if a wx App has been created.  If no App has been
created, the hook is a no-op.  But, the second you create an App, our
function picks that up and iterates the event loop while raw_input is
being called.




>> If you do this, it will be your repsonsibility to create and
>> manage an Application object.  BUT, don't start the event loop
>> yourself, it is already running.
>  > A warning: you may have to pass very
>> specific options to the wx App when you create it.  See our app
>> creation logic here for details of what you will likely have to do:
>> inputhook.InputHookManager.enable_wx
>> If you do:
>> %gui -a wx
>> We start the event loop AND create a wx Application passing reasonable
>> options.  In this case, you should not create an App, but rather just
>> get the one IPython created using wx.GetApp().
> Got it -- I had only seen the "-a" option in the docs, so that is what I
> was messing with.
>> What I don't know is what wx does if the App gets closed down.  We
>> don't do anything unusual though that would mess with how wx handles
>> this type of thing.
>>> If I close the frame, then call run gui-wx.py -- it is unstable,
>>> freezing up on me fairly quickly.
>> I am guessing the App gets shutdown and that kills any further wx goodness.
> yup -- wx doesn't support stopping and restarting an App.
>>> I haven't looked yet at the ipython code to see what you are doing in
>>> appstart_wx. I'll try to do that soon.
>> Yes, also look at enable_wx.  We don't do much at all.
> will do.
>> Have a look at what we are doing - it is basically \epsilon, so for
>> the most part wx should be doing what you tell it to.  BUT, this is
>> way different from the older IPython.  There we used to do a lot to
>> hijack/monkeypatch wx so many thing happened automagically.  but
>> monkeypatching = crashing.
> yes, it can mean that.
> I think I'm envisioning having a "IpythonWxApp", that would act like a
> normal wx app when run on it's own, and do special stuff when run under
> wx -- Ideally it would live with wx, but that's not too big a deal.
> Hopefully I"ll get a bit of time to try to write such a beast.
> -Chris
> --
> Christopher Barker, Ph.D.
> Oceanographer
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
> Chris.Barker at noaa.gov
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com

More information about the IPython-dev mailing list