[pygtk] Using get_snapshot with obscured widgets

Robert Schroll rschroll at gmail.com
Tue Nov 10 14:11:14 WST 2009


Dear all,

I have been trying to use get_snapshot to create a raster image of a 
widget.  This widget is in a gtk.TextView, so it may or may not be 
visible, depending on the scrolling position.  What I've found is that 
everything works when the widget is fully visible.  If the widget is 
completely obscured, I get junk, and if it is partially obscured, only 
the visible part of the widget shows up okay in the image.

Attached is a sample application which demonstrates the problem.  When 
the "Take Snapshot" button is pressed, get_snapshot() is called on a 
gtk.Label at the top of the TextView, and the resultant image is saved 
to snapshot.png.  For me at least, this works when the Label is visible 
in the TextView, but produces a junk image when the TextView has been 
scrolled downwards.

Previously, I had been using GTK 2.16.1.  With that version, I found 
that I could get things to work if I wrapped the Label in a 
gtk.EventBox.  I theorized that the X-window associated with the 
EventBox gave the widget something to draw onto even when I was not 
visible.  Upon upgrading to 2.18, however, I've found that this hack no 
longer works.

I'm very much new to GTK programming, so I apologize if this is an 
obvious issue to everyone else.  My questions are:
- Am I using get_snapshot() correctly?
- Is get_snapshot supposed to work with non-visible widgets?
- If so, should I submit this as a bug?
- If not, is there another way to render existing widgets to raster images?

Thank you,
Robert

-------------- next part --------------
A non-text attachment was scrubbed...
Name: snapshot.py
Type: text/x-python
Size: 1548 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20091110/ca88a61f/attachment.py 


More information about the pygtk mailing list