Question about copy_from_bbox

Hi

I am using blitting and am not able to get it to work as I want.

I am using copy_from_bbox during the setup of my PyQt GUI to save a meshgrid as a starting empty background.
Then, once the GUI is loaded, the user can click on the meshgrid and a square is displayed on the selected pixel with blitting, so that no re-plotting needs to be done.

The problem is that between the copy_from_bbox call and the final GUI setup, there is some movement of the widgets (don’t really know why, surely PyQt layout adjustments).
This leads to a shift of the restored region, because the saved one (after the draw() call) is not the one which is finally displayed in the GUI. This can lead to strange display errors …

I tried to trim down my code to the essential, I hope it’s short enough.
I am using Matplotlib 1.3.1 on OS X, but I am having this problem one or two years and had never time to tackle it (I have it also on Windows and Fedora)

Here is my code, just run it and click on the meshgrid, you will see it move down, so that the top of the red square is not drawn correctly.
https://gist.github.com/iMichka/9901318

In the case of my example the shift is quite small (I could live with a shift of one pixel …), but in my real app there is more stuff and the shift is bigger … the plot even overlaps with PyQt buttons …

Is there any way to call copy_from_bbox when the PyQt GUI has stabilized ? This means after the PyQt event loop has finished refreshing, and not before the refreshing ?

Any help would be much appreciated :slight_smile:

Michka

Hi Michka,

I haven't practiced PyQt for some time, but I think I remember there is
a common practice of using a "0 ms" timer to launch a function after the
Gui setup.

I've modified your gist here :
https://gist.github.com/pierre-haessig/9909708
(for some reason the Github fork button printed "The change you wanted
was rejected.")

I don't know if it does what you want, but at least it doesn't move anymore.

best,
Pierre

Hi

thanks for the help, this is exactly what I needed. I updated the code in my
app and it worked.

Some minor observations though :
- This does not play well with tight_layout. I think tight_layout tries to
readjust the plots even after the singleShot call. So I needed to disable
it.
- I have plots in multiple tabs (in a QtGui.QTabWidget()). When moving from
one tab to another, I update the plots. I had to set the delay to 50 ms (on
faster computers the delay could be made smaller). 0 ms is too short in this
specific case and the copy_from_bbox will copy the background of the
previous tab.
- I have to work on the resizing of the window. I have to catch the
resizeEvent in the plot and update it to get a new fresh background. Don't
know what's the best solution for this.

Thanks very much for the singleShot trick, this was very helpful.

Michka

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Question-about-copy-from-bbox-tp43182p43192.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

I tried to get the resizing working, but to no avail.

Without modifying your code, when you click on multiple squares, and then
resize, all the previously displayed squares are dawn, as if there was a
merge of all the previous blits...

Any idea ?

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Question-about-copy-from-bbox-tp43182p43194.html
Sent from the matplotlib - users mailing list archive at Nabble.com.