programming using pyclutter

507 views Asked by At

I am new to clutter (and pyclutter). I have been trying to use pyclutter. I haven't found any good tutorial for it so far. I mean nothin that really explains properly. I saw a couple of example programs but when I tried to use pyclutter I dint get any good results. The commands are anailable but their proper use is what is causing a problem. I tried to render a line using pyclutter but haven't even been able to do that. My code:

import clutter
from clutter import cogl

stage = clutter.Stage()
stage.set_size(400, 400)

label = clutter.Text()
label.set_text("line")

stage.add(label)

clutter.cogl.set_source_color4ub (255,0,0,255)
clutter.cogl.path_line(100,100,200,200)
clutter.cogl.path_stroke()

stage.show_all()
stage.connect("destroy",clutter.main_quit)
clutter.main()

Its possible that my mistakes are really stupid, but i'd be really grateful if anyone could point me to a good tutorial where i can learn clutter(pyclutter) from.

1

There are 1 answers

1
tito On

This will not work, cause cogl is an abstraction to use OpenGL. In OpenGL world, the drawing must be done for everyframe. That's mean, your code will be executed only once, as soon as you window will flip, you'll not see the line. You can create a custom actor for that, and put your instruction in the do_paint() method :

class MyDrawing(clutter.Actor):
    __gtype_name__ = 'MyDrawing'
    def do_paint(self):
        clutter.cogl.set_source_color4ub (255,0,0,255)
        clutter.cogl.path_line(100,100,200,200)
        clutter.cogl.path_stroke()

And then, use it in your example like the Text actor:

stage.add(MyDrawing())