Hi Dischi, here's the ported cairo-clock example: http://paste.debian.net/147341/
so long
:wq buz
On Mon, Nov 28, 2011 at 07:57:38PM +0100, Dirk Meyer wrote:
> On 11/05/2011 11:51 AM, Dirk Meyer wrote:
> > I'm trying to port my Python code to gi.repository since this seems to
> > be the only way I will be able to mix clutter, gtk and gstreamer. Most
> > of the stuff already works, but the cairo texture is causing problems.
> >
> > I tried the "old" way to just get the context and draw whenever I want
> > as well as using texture.connect_after('draw', draw). I do not get an
> > error, but I never see the texture.
>
> Anyone here knowing how to use cairo with python gi?
>
> Regards,
>
> Dirk
> --
> I pretend to work. They pretend to pay me.
> _______________________________________________
> clutter-app-devel-list mailing list
> [email protected]
> http://lists.clutter-project.org/listinfo/clutter-app-devel-list
--
This is a free country. You have a right to send me email, and I have a right
not to read them!
GnuPG Fingerprint: 2FFF FC48 C7DF 1EA0 00A0 FD53 8C35 FD2E 6908 7B82
import math
import cairo
from datetime import datetime
from gi.repository import GObject
from gi.repository import Clutter
class CairoClock(Clutter.CairoTexture):
def __init__(self, **kwargs):
Clutter.CairoTexture.__init__(self, **kwargs)
self.connect('draw', self._draw_cb)
self.invalidate()
GObject.timeout_add_seconds(1, self._tick_cb)
def _draw_cb(self, texture, cr):
# clock drawing code from http://www.cairographics.org/SDLCLock
# store the current time
now = datetime.now()
# compute the angles for the indicators of our clock
hours = now.hour * math.pi / 6
minutes = now.minute * math.pi / 30
seconds = now.second * math.pi / 30
# Scale to surface size
width, height = self.get_surface_size()
cr.scale(width, height)
# Clear our surface
cr.set_operator (cairo.OPERATOR_CLEAR)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
# who doesn't want all those nice line settings :)
cr.set_line_cap(cairo.LINE_CAP_ROUND)
cr.set_line_width(0.1)
# translate to the center of the rendering context and draw a black
# clock outline
cr.set_source_rgba(0, 0, 0, 1)
cr.translate(0.5, 0.5)
cr.arc(0, 0, 0.4, 0, math.pi * 2)
cr.stroke()
# draw a white dot on the current second.
cr.set_source_rgba(1, 1, 1, 0.6)
cr.arc(math.sin(seconds) * 0.4, -math.cos(seconds) * 0.4, 0.05, 0, math.pi * 2)
cr.fill()
# draw the minutes indicator
cr.set_source_rgba(0.2, 0.2, 1, 0.6)
cr.move_to(0, 0)
cr.line_to(math.sin(minutes) * 0.4, -math.cos(minutes) * 0.4)
cr.stroke()
# draw the hours indicator
cr.move_to(0, 0)
cr.line_to(math.sin(hours) * 0.2, -math.cos(hours) * 0.2)
cr.stroke()
# XXX: It's important to return True!
# See http://docs.clutter-project.org/docs/clutter/stable/ClutterCairoTexture.html#ClutterCairoTexture-draw
return True
def _tick_cb(self):
self.invalidate()
# XXX: You also have to return True here!
return True
if __name__ == '__main__':
import sys
Clutter.init(sys.argv[1:])
stage = Clutter.Stage()
stage.connect('destroy', lambda stage: Clutter.main_quit())
stage_color = Clutter.Color.new(0x99, 0xcc, 0xff, 0xff)
stage.set_color(stage_color)
clock = CairoClock(width=300, height=300, auto_resize=True)
clock.set_position(stage.get_width() / 2 - clock.get_width() / 2,
stage.get_height() / 2 - clock.get_height() / 2)
stage.add_actor(clock)
stage.show()
Clutter.main()
signature.asc
Description: Digital signature
_______________________________________________ clutter-app-devel-list mailing list [email protected] http://lists.clutter-project.org/listinfo/clutter-app-devel-list
