自己做一个cairo clock
由于手头工作的原因,我要接触cairo这个矢量图形库,因为它的免费高效跨平台。如果你现在使用的Firefox 3浏览器,那么恭喜你,Cairo正在为你工作。当然了,GTK和Gnome这样的项目也采用了Cairo。
Cairo:http://www.cairographics.org/
下面的内容你可能需要一些GTK和python的前置知识。还有Cairo本身.
import gtk
import pygtk
import cairo
import math
import time
import gobject
class Clock(gtk.DrawingArea):
def progress_timeout(self, object):
width, height = self.get_parent().size_request()
#Adds region to the update area for window
object.window.invalidate_rect((0, 0, width, height), False)
return True
def __init__(self):
gtk.DrawingArea.__init__(self)
self.connect(“expose_event”, self.expose_cb)
self.timer = gobject.timeout_add (300, self.progress_timeout, self)
def expose_cb(self, widget, event):
self.context = widget.window.cairo_create()
# set a clip region for the expose event
self.context.rectangle(event.area.x, event.area.y,
[...]