Repository navigation
Add support for PyQt5. - #5458
Conversation
|
Does this require mpl to play nice with QT5 as well? |
|
Oh, I haven't checked mpl yet, I just needed some interactive shell in a Qt5 application. But true, something similar should work for mpl as well (checking for existing Qt imports and join QtGui+QtWidgets if PyQt5 is loaded). |
|
Cross-link to PR in matplotlib: matplotlib/matplotlib#2471 |
|
Interresting. The behaviour of |
|
gah, sorry for botching the github-foo |
|
Thanks. We're coming up to the 2.0 release, so we'll probably leave this until after the release, to avoid breaking things accidentally. |
|
@takluyver Then it's a good thing that the PR also re-fixes the problem of accidentally mixing different Qt apis since IPython doesn't detect PyQt5 at the moment ;) |
|
It might be a candidate for a backport to 2.1 - it's kind of in the grey area between bugfix and feature. Thanks for being understanding. There's probably a couple more doc changes to do, e.g. module level docstrings. Nothing else I can see at the moment. |
There was a problem hiding this comment.
Do we need to create a new class for this? Can we just instantiate types.ModuleType and update the object's __dict__?
There was a problem hiding this comment.
I recently had an error when trying to update a __dict__ attribute in python3 since it was of type mappingproxy instead of dict, so I assumed this approach was discouraged. This however doesn't seem to be the case here, so I'll modify the PR according to your suggestion.
|
Thanks, I think this looks good now. |
|
With PyQt5 installed and PyQt4 not installed, I have to import PyQt5 modules before %gui qt works: In [2]: %gui qt In [3]: from PyQt5 import QtCore, QtGui, QtWidgets, QtOpenGL In [4]: %gui qt I am on commit 3639432. |
|
That seems to work for me. %matplotlib and %pylab naturally doesn't work since there is no support in MPL yet. However the qtconsole doesn't work for me QT_API=pyqt5 ipython qtconsole
Traceback (most recent call last):
File "/Users/jhn/Envs/ipython_master/bin/ipython", line 9, in <module>
load_entry_point('ipython==3.0.0-dev', 'console_scripts', 'ipython')()
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 548, in launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 319, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/core/application.py", line 378, in initialize
self.parse_command_line(argv)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 314, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 460, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 398, in initialize_subcommand
self.subapp.initialize(argv)
File "<string>", line 2, in initialize
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/qt/console/qtconsoleapp.py", line 344, in initialize
IPythonConsoleApp.initialize(self,argv)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/consoleapp.py", line 352, in initialize
self.init_kernel_client()
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/consoleapp.py", line 339, in init_kernel_client
self.kernel_client.start_channels()
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/qt/kernel_mixins.py", line 208, in start_channels
super(QtKernelClientMixin, self).start_channels(*args, **kw)
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/kernel/client.py", line 109, in start_channels
self.shell_channel.start()
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/kernel/client.py", line 153, in shell_channel
self.context, self.session, url
File "/Users/jhn/Envs/ipython_master/lib/python2.7/site-packages/IPython/qt/util.py", line 67, in __new__
QtCore.QObject.__init__(inst)
TypeError: __init__() takes exactly 4 arguments (1 given)
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True |
|
Apparently, there is another Mixin-Class without default constructor involved when using qtconsole. I'll have a look at it. |
|
@jenshnielsen @pwuertz Is there a bug open for the above issue? Having the same problems with PyQt5 at qtconsole myself. |
|
I've opened a bug report here: #6103 with additional info I've managed to figure out (the error is occurring in the |
Add support for PyQt5.
|
this should probably be backported to 2.4 if you are still planing that. Some distributions are planning to remove qt4 soon (debian maybe in the next cycle). |
This PR adds the new `QT_API_PYQT5` to `IPython/external/qt_loaders.py ` and allows to embed the IPython console in Qt5 Applications. In case of PyQt5, the loader returns a union of `PyQt5.QtGui` and `PyQt5.QtWidgets` acting as a Qt4-QtGui compatibility module. One small fix to `InProcessChannel.__init__` was necessary though. For some reason, when constructing `QtInProcessShellChannel`, the `QtCore.QObject.__init__` initializer from `SuperQObject` indirectly calls the `InProcessChannel.__init__` function, which doesn't have a default constructor and thus fails. I assume this has something to do with the metaclass/multiple inheritance approach IPython uses on QObject. Adding a default value for `client` in `InProcessChannel.__init__` solved the problem for me.
|
Backported to 2.x, thanks. |
This PR adds the new `QT_API_PYQT5` to `IPython/external/qt_loaders.py ` and allows to embed the IPython console in Qt5 Applications. In case of PyQt5, the loader returns a union of `PyQt5.QtGui` and `PyQt5.QtWidgets` acting as a Qt4-QtGui compatibility module. One small fix to `InProcessChannel.__init__` was necessary though. For some reason, when constructing `QtInProcessShellChannel`, the `QtCore.QObject.__init__` initializer from `SuperQObject` indirectly calls the `InProcessChannel.__init__` function, which doesn't have a default constructor and thus fails. I assume this has something to do with the metaclass/multiple inheritance approach IPython uses on QObject. Adding a default value for `client` in `InProcessChannel.__init__` solved the problem for me.
This PR adds the new
QT_API_PYQT5toIPython/external/qt_loaders.pyand allows to embed the IPython console in Qt5 Applications. In case of PyQt5, the loader returns a union ofPyQt5.QtGuiandPyQt5.QtWidgetsacting as a Qt4-QtGui compatibility module.One small fix to
InProcessChannel.__init__was necessary though. For some reason, when constructingQtInProcessShellChannel, theQtCore.QObject.__init__initializer fromSuperQObjectindirectly calls theInProcessChannel.__init__function, which doesn't have a default constructor and thus fails. I assume this has something to do with the metaclass/multiple inheritance approach IPython uses on QObject. Adding a default value forclientinInProcessChannel.__init__solved the problem for me.