problem refreshing cairo surface

Zoltán Vörös <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hi All,

I believe, this is a trivial problem, but lacking experience, I can't 
solve it, and I was wondering whether someone could lend a hand here. In 
short, I have a python class that just initialises a drawing area, and I 
would like to use it from somewhere else. It looks like this

class Preview:
     def __init__(self):
         self.da = Gtk.DrawingArea()
         self.da.set_size_request(400, 600)
         self.da.connect('configure-event', self.configure_event)
         self.da.connect('draw', self.on_draw)
         self.da.show()

     def configure_event(self, da, event):
         allocation = da.get_allocation()
         self.surface = 
da.get_window().create_similar_surface(cairo.CONTENT_COLOR,
                                                                 
allocation.width,
                                                                 
allocation.height)

         self.cairo_ctx = cairo.Context(self.surface)
         self.cairo_ctx.set_source_rgb(1, 1, 1)
         self.cairo_ctx.paint()
         return True

     def on_draw(self, da, cairo_ctx):
         cairo_ctx.set_source_surface(self.surface, 0, 0)
         cairo_ctx.paint()
         return True

     pass

Now, in a gui I have a button that calls the following function:


     def on_load(self, widget, data=None):

         self.DA = Preview()
         self.widget('box_preview').pack_start(self.DA.da, True, True, 0)

         self.DA.cairo_ctx.set_source_rgb(1, 0, 0)
         self.DA.cairo_ctx.paint()
         rect = self.DA.da.get_allocation()
         self.DA.da.get_window().invalidate_rect(rect, False)

         print 'here'


The function is executed without errors, and at the end 'here' is 
printed. Yet, the drawing area is not red as I would expect it from the 
line self.DA.cairo_ctx.set_source_rgb(1, 0, 0), but white, as done in 
the initialisation function. Of course, I could pass red as an argument 
to the init function, but that can't be a long-term solution, because I 
actually would like to manipulate the canvas from the main program.
I think I would formulate my question as what should one do in order to 
update the canvas from the main function?
Many thanks for any hints,
Zoltán

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.