[IPython-user] TraitsUI and ipython

Dave davbrow at gmail.com
Mon Dec 4 15:05:11 CST 2006

> ########
> Subject:
> Re: TraitsUI and ipython
> From:
> Robert Kern <robert.kern at gmail.com>
> Date:
> Sun, 03 Dec 2006 19:03:10 -0600
> To:
> ipython-user at scipy.net
> Dave wrote:
>  > > I'm just starting to work with the Enthought Traits module which
> looks
>  > > to have a very handy basic GUI for setting configuration data in
>  > > scripts and handling bits of persistent data with a trivial level of
>  > > effort.  It seems like it would be a great addition to the
>  > > ipython/pylab/YFE (your favotite editor) setup.  However, so far, I
>  > > have not been able to get python and pylab to cooperate on OS X.  I'm
>  > > using wxpython in pylab.  When I start ipython with -pylab or use
>  > > ipython -wthread and then run a TraitUI script the GUI window appears
>  > > along with a spinning-disk cursor for several seconds, followed by a
>  > > python/wxpython crash.
> What are you using to bring up the Traits sheet? .configure_traits() is
> used for
> when the Traits sheet *is* the application; i.e., it should not be used
> when a
> wx.App() has already been created like it is with "ipython -wthread". Use
> .edit_traits() instead. I apologize for the near-indistinguishable names;
> personally, I'd prefer that .configure_traits() be called
> .edit_traits_with_new_app().
> This is what I get (Intel OS X, Python 2.5, "ipython -wthread"
> svn-mumble-mumble, wxPython 2.6.3.x, enthought bleeding-svn):
> In [1]: from enthought.traits.api import *
> In [2]: class Foo(HasTraits):
>    ...:     bar = Str
>    ...:
>    ...:
> In [3]: f = Foo()
> In [4]: f.edit_traits()  # It works!
> Out[4]: <enthought.traits.ui.ui.UI object at 0x179f2ea0>
> In [5]: f.configure_traits()  # It fails!
> Out[5]: False
> In [6]: zsh: bus error  ipython -wthread

I was using .configure_traits() so that is likely the problem.  I'm very new
to TraitsUI and I did see the edit_traits() method in the docs but I did not
understand that ipython -wthread or-pylab creates the wx.App.  Thanks for
the tip and example Robert.

The solution is helpful but not ideal for me since, if I recall correctly,
.edit_traits() does not handle persistant storage.  Also I will need to know
the GUI context and write my script accordingly.  But avoiding this sort of
complication is my reason for using TraitsUI since it can
(almost) effectively hide the event loop and other GUI details from
polluting my simple-minded script code, as well as the minds of
future script readers.

Ideally I would think .configure_traits()  could do it's non-GUI stuff like
optional storage and typing, check for a wx.App or other appropriate GUI
context, create one if needed, call .edit_traits() to display the widgets,
and then update the storage. Temporarily, I migth be able to wrap
HasTraits, at least for wx.APP checking, to prevent the crash if anyone has
a suggestion for where to start.  Since it sounds like a TraitsUI issue I
follow up on enthought-dev for a longer-term solution.

In simple terms how does ipython and pylab work together today?  If ipyhon
-wthread creates an wx.App does pylab check for it first?  I'm wondering if
the approach would work for TraitsUI or if it's considered a short-term (but
very helpful) hack.

-- David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/ipython-user/attachments/20061204/a7ce7efe/attachment.html 

More information about the IPython-user mailing list