开发者

(Py)GTK: How can I force my window to be repainted / call expose-event?

开发者 https://www.devze.com 2023-01-29 04:02 出处:网络
Currently I\'m drawing some things in a subclass of DrawingArea, where I get a cairo context inside an expose-event and call a draw method from there. (according to some PyGTK tu开发者_如何转开发toria

Currently I'm drawing some things in a subclass of DrawingArea, where I get a cairo context inside an expose-event and call a draw method from there. (according to some PyGTK tu开发者_如何转开发torial I found)

I'm used to doing a repaint() with java, but how can I get the same effect here?


Using queue_draw (which is actually defined for each widget) as you suggested is the correct way for doing it asynchronously. The documentation clearly states this:

gtk_widget_draw is deprecated and should not be used in newly-written code.

In GTK+ 1.2, this function would immediately render the region area of a widget, by invoking the virtual draw method of a widget. In GTK+ 2.0, the draw method is gone, and instead gtk_widget_draw() simply invalidates the specified region of the widget, then updates the invalid region of the widget immediately. Usually you don't want to update the region immediately for performance reasons, so in general gtk_widget_queue_draw_area() is a better choice if you want to draw a region of a widget.

If you fear the drawing delay is too high, then instead of drawing synchronously, you should invalidate only the area that needs to be redrawn (using queue_draw_area).


I found a solution that uses the queue_draw() method (callable from the Gtk.DrawingArea but seems like a method every gtk widget must have), but there are probably alternatives since this one implies it might get delayed, even though in my tests it didn't happen.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号