From: John H. <jdh...@ac...> - 2004-09-13 16:57:50
|
>>>>> "Matt" == Matt Newville <new...@ca...> writes: Matt> I agree that it would not be that easy with TkAgg. I think Matt> you have to use Tkinter.Canvas.postscript() to get a Matt> representation of the whole canvas. Then you'd have to Matt> convert postscript to a bitmap that can be copied to the Matt> clipboard (using clipboard_copy() / clipboard_append()). I Matt> think that's not very easy, as PIL is not that good with Matt> postscript. Matt> It might be easier to switch to the Agg backend and create a Matt> bitmap that can then be copied to the clipboard. This looks Matt> possible, and might make a more uniform way to copy to Matt> clipboard. Matt> By the way, for the WXAgg backend, copy to the clipboard is Matt> fairly simple, as it already provides the bitmap: For a Matt> canvas = FigureCanvasWxAgg(...) Matt> This works: bmp = wx.BitmapDataObject() Matt> bmp.SetBitmap(canvas.bitmap) wx.TheClipboard.Open() Matt> 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 |