使用pyclutter进行编程 [英] programming using pyclutter

查看:73
本文介绍了使用pyclutter进行编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是杂物(和pyclutter)的新手.我一直在尝试使用pyclutter.到目前为止,我还没有找到任何好的教程.我的意思是,这没什么真正可以解释的.我看到了几个示例程序,但是当我尝试使用pyclutter时,我得到了很多不错的结果.这些命令是可粘贴的,但是导致问题的原因是正确使用它们.我试图使用pyclutter渲染一条线,但甚至无法做到这一点.我的代码:

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()

我的错误很可能是愚蠢的,但是如果有人能指出我一个很好的教程,我可以从中学习混乱(pyclutter),我将不胜感激.

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.

推荐答案

这将不起作用,因为cogl是使用OpenGL的抽象.在OpenGL世界中,必须为每个帧绘制图形.就是说,您的代码将只执行一次,一旦窗口翻转,您将看不到该行. 您可以为此创建一个自定义actor,并将您的指令放入do_paint()方法中:

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()

然后,在您的示例中使用它,例如Text actor:

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

stage.add(MyDrawing())

这篇关于使用pyclutter进行编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆