title: Drawing a point with cairo through a gobject.timeout_add callback function
body: <p>I have an almost-working piece of code (I hope). In the update method of this class, random black points should be drawn at locations bounded by the width and height of the window - the problem is that the points are not drawn. A gtk window containing the background image  that is loaded with the cairo ImageSurface.create_from_png(BG_IMG) is displayed and I've also verified that the update function is called (every 17ms with a gobject.timeout_add callback function). I've searched here and elsewhere, but I can't quite see what's wrong with this code..</p>
  
  <pre><code>class Screen(gtk.DrawingArea):
  
      __gsignals__ = {"expose-event": "override"}
  
      def do_expose_event(self, event):
          self.cr = self.window.cairo_create()
  
          self.cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
          self.cr.clip()
          self.draw(*self.window.get_size())
  
      def draw(self, width, height):
          x = y = 0
          self.bg = c.ImageSurface.create_from_png(BG_IMG)
          self.cr.set_source_surface(self.bg, x, y)
          self.cr.paint()
  
      def update(self):
          x = randint(0, DOCK_W)
          y = randint(0, DOCK_H)
          self.cr.rectangle(x, y, 1, 1)
          self.cr.set_source_rgba(0, 0, 0, 1)
          self.cr.fill()
          self.cr.paint()
  </code></pre>
  
  <p>Anybody have some insights into why this is code is failing? Big thanks in advance!</p>
  
  <h2>Solved</h2>
  
  <p>I was unaware that a new cairo context could be used at each draw operation. That turned out to be the main problem.</p>