From: Jean-Michel P. <jea...@ir...> - 2004-09-13 06:39:25
|
jm...@st... wrote: > I took a quick look at this and my impression is that clipboard support > must be explicitly added to the TkAgg backend and AFIK has not been. My > guess is that this is a wider reaching problem than TkAgg and it should > go into the list of future enhancements for matplotlib. > > Regards, > Todd It sounds more complicated than I thought. Indeed I was searching for existing solutions that would copy the window contents into clipboard. I know it is quite easy to do with Tcl/Tk and the BLT extension or something similar. You just call a function with the window path as arg and your clipboard is filled. This is why I focused on TkAgg. Thanks. JM. |
From: Matt N. <new...@ca...> - 2004-09-13 16:39:12
|
Hi, > It sounds more complicated than I thought. Indeed I was > searching for existing solutions that would copy the window > contents into clipboard. I know it is quite easy to do with > Tcl/Tk and the BLT extension or something similar. You just call > a function with the window path as arg and your clipboard is > filled. This is why I focused on TkAgg. 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() Hope that helps, --Matt |
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 |
From: Todd M. <jm...@st...> - 2004-09-13 17:53:25
|
On Mon, 2004-09-13 at 12:08, John Hunter wrote: > >>>>> "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. 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 > > 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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- |