testinggtk r374 - trunk/tests



Author: bjornl
Date: Mon Aug 18 21:54:10 2008
New Revision: 374
URL: http://svn.gnome.org/viewvc/testinggtk?rev=374&view=rev

Log:
New function that encapsulates widget.get_snapshot(), also tweak the times for gtk_process_all_pending_events

Modified:
   trunk/tests/utils.py

Modified: trunk/tests/utils.py
==============================================================================
--- trunk/tests/utils.py	(original)
+++ trunk/tests/utils.py	Mon Aug 18 21:54:10 2008
@@ -104,10 +104,10 @@
     Let GTK process all events in its pending queue without blocking.
     '''
     gtk.main_iteration(False)
-    time.sleep(0.3)
+    time.sleep(0.05)
     while gtk.events_pending():
         gtk.main_iteration(False)
-        time.sleep(0.1)
+        time.sleep(0.05)
 
 def gtk_container_find_child(container, path):
     '''
@@ -172,3 +172,22 @@
         if r == red and g == green and b == blue:
             count += 1
     return count
+
+def widget_get_rendering(widget):
+    '''
+    Returns a ``gdk.Pixbuf`` which contains a rendering of the
+    `widget` aquired using ``widget.get_snapshot``
+
+    :param widget: a realized ``gtk.Widget``
+    :return: a ``gdk.Pixbuf`` of the rendered widget
+    '''
+    if not widget.window:
+        raise ValueError('widget must be realized')
+    width, height = widget.window.get_size()
+    clip = gdk.Rectangle(0, 0, width, height)
+    pixmap = widget.get_snapshot(clip)
+    pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, width, height)
+    pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
+                             0, 0, 0, 0,
+                             width, height)
+    return pixbuf



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]