[pyclutter] examples: Add more comments to the image-content example



commit 9391231cd58749a2dc52e47c6d56ac81636d9630
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Apr 16 12:01:59 2015 +0100

    examples: Add more comments to the image-content example

 examples/image-content.py |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/examples/image-content.py b/examples/image-content.py
index 2698ad2..f6ca829 100644
--- a/examples/image-content.py
+++ b/examples/image-content.py
@@ -31,44 +31,55 @@ current_gravity = 0
 def on_tap(action, actor, text):
     global gravities, current_gravity
 
+    # Change the label
+    text.props.text = 'Content Gravity: ' + gravities[current_gravity][1]
+
+    # Animate the content gravity changes
     with actor.easing_state():
         actor.set_content_gravity(gravities[current_gravity][0])
 
-    text.props.text = 'Content Gravity: ' + gravities[current_gravity][1]
-
+    # Cycle through all gravities
     current_gravity += 1
     if current_gravity >= len(gravities):
         current_gravity = 0
 
 if __name__ == '__main__':
+    # Our stage
     stage = Clutter.Stage(title='Content Box', user_resizable=True)
     stage.set_margin(Clutter.Margin(12))
     stage.connect('destroy', Clutter.main_quit)
     stage.show()
 
+    # Load the texture data from a file
     pixbuf = GdkPixbuf.Pixbuf.new_from_file('redhand.png')
 
+    # Use the correct pixel format depending on whether the image
+    # has an alpha channel
     pixel_format = Cogl.PixelFormat.RGB_888
     if pixbuf.get_has_alpha():
         pixel_format = Cogl.PixelFormat.RGBA_8888
 
+    data = pixbuf.read_pixel_bytes()
     width = pixbuf.get_width()
     height = pixbuf.get_height()
     stride = pixbuf.get_rowstride()
 
+    # The Image content knows how to draw texture data
     image = Clutter.Image()
-    image.set_bytes(pixbuf.read_pixel_bytes(), pixel_format, width, height, stride)
+    image.set_bytes(data, pixel_format, width, height, stride)
 
+    # A Stage is like any other actor, and can paint a Content
     stage.set_content_gravity(Clutter.ContentGravity.RESIZE_ASPECT)
-    stage.set_content_scaling_filters(Clutter.ScalingFilter.TRILINEAR,
-                                      Clutter.ScalingFilter.LINEAR)
+    stage.set_content_scaling_filters(Clutter.ScalingFilter.TRILINEAR, Clutter.ScalingFilter.LINEAR)
     stage.set_content(image)
 
+    # Show a label with the current content gravity
     label = 'Content Gravity: Resize Aspect'
     text = Clutter.Text(text=label)
     text.add_constraint(Clutter.AlignConstraint(source=stage, align_axis=Clutter.AlignAxis.BOTH, factor=0.5))
     stage.add_child(text)
 
+    # Change the content gravity on tap/click
     action = Clutter.TapAction()
     action.connect('tap', on_tap, text)
     stage.add_action(action)


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