开发者

Force repaint in wxPython Canvas

I've got a Canvas which manipulates objects in the mouse event handler. After modifying the objects, I want to trigger the OnPaint() event for the same Canvas to show (rerender) the changes. What is the right way to do this? It doesn't let me call OnPaint() directly. Also, is triggering an event from another event "wrong" in some sense, or likely to lead to trou开发者_Python百科ble?


I would just call self.Refresh() or maybe RefreshRect() and pass the area that needs to be repainted.


I tried self.refresh() as suggested by Mike Driscoll. That worked partially. I'm moving my own objects with mouse events and then repainting the image - rendering my objects. So the mouse events were updating coordinates and the repaint was updating the display. The problem is that refresh() seems to be called lazily or has lower priority than the mouse events. Refresh() thus produces a choppy display.

Since I am using a buffered display via the wxDemo for Scrolled Area, I took the following line from the Paint event:

dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)

And called my drawing function with that DC from within the mouse event handler. Upon completion dc is freed and (according to the comments in the demo) copied to the screen. It was not previously clear to me how the Paint event was handling DCs, so I was trying to call the event. Turns out you can use that DC and just render from inside the mouse events. This results in smooth dragging of my custom drawn objects.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜