Skip to content

support %matplotlib qt5 and %matplotlib nbagg - #6587

Merged
takluyver merged 3 commits into
ipython:masterfrom
minrk:mpl-qt5
Oct 1, 2014
Merged

takluyver merged 3 commits into
ipython:masterfrom
minrk:mpl-qt5

Conversation

@minrk

@minrk minrk commented Oct 1, 2014

Copy link
Copy Markdown
Member

just needed the key, since %gui qt5 already works

also copy %gui qt5 logic from #6496 to the kernel eventloop registry.

closes #6057

minrk added 2 commits October 1, 2014 12:00
same as terminal IPython in ipython#6496
didn't need anything beyond register
just needed the key, since `%gui qt5` already works
@minrk minrk modified the milestones: 3.0, 2.3 Oct 1, 2014
@tacaswell

Copy link
Copy Markdown
Contributor

Can you also add support for nbagg?

we don't need to do anything, just add keys to a couple of dictionaries
@minrk minrk changed the title support %matplotlib qt5 support %matplotlib qt5 and %matplotlib nbagg Oct 1, 2014
@minrk

minrk commented Oct 1, 2014

Copy link
Copy Markdown
Member Author

Yup, since we don't need to do anything for nbagg support, I just added the relevant keys where needed. I will do a separate PR not to be backported, where I will propose %matplotlib [backend_name] should work for any backend name, and if IPython doesn't know anything about it, it will assume no eventloop integration is needed. This would have prevented the need for nbagg to be added at all.

takluyver added a commit that referenced this pull request Oct 1, 2014
support `%matplotlib qt5` and `%matplotlib nbagg`
@takluyver
takluyver merged commit 9bedf1d into ipython:master Oct 1, 2014
@tacaswell

Copy link
Copy Markdown
Contributor

Awesome!

I just got to testing this and am getting strange behavior. The first time I run %matplotlib qt5 is get exceptions, the second time I don't and

(py3k)tcaswell@eowyn:~$ ipython
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0-dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %matplotlib qt5                
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-fbf5de2c563c> in <module>()
----> 1 get_ipython().magic('matplotlib qt5')

/home/tcaswell/other_source/ipython/IPython/core/interactiveshell.py in magic(self, arg_s)
   2275         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2276         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2277         return self.run_line_magic(magic_name, magic_arg_s)
   2278 
   2279     #-------------------------------------------------------------------------

/home/tcaswell/other_source/ipython/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2196                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2197             with self.builtin_trap:
-> 2198                 result = fn(*args,**kwargs)
   2199             return result
   2200 

/home/tcaswell/other_source/ipython/IPython/core/magics/pylab.py in matplotlib(self, line)

/home/tcaswell/other_source/ipython/IPython/core/magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/home/tcaswell/other_source/ipython/IPython/core/magics/pylab.py in matplotlib(self, line)
     78         """
     79         args = magic_arguments.parse_argstring(self.matplotlib, line)
---> 80         gui, backend = self.shell.enable_matplotlib(args.gui)
     81         self._show_matplotlib_backend(args.gui, backend)
     82 

/home/tcaswell/other_source/ipython/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   3009         # Now we must activate the gui pylab wants to use, and fix %run to take
   3010         # plot updates into account
-> 3011         self.enable_gui(gui)
   3012         self.magics_manager.registry['ExecutionMagics'].default_runner = \
   3013             pt.mpl_runner(self.safe_execfile)

/home/tcaswell/other_source/ipython/IPython/terminal/interactiveshell.py in enable_gui(gui, app)
    307         from IPython.lib.inputhook import enable_gui as real_enable_gui
    308         try:
--> 309             return real_enable_gui(gui, app)
    310         except ValueError as e:
    311             raise UsageError("%s" % e)

/home/tcaswell/other_source/ipython/IPython/lib/inputhook.py in enable_gui(self, gui, app)
    248         self._current_gui = gui
    249 
--> 250         app = gui_hook.enable(app)
    251         if app is not None:
    252             app._in_event_loop = True

/home/tcaswell/other_source/ipython/IPython/lib/inputhook.py in enable(self, app)
    383     def enable(self, app=None):
    384         os.environ['QT_API'] = 'pyqt5'
--> 385         return Qt4InputHook.enable(self, app)
    386 
    387 

/home/tcaswell/other_source/ipython/IPython/lib/inputhook.py in enable(self, app)
    362             app = QtGui.QApplication(sys.argv)
    363         """
--> 364         from IPython.lib.inputhookqt4 import create_inputhook_qt4
    365         from IPython.external.appnope import nope
    366         app, inputhook_qt4 = create_inputhook_qt4(self, app)

/home/tcaswell/other_source/ipython/IPython/lib/inputhookqt4.py in <module>()
     22 
     23 from IPython.core.interactiveshell import InteractiveShell
---> 24 from IPython.external.qt_for_kernel import QtCore, QtGui
     25 from IPython.lib.inputhook import allow_CTRL_C, ignore_CTRL_C, stdin_ready
     26 

/home/tcaswell/other_source/ipython/IPython/external/qt_for_kernel.py in <module>()
     78 api_opts = get_options()
     79 if api_opts is not None:
---> 80     QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
     81 
     82 else: # use ETS variable

/home/tcaswell/other_source/ipython/IPython/external/qt_loaders.py in load_qt(api_options)
    294            has_binding(QT_API_PYQT5),
    295            has_binding(QT_API_PYSIDE),
--> 296            api_options))

ImportError: 
    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 is available,
    and only one is imported per session.

    Currently-imported Qt library:   'pyqt5'
    PyQt4 installed:                 True
    PyQt5 installed:                 False
    PySide >= 1.0.3 installed:       True
    Tried to load:                   ['pyqt5']


In [2]: %matplotlib qt5

In [3]: 

It works as expected before the second call to the magic, but the error is disconcerting (particularly because import PyQt5 works.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
support `%matplotlib qt5` and `%matplotlib nbagg`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

%matplotlib + qt5

4 participants