Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Prevent Qt4 from stopping the interpreter #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 19, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Just check DISPLAY env var
  • Loading branch information
openturns-appveyor committed Apr 16, 2013
commit 9bed01614814b2bc76d32110e1c6a3f9aa773971
14 changes: 6 additions & 8 deletions lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ def _create_qApp():
app = QtGui.QApplication.instance()
if app is None:

# try to launch a QApplication in a separate process
# otherwise it may stop the intepreter on failure (if no X server for example)
p = subprocess.Popen(sys.executable, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p.stdin.write('from matplotlib.backends.qt4_compat import QtGui\napp = QtGui.QApplication([])\n')
p.stdin.close()
if p.wait() != 0:
raise RuntimeError( 'Qt4 failed to initialize ' + p.stderr.readline().rstrip() )

# check for DISPLAY env variable
if sys.platform.startswith('linux'):
display = os.environ.get('DISPLAY')
if (display is None) or (not ':' in display.strip()):
raise RuntimeError('Invalid DISPLAY variable')

qApp = QtGui.QApplication( [" "] )
QtCore.QObject.connect( qApp, QtCore.SIGNAL( "lastWindowClosed()" ),
qApp, QtCore.SLOT( "quit()" ) )
Expand Down