Attached is a version of the GIR Clutter example (found here 
http://wiki.clutter-project.org/wiki/ExamplePython) slightly modified to 
include a cairo texture, for some reason, the rectangle and text work, and 
there's space as if there were another texture there, but the texture doesn't 
show up. 

Can anyone else verify this or propose a fix? I'm using pygobject-3 and clutter 
1.8

BR,
  K


#!/usr/bin/python
#-------------------------------------------------------------------------------
# Clutter_HelloWorld.py
#
# A basic reference example to demonstrate how to use Clutter with Python's 
# GObject-Introspection capabilities.
#
# by: Dinh Bowman
#-------------------------------------------------------------------------------

from gi.repository import Clutter
import sys

# An easy way to debug clutter and cogl without having to type the
# command line arguments
#DEBUG = True
DEBUG = False
debugArgs = ['--clutter-debug=all', '--cogl-debug=all']


# Define some standard colors to make basic color assigments easier
colorWhite = Clutter.Color.new(255,255,255,255)
colorMuddyBlue = Clutter.Color.new(49,78,108,255)
colorBlack = Clutter.Color.new(0,0,0,255)


class GUI:
    def __init__(self):
        """
        Build the user interface.
        """
        self.mainStage = Clutter.Stage.get_default()
        self.mainStage.set_color(colorBlack)
        self.mainStage.set_title("Python Clutter")
        self.mainStage.set_size(400, 150)
        self.mainStage.set_reactive(True)

        # Create a main layout manager
        self.mainLayoutManager = Clutter.BoxLayout()
        self.mainLayoutManager.set_vertical(True)
        self.mainLayoutManager.set_homogeneous(False)
        self.mainLayoutManager.set_pack_start(False)
        
        # Create the main window
        # mainStage 
        #  mainWindow :: mainLayoutManager
        self.mainWindow = Clutter.Box.new(self.mainLayoutManager)
        self.mainWindow.set_color(colorBlack)
        self.mainStage.add_actor(self.mainWindow)

        # Make the main window fill the entire stage
        mainGeometry = self.mainStage.get_geometry()
        self.mainWindow.set_geometry(mainGeometry)

        # Create some text
        self.renderText()

        # Create a rectangle
        self.renderRect()
        
        self.renderCairoTex()

        # Setup some key bindings on the main stage
        self.mainStage.connect_after("key-press-event", self.onKeyPress)

        # Present the main stage (and make sure everything is shown)
        self.mainStage.show_all()


    def renderText(self):
        """
        Create a ClutterText with the phrase Hello World
        """
        txtFont = "Mono 10"
        self.clutterText = Clutter.Text.new_full(txtFont, "Hello World", colorWhite)
        Clutter.Container.add_actor(self.mainWindow, self.clutterText)
        self.clutterText.set_position(5,5)
        self.clutterText.show()


    def renderRect(self):
        """
        Create a basic colored rectangle
        """
        self.clutterRectangle = Clutter.Rectangle.new_with_color(colorMuddyBlue)
        self.clutterRectangle.set_size(200,50)
        Clutter.Container.add_actor(self.mainWindow, self.clutterRectangle)
        self.clutterRectangle.show()

    def renderCairoTex(self):
        """
        Create a basic cairo texture
        """
        self.cairoTex = Clutter.CairoTexture.new(50,50)
        self.cairoTex.set_size(50,50)
        self.cairoTex.set_opacity(255)
        Clutter.Container.add_actor(self.mainWindow, self.cairoTex)
        
        cr = self.cairoTex.create()
        cr.set_source_rgb(1,1,0)
        cr.paint()
        del(cr)
        self.cairoTex.show()
        
    def destroy(self):
        Clutter.main_quit()


    def onKeyPress(self, actor=None, event=None, data=None):
        """
        Basic key binding handler
        """
        try:
            pressed = chr(event.key.keyval)

            # Evaluate the key modifiers
            state = event.get_state()
            if (state & state.SHIFT_MASK == state.SHIFT_MASK):
                modShift = True
            else:
                modShift = False

            if (state & state.CONTROL_MASK == state.CONTROL_MASK):
                modControl = True
            else:
                modControl = False

            if (state & state.META_MASK == state.META_MASK):
                modMeta = True
            else:
                modMeta = False

            if (pressed == 'q'):
                print "Quitting"
                self.destroy()
            elif (pressed == 'j'):
                print "Down"
            elif (pressed == 'k'):
                print "Up"
            elif (pressed == 'i'):
                print "Interrupt - Debug"
                try:
                    import ipdb as pdb
                except:
                    import pdb
                pdb.set_trace()
        except:
            pass


################################################################################
# Main
################################################################################
def main():
    if DEBUG:
        Clutter.init(debugArgs)
    else:
        Clutter.init(sys.argv)
    app = GUI()
    Clutter.main()
    
if __name__ == "__main__":
    sys.exit(main())

Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list

Reply via email to