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
Implement backend for PyQt5 + modify Qt4 backends to use Qt5 module via shim #3072
Conversation
It needs to be re-based an current master. |
fn_name, cursord, draw_if_interactive, _create_qApp, show, \ | ||
new_figure_manager, new_figure_manager_given_figure, \ | ||
TimerQT, FigureCanvasQT, MainWindow, FigureManagerQT, NavigationToolbar2QT, \ | ||
SubplotToolQt, error_msg_qt, exception_handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor style quibble, this should be done with ()
continuation not \
(see the from __future__
import).
There are some issues with the
|
Thanks @tacaswell |
I was poking at it a bit and I think it is related to the changes with how coperative mix-ins are handled. I suspect that we may end up having to touch more-or-less every class in the canvas tree. The above was with pysides and am set up to test both pyqt4 and pysides. |
Thanks for the feedback/suggestions. The latest commit works on PyQt4 (tested on Ubuntu Linux/python2.7). I basically copied the init block across into However, the end result is that this should now happily work with both PyQt5 and PyQt4. I'm going to look at installing PySide on the Linux box to test that too. |
copy-pasta? |
In
In
i.e. the whole init block is copied between the two - however I see no way to avoid it. It could be minimised by a small shared "init()" function but not sure if that improves clarity. Testing on PySide now and then I'll re-bunch the various commits into a single one (I'm testing on two machines and passing the latest iteration back and forward via github). |
It works for me with pyqt4, but I get a black window on pysides |
That's reassuring I get the same - but unfortunately no errors! I'm going to pull the latest matplotlib and try gradually applying the changes til it breaks. |
The latest commit fixes the issue with PySide for me (and tidies up a few other things). It is now tested as working for me under:
Can you check on your setup? Thanks |
with py2.7 it passes the smoke test (I can see a graph) with both pyqt4 as pyside. What was causing the black window? |
Never mind, I can read commit messages. |
Good stuff. Should I roll this up into a single commit for possible merge? |
If you want to squash it down, go ahead, if not it is probably fine. Please fix the indention issues though. |
A backend for PyQt5 based on intial work by @badders, modified to fix Qt5 mouse event handling, then re-structured to implement as a wrapper over the existing Qt4 code. Following discussions on this pull request: #2471 The code has been restructured to implement PyQt5 backend as a first-class implementation, with other Qt backends (PyQt4, PyQt4v2, PySide (Qt v4)) wrapping it and modifying as required. The issues of objects being moved around in the Qt namespace (many QtGui objects now in QtWidgets) QtWidgets is simply assigned as a copy of QtGui if not available. This achieves the intended outcome with the minimum code. PySide required re-ordering of import on FigureCanvasQTAgg or paintEvent function would not being called on FigureCanvasQTAggBase resulting in black window. A number of indentation, import and other fixes.
@Tillsten Could you test this on windows? I am more worried about regressions in the qt4 functionality. |
@tacaswell i will test it as far as i can when i am home (still not able to build mpl with windows), which should be ok for theses changes. but i am quite optimistic, qt is really good at being platform agnostic. |
Some encoding issue with one line:
It seems the first space in line 22 is some kind of unicode spacing. Using ansi encoding, the line shows up as: |
from .backend_qt5 import QtGui | ||
from .backend_qt5 import FigureManagerQT | ||
from .backend_qt5 import NavigationToolbar2QT | ||
##### Modified Qt5 backend import |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure there are no funny characters here, there should be only ascii in these files.
First impression: qt4 seems to work, but _priv_update is not used. See the used draw method in backend_qt5agg (which is used by the qt4 backend too, maybe change the file naming?). I still have to check some event based examples and qt5 under py3. btw, there are quite a lot of unused imports in backend_qt4agg. |
# causes problems with code that uses the result of the | ||
# draw() to update plot elements. | ||
FigureCanvasAgg.draw(self) | ||
self.update() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this here should be self._priv_update
.
The imports are there to make sure we don't break back compatibility with things that expect to be able to import them from this module. The backends are a bit of a nightmare. If/when we do a 2.0 this is one of the things I would want to aggressively change. |
@tacaswell apologies for missing your update. I'm on Python 3.4.0 and checking package versions ( So I'm a bit stumped why it isn't working for you. Do you get any output at all? |
I'm not near a computer where I can test this (and won't be for a week and a half). I was testing through ipython + pyplot. There are no error messages. |
Ah, that’s a difference from my approach at least - I was testing from the default Python shell. I’ll try again through IPython and see if I can reproduce. On 13 June 2014 at 00:24:50, Thomas A Caswell (notifications@github.com) wrote: I'm not near a computer where I can test this (and won't be for a week and a half). I was testing through ipython + pyplot. There are no error messages. — |
There was a bug on the pyplot initialisation that was wrongly looking for qApp in PyQt5.QtGui rather than PyQt5.QtWidgets. I've updated the init to do this correctly, which hopefully fixes the bug reported by @tacaswell
Has this been pushed to master yet? |
No @ezust this hasn't been merged yet and it's in a separate branch |
…d in matplotlib (branch) Previously the Qt5 interface was managed by backend_qt5 a temporary interface that formed the basis of a complete backend implementation for matplotlib. This has been commited and a PR submitted for inclusion in matplotlib v1.4.0. This is available here: matplotlib/matplotlib#3072 Clone and install from that repo using `pip install .`
@mfitzp The patch does not fix it for me. I only have issues when the |
After poking a bit, I am pretty sure this is an issue with the ipython magics. There is some logic in there to explicitly do the mapping between what we call backends and how they keep track of gui frameworks. |
I cleaned up some pep8 violations and merged this into master. I will create an issue with ipython re the magics and create a separate PR dealing with whats_new.rst |
Great news, thanks for all the guidance on getting this good to go. |
Thanks for doing the work to make it happen. |
Glad to see this is merged, looking forward to the 1.4.0 release more than ever |
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5 Conflicts: doc/api/api_changes/code_removal.rst
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5 Conflicts: doc/api/api_changes/code_removal.rst
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5 Conflicts: doc/api/api_changes/code_removal.rst
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5 Conflicts: doc/api/api_changes/code_removal.rst
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5
Deprecated in matplotlib#3174 / f896381 Fall out from the Qt5 upgrade PR matplotlib#3072 / b0dc1d5
A backend for PyQt5 based on intial work by @badders, modified to fix Qt5 mouse event handling, then re-structured to implement as a wrapper over the existing Qt4 code. Following discussions on this pull request:
#2471
the code has been restructured to implement PyQt5 backend as a first-class implementation, with other Qt backends (PyQt4, PyQt4v2, PySide (Qt v4)) wrapping it and modifying as required. The issues of objects being moved around in the Qt namespace (many QtGui objects now in QtWidgets) QtWidgets is simply assigned as a copy of QtGui if not available. This achieves the intended outcome with the minimum code.