hi;

On Sun, 2007-08-19 at 15:14 +0200, Stefan Schwarzburg wrote:
 
> Can someone give me a hint on what I'm doing wrong with the following
> code?
> I just want to paint something with cairo on an clutter actor. But I
> only get a blue stage with nothing on it. 
> I tried to compare the steps with with the flowers and clock example
> ( in C) but I did not see anything obvious. 

there is a clutter-cairo example in the examples/ directory of the
python bindings for clutter where I wrote what you need to do with the
context. for the archives:

> #!/usr/bin/env python
> import clutter
> import cairo
> from clutter import cluttercairo
> 
> stage = clutter.stage_get_default()
> stage.set_size(500, 500)
> stage.set_color (clutter.color_parse('Dark Blue'))
> stage.connect('key-press-event', clutter.main_quit)
> 
> cTexture = cluttercairo.CairoTexture(300,300)
> cTexture.set_position(50, 50)
> 
> cContext =  cTexture.cairo_create ()
> 
> cContext.set_operator(cairo.OPERATOR_OVER)
> cContext.set_line_width(5)
> cContext.set_source_rgba(0, 1, 0, 0.5)
> 
> cContext.move_to(100, 100)
> cContext.rel_line_to(100, 100)
> cContext.rel_line_to(-200, 0) 
> cContext.close_path()
> cContext.stroke()

delete (cContext) # you need to either explicitly destroy
                  # the cairo context or let it got out
                  # of the function scope; that's how the
                  # cairo context gets painted on the texture

> cTexture.show()
> 
> stage.add(cTexture)
> stage.show_all()
> 
> clutter.main()

the clutter-cairo bindings work automagically when you put the cairo
drawing operations into their own function and let the cairo context
variable go out of scope by itself; if you do everything into __main__
then the variable will never get out of scope and get destroyed - hence
the forced destruction via delete().

ciao,
 Emmanuele.

-- 
Emmanuele Bassi, OpenedHand Ltd.
Unit R, Homesdale Business Centre
216-218 Homesdale Rd., Bromley - BR12QZ
http://www.o-hand.com

-- 
To unsubscribe send a mail to [EMAIL PROTECTED]

Reply via email to