PyQt and Chaco: copy plot container to clipboard

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

PyQt and Chaco: copy plot container to clipboard

Barth
Hello,

i am trying to copy Chaco Plot container onto the clipboard. I tried to adapt what is explained on the manual http://code.enthought.com/projects/chaco/docs/Chaco.pdf fur using pyQt. However, the following code has a problem: when i paste from the clipboard, i only have a black image. Could someone tell me what i did wrong ? 



width, height = plot.container.outer_bounds
gc = PlotGraphicsContext((width, height), dpi=72)
gc.render_component(plot.container)
        
bitmap=QtGui.QImage(gc.bmp_array)
clipboard=figure._parent.clipboard  #QApplication.clipboard()
clipboard.setImage(bitmap)


Bests,

Pierre



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: PyQt and Chaco: copy plot container to clipboard

Robert Kern
On Tue, Jun 5, 2012 at 5:28 PM, Pierre Barthelemy <[hidden email]> wrote:

> Hello,
>
> i am trying to copy Chaco Plot container onto the clipboard. I tried to
> adapt what is explained on the
> manual http://code.enthought.com/projects/chaco/docs/Chaco.pdf fur using
> pyQt. However, the following code has a problem: when i paste from the
> clipboard, i only have a black image. Could someone tell me what i did wrong
> ?
>
>
>
> width, height = plot.container.outer_bounds
> gc = PlotGraphicsContext((width, height), dpi=72)
> gc.render_component(plot.container)
>
> bitmap=QtGui.QImage(gc.bmp_array)
> clipboard=figure._parent.clipboard  #QApplication.clipboard()
> clipboard.setImage(bitmap)

Possibly, what's happening is that QImage is just using gc.bmp_array's
buffer interface to grab the pointer to the data and not making a copy
of the data. It is possible that setImage() works asynchronously and
returns before it really copies the data out onto the system's
clipboard. Try this:

  bitmap = QtGui.QImage(gc.bmp_array.copy())

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev