[IPython-dev] GUI support: conflicts between IPython 0.11 and Matplotlib/ETS

Hans Meine hans_meine@gmx....
Fri Feb 12 05:06:50 CST 2010


On Friday 12 February 2010 11:17:22 you wrote:
> On Fri, Feb 12, 2010 at 11:08:18AM +0100, Hans Meine wrote:
> > if __name__ == "__main__":
> > 	import sys
> >
> > 	app = QtGui.QApplication(sys.argv)
> >
> > 	mw = BeverageMainWindow()
> > 	mw.resize(800, 600)
> > 	mw.show()
> > 	sys.exit(app.exec_())
> >
> > This is a prototypical __main__ which I'd like to be able to %run from
> > IPython as well as from the commandline.  If I want to reuse code, I'll
> > import the file and reuse BeverageMainWindow, but not the __main__
> > code.
> 
> OK, but in the above code, you are saying that you want to own the
> application object.

Do I?  I see it more like a minimal setup function for opening the main 
window, which is all I care about.  The QApplication line is only there to 
make the stuff below work (with Qt, as with most toolkits AFAIK, I would 
otherwise get an error because the widgets will rely on global state being 
initialized by the application constructor).

> What if you want to interact with other code that
> does the same thing? There can only be one like this.

Actually, the most important use case I see is that I repeatedly %run the same 
program.  That would even work if I called app.setApplicationName(), 
.setVersion, ... which I did not in my above minimal example.

> [...] if you follow this logic, then you end up deciding
> that nobody should ever create a new application object without checking
> that one already exists, unless they want exactly that (eg for explicit
> threading reasons).

OK, but then my __main__ becomes twice as long, because I must also not enter 
the main loop and not call sys.exit() in theory.

I would simply prefer if IPython automatically handled that for me.

I fully understand that this will not work in general, with any application.
(For instance, Qt's database handling includes global state about the "default 
database" for your convenience etc.)

OTOH, ipython mostly is about hacks for convenient interactive experiments, 
and most of my programs
- do not rely on global state at all (i.e. the main window is all I actually 
care about), or
- just set up some "more or less constant" global state (like app name & 
version) which would still work if I %run the same app several times (and 
probably degrade quite gracefully if I %run another app).

> What I am trying to say is that you have contradictory requirements: you
> are asking for full ownership of the application,

I do not mean to.

> but you would also like
> to play nice with other environments.

Not really either. ;-)

Greetings,
  Hans


More information about the IPython-dev mailing list