开发者

Force repaint in wxPython Canvas

开发者 https://www.devze.com 2023-03-07 03:36 出处:网络
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

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

精彩评论

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

关注公众号