Hi
Does any one know why am I getting this error in the attached file?
Why can't I use DrawingArea in gtk?
File "/home/rob/cairo.py", line 9, in <module>
import gtk
File "/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 40,
in <module>
from gtk import _gtk
File "/home/rob/cairo.py", line 12, in <module>
class EggClockFace(gtk.DrawingArea):
--
--
Rob
#!/usr/bin/env python
# clock_ex2.py
# a pygtk widget that implements a clock face
# author: Lawrence Oluyede <l.oluy...@gmail.com>
# date: 03 December 2005
import gtk
import math
class EggClockFace(gtk.DrawingArea):
def __init__(self):
gtk.DrawingArea.__init__(self)
self.connect("expose_event", self.expose)
def expose(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,
event.area.width, event.area.height)
self.context.clip()
self.draw(self.context)
return False
def draw(self, context):
rect = self.get_allocation()
x = rect.x + rect.width / 2
y = rect.y + rect.height / 2
radius = min(rect.width / 2, rect.height / 2) - 5
# clock back
context.arc(x, y, radius, 0, 2 * math.pi)
context.set_source_rgb(1, 1, 1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
for i in xrange(12):
inset = 0.1 * radius
context.move_to(x + (radius - inset) * math.cos(i * math.pi / 6),
y + (radius - inset) * math.sin(i * math.pi / 6))
context.line_to(x + radius * math.cos(i * math.pi / 6),
y + radius * math.sin(i * math.pi / 6))
context.stroke()
def main():
window = gtk.Window()
clock = EggClockFace()
window.add(clock)
window.connect("destroy", gtk.main_quit)
window.show_all()
gtk.main()
if __name__ == "__main__":
main()
_______________________________________________
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/