-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Qt5: Move agg draw to main thread and fix rubberband #4972
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
Conversation
This needs a rebase, sorry. |
This PR contains two fixes. The first one moves the agg draw back to the main thread. Qt uses a dedicated render thread for paintEvent. Although the agg buffer should be updated as closely to the qt repaint as possible in order to take all the latest events into account, accessing the scenegraph from the render thread is dangerous since the scenegraph has no locking mechanism. The second and third commit address problems with the rubberband in qt. The second adds a The last commit changes the rubberband handling in the qt backend to utilize the rubberband removal handler. The previous solution was to simply remove the rectangle after each draw. This method fails when there is an additional paintEvent between two |
@jrevans Do you have an example for the situation you described where |
My reading of @jrevans comments is that was his guess as to why the draw was there. That conditional can probably be removed. |
I would like confirmation from @jrevans that this does not break any of their use cases. I gave this a read over and it seems reasonable, but need sink more time into it. I am slightly worried about the MI re-ordering and making sure all of our classes are correctly cooperating when they need to be (one of the big changes between pyQt4 and pyQt5 is that their classes are now cooperating) so everything works with both qt4 and qt5. attn @mfitzp (you clearly need a distraction from thesis writing 😈 ) |
@astrofrog Can you have a look at how this impacts glueviz? |
@tacaswell - we don't yet use Qt5 in glueviz, so I'm not able to test this yet (unless this impacts Qt4 in some way?) |
It does, qt4 is implemented as a shim on to of qt5. On Sun, Aug 23, 2015, 11:27 AM Thomas Robitaille notifications@github.com
|
@tacaswell - ok, in that case I will test this out tomorrow with glueviz |
@tacaswell - sorry for the delay. Unfortunately this does break glueviz: Before (master): After (this PR): |
Any idea why this would have an impact on glueviz while the regular gui operates normally? |
glueviz does some monkey patching to try and control the draw cadence (if I recall correctly). I suspect that someplace they are calling |
Strange, that shouldnt stop the Widget from painting. Anything hardcoded to the order of the base and Mixin-classes? I will probably look into installing glueviz also... |
@@ -54,8 +54,8 @@ def new_figure_manager_given_figure(num, figure): | |||
return FigureManagerQT(canvas, num) | |||
|
|||
|
|||
class FigureCanvasQTAgg(FigureCanvasQTAggBase, | |||
FigureCanvasQT, FigureCanvasAgg): | |||
class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasQTAggBase, |
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 worry about this change a bit.
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.
Indeed, both FigureCanvasQT and FigureCanvasQTAggBase define draw() methods, and the one from FigureCanvasQT is supposed to be overwritten. So FigureCanvasQTAggBase must be the first class for now.
Yea, seems to be a problem with the python MRO. The glueviz problem is caused by making FigureCanvasQT the first class instead of FigureCanvasQTAggBase, although making the QObject the first class this is the preferred layout according to the PyQt documentation. |
Reverted to original class order and rebased to current master. |
@astrofrog @jrevans Can you both please check the impact of this branch on your applications? |
@@ -2763,6 +2763,10 @@ def draw_rubberband(self, event, x0, y0, x1, y1): | |||
"""Draw a rectangle rubberband to indicate zoom limits""" | |||
pass | |||
|
|||
def remove_rubberband(self): |
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.
Do any other backends implement this?
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.
Not at this time. I found a class named RubberbandBase
in backend_tools.py that looks like a template for rubberband functionality, including a remove_rubberband
function. Gtk3 and TK seem to implement this class. However, this code path is never used. Seems to me that this solution has been abandoned at some time and now only draw_rubberband
implemented by the canvas is used.
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.
Other way around, the toolbase work is functionality that is just starting to be built out by @fariza and @OceanWolf
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.
@pwuertz It's not abandoned, It's just the beginning. For now only Gtk3 and Tk are implemented, we are waiting for MEP27 to land to finish the other backends
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.
Ah, well then porting this solution to the toolbase framework should be straight forward since it implements the same draw/remove concept.
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.
Yes, the codepath does get used see FigureManagerGTK3
and FigureManagerTkAgg
which calls this codepath via backend_tools.default_tools
. In the upcoming 1.5 release this will go out as an experimental proof of concept, then we will begin work on the final polishing, MEP27 does this a bit (see #4143), and other commits related to MEP22 (see #3652). So for 2.1 we should have this ready to go out fully.
Feel free to test, just set rcParam['toolbar'] = 'toolmanager'
, but as we say, only on GTK3
and TKAgg
for now.
@tacaswell @pwuertz - just confirming that this now works with glueviz |
MNT: Move agg draw to main thread and fix rubberband in Qt
Follow up from #4962