import pygtk import gtk, gobject, cairo, math from gtk import gdk class Screen( gtk.DrawingArea ): """ This class is a Drawing Area""" def __init__( self, w, h, speed ): super( Screen, self ).__init__( ) self.connect ( "expose_event", self.do_expose_event ) gobject.timeout_add( speed, self.tick ) # Go call tick every 'speed' whatsits. self.width, self.height = w, h self.set_size_request ( w, h ) def tick ( self ): self.alloc = self.get_allocation ( ) rect = gtk.gdk.Rectangle ( self.alloc.x, self.alloc.y, self.alloc.width, self.alloc.height ) self.window.invalidate_rect ( rect, True ) return True # Causes timeout to tick again. def do_expose_event( self, widget, event ): self.cr = self.window.cairo_create( ) self.draw( ) class MyStuff ( Screen ): def __init__ ( self, w, h, speed): Screen.__init__( self, w, h, speed ) def draw( self ): cr = self.cr # Shabby shortcut. cr.set_source_rgba(0.5, 0.1, 0.1, 1) cr.set_line_width(200) cr.arc(200, 200, 100, 0*(math.pi/180), -60*(math.pi/180)) cr.stroke() #cr.move_to(200, 200) #cr.arc(200, 200, 200, 0*(math.pi/180), -60*(math.pi/180)) #cr.fill() def run( Widget, w, h, speed ): window = gtk.Window() #window.move(0, 0) window.connect( "delete-event", gtk.main_quit ) widget = Widget( w, h, speed ) widget.show( ) window.add( widget ) window.present( ) gtk.main( ) run( MyStuff, 640, 480, speed = 20 )