mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
Fix execution in IPython with qt backend.
New QApplication and event-loop implementation stolen shamelessly from IPython. Strangely, running the viewer at the IPython prompt will open an orphan Matplotlib figure window, but running a script using `%run` does not. Only tested on PySide (not PyQt4).
This commit is contained in:
@@ -22,22 +22,37 @@ __all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage',
|
||||
'update_axes_image']
|
||||
|
||||
|
||||
QApp = None
|
||||
|
||||
|
||||
def init_qtapp():
|
||||
"""Initialize QAppliction.
|
||||
|
||||
The QApplication needs to be initialized before creating any QWidgets
|
||||
"""
|
||||
global QApp
|
||||
if QApp is None:
|
||||
QApp = QtGui.QApplication([])
|
||||
app = QtGui.QApplication.instance()
|
||||
if app is None:
|
||||
app = QtGui.QApplication([])
|
||||
return app
|
||||
|
||||
|
||||
def start_qtapp():
|
||||
def is_event_loop_running(app=None):
|
||||
"""Return True if event loop is running."""
|
||||
if app is None:
|
||||
app = init_qtapp()
|
||||
if hasattr(app, '_in_event_loop'):
|
||||
return app._in_event_loop
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def start_qtapp(app=None):
|
||||
"""Start Qt mainloop"""
|
||||
QApp.exec_()
|
||||
if app is None:
|
||||
app = init_qtapp()
|
||||
if not is_event_loop_running(app):
|
||||
app._in_event_loop = True
|
||||
app.exec_()
|
||||
app._in_event_loop = False
|
||||
else:
|
||||
app._in_event_loop = True
|
||||
|
||||
|
||||
class RequiredAttr(object):
|
||||
|
||||
Reference in New Issue
Block a user