Enthought Canopy - passing sys.argv from PySide Qt program
Question: I've recently been looking at the Enthought distro of iPython. Today I decided
to see if I could get some Qt GUI progs running and was successful after
making minor changes. Simple example:

    
    
    import sys
    from PySide import QtGui    # was 'from PyQT4 import QtGui'
    
    # app = QtGui.QApplication(sys.argv)   -- not needed
    
    win = QtGui.QWidget()
    
    win.resize(320, 240)  
    win.setWindowTitle("Hello MIT 6X!") 
    win.show()
    
    sys.exit()   # was 'sys.exit(app.exec_())'
    

But I would like to be able to pass `sys.argv` in some cases. Most example
code I see is in the form of the commented out `'app = '` line above. If I
include it, I get

> 'RuntimeError: A QApplication instance already exists.'

Suggestions for passing arguments appreciated.


Answer: Two separate issues:

1) Passing command line arguments: As you have probably noticed, when you do
the "Run" command from the Canopy editor, all it does is issue the IPython
%run magic command. You can type the same command in the IPython shell, plus
command line parameters, which your program will see. Or to save keystrokes,
do this auto-generated Run command once, then press Up Arrow in the IPython
shell to recall that auto-generated %run command, then enter your parameters
after the filename, and then press Enter. You'll end up with an IPython magic
command like this:

    
    
    %run pathtoprog/myprogrampy p1 p2 p3
    

We (Enthought) are considering adding a setting for command-line parameters so
that you could do "Run with parameters" and have the best of both worlds.

2) Existing QApplication: By default, Canopy's IPython is running in IPython's
interactive Pylab mode, with a Qt backend. If you don't want this, you can
just disable Pylab mode in the Canopy Preferences/Python menu, or change the
Pylab mode to Inline (for matplotlib) instead of Interactive.

For maximum flexibility, with a bit more work, you could (as matplotlib does)
introduce logic which checks whether a QApplication already exists, use it if
it exists and create it if it does not.

