OnPaint Resize

All,

I'm obviously not getting this OnPaint method with wx.PaintDC.

import wx
from math import hypot, sin, cos, pi

class Lines(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(450, 500))
        
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
        self.Center()
        self.Show()
        
    def OnPaint(self, event):
        
        dc = wx.PaintDC(self)
        
        size_x, size_y = self.GetClientSizeTuple()
        dc.SetDeviceOrigin(size_x / 2, size_y / 2)
        
        radius = hypot(size_x / 2, size_y / 2)
        angle = 0
        
        while (angle < 2 * pi):
            x = radius * cos(angle)
            y = radius * sin(angle)
            dc.DrawLinePoint((0, 0), (x, y))
            angle += pi / 180
        
app = wx.App(False)
Lines(None, -1, 'Lines')
app.MainLoop()

When I resize the window, making it bigger, the program does not recalculate a new center and redraw with a new center. I'm on a macbook pro.

What am I missing?

D.

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Only the newly "exposed" areas of the window are part of the update region when the paint event is sent, so the rest of the window is clipped out of what is drawn to the screen. In cases like this when changing size causes what is in the already visible portions of the window to also be changed then you need to force the whole window to be refreshed. There is a window style that can be used to do this, but usually I just call Refresh from an EVT_SIZE handler so it is more explicit what is happening.

I've attached a modified version of your sample that does this in a simple way that works fine for OSX. It will probably cause flicker on Windows though so it would need to be a bit more complex to work well everywhere.

arnold.py (914 Bytes)

···

On 5/4/10 8:40 PM, David Arnold wrote:

When I resize the window, making it bigger, the program does not recalculate a new center and redraw with a new center. I'm on a macbook pro.

What am I missing?

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Robin,

Thanks. That explains a lot.

D.

···

On May 4, 2010, at 9:40 PM, Robin Dunn wrote:

On 5/4/10 8:40 PM, David Arnold wrote:

When I resize the window, making it bigger, the program does not recalculate a new center and redraw with a new center. I'm on a macbook pro.

What am I missing?

Only the newly "exposed" areas of the window are part of the update region when the paint event is sent, so the rest of the window is clipped out of what is drawn to the screen. In cases like this when changing size causes what is in the already visible portions of the window to also be changed then you need to force the whole window to be refreshed. There is a window style that can be used to do this, but usually I just call Refresh from an EVT_SIZE handler so it is more explicit what is happening.

I've attached a modified version of your sample that does this in a simple way that works fine for OSX. It will probably cause flicker on Windows though so it would need to be a bit more complex to work well everywhere.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en&lt;arnold\.py&gt;

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en