clipboard copy

I agree that it would not be that easy with TkAgg. I think

    > you have to use Tkinter.Canvas.postscript() to get a
    > representation of the whole canvas. Then you'd have to
    > convert postscript to a bitmap that can be copied to the
    > clipboard (using clipboard_copy() / clipboard_append()). I
    > think that's not very easy, as PIL is not that good with
    > postscript.

    > It might be easier to switch to the Agg backend and create a
    > bitmap that can then be copied to the clipboard. This looks
    > possible, and might make a more uniform way to copy to
    > clipboard.

    > By the way, for the WXAgg backend, copy to the clipboard is
    > fairly simple, as it already provides the bitmap: For a
    > canvas = FigureCanvasWxAgg(...)

    > This works: bmp = wx.BitmapDataObject()
    > bmp.SetBitmap(canvas.bitmap) wx.TheClipboard.Open()
    > wx.TheClipboard.SetData(bmp) wx.TheClipboard.Close()

I don't know about how one accesses the operating system clipboard in
tk or the other GUI toolkits (I assume this is platform dependent),
but it is easy to get the bitmap from tkagg. FigureCanvasTkAgg
derives from FigureCanvasAgg, which provides a method tostring_rgb.
You should be able to use this to create a bitmap for copying to the
clipboard.

This is how wxagg's FigureCanvasWxAgg gets the bitmap in the first
place

    def draw(self):
        """
        Render the figure using agg
        """
        DEBUG_MSG("draw()", 1, self)

        FigureCanvasAgg.draw(self)
        s = self.tostring_rgb()
        w = int(self.renderer.width)
        h = int(self.renderer.height)
        image = wxEmptyImage(w,h)
        image.SetData(s)
        self.bitmap = image.ConvertToBitmap()

Hope this helps...

Thanks for the wx example.

JDH

    > I agree that it would not be that easy with TkAgg. I think
    > you have to use Tkinter.Canvas.postscript() to get a
    > representation of the whole canvas. Then you'd have to
    > convert postscript to a bitmap that can be copied to the
    > clipboard (using clipboard_copy() / clipboard_append()). I
    > think that's not very easy, as PIL is not that good with
    > postscript.

    > It might be easier to switch to the Agg backend and create a
    > bitmap that can then be copied to the clipboard. This looks
    > possible, and might make a more uniform way to copy to
    > clipboard.

    > By the way, for the WXAgg backend, copy to the clipboard is
    > fairly simple, as it already provides the bitmap: For a
    > canvas = FigureCanvasWxAgg(...)

    > This works: bmp = wx.BitmapDataObject()
    > bmp.SetBitmap(canvas.bitmap) wx.TheClipboard.Open()
    > wx.TheClipboard.SetData(bmp) wx.TheClipboard.Close()

I don't know about how one accesses the operating system clipboard in
tk or the other GUI toolkits (I assume this is platform dependent),
but it is easy to get the bitmap from tkagg. FigureCanvasTkAgg
derives from FigureCanvasAgg, which provides a method tostring_rgb.
You should be able to use this to create a bitmap for copying to the
clipboard.

That sounds pretty easy. I have two questions:

1. What is meant by "bitmap"? How standard is the format?

2. Is a "bitmap" the right format? What about EPS?

I guess that was 4.

Cheers,
Todd

···

On Mon, 2004-09-13 at 12:08, John Hunter wrote:

This is how wxagg's FigureCanvasWxAgg gets the bitmap in the first
place

    def draw(self):
        """
        Render the figure using agg
        """
        DEBUG_MSG("draw()", 1, self)

        FigureCanvasAgg.draw(self)
        s = self.tostring_rgb()
        w = int(self.renderer.width)
        h = int(self.renderer.height)
        image = wxEmptyImage(w,h)
        image.SetData(s)
        self.bitmap = image.ConvertToBitmap()

Hope this helps...

Thanks for the wx example.

JDH

-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--