[wxPython] Resize troubles

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Resize troubles

Vic Kelson
Hi All,

I am a recent convert from Visual Basic to Python/wxPython, and I must
say, Python and wxPython are great!  I'm writing a hydrological modeling
GUI, which is largely geographical in nature.  Here's my problem:

I am trapping the EVT_SIZE event for a wxFrame and forcing a redraw of
the map and the elements of the model.  Trouble is that a single resize
of the window fires many resize events, even if you hit the "maximize"
button.  The code begis a redraw, then another, then...  And on the LAST
event, the window is left blank *sigh*.  How do I check during a resize
event to see if the window is still resizing?  Can this be done?  Or can
I set the frame to only send ONE resize event when Windoze or the WM has
finished the stupid animation?

THANKS!  Keep up the good work!
Vic Kelson


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Resize troubles

Ken Seehof-2
Congratulations on switching from VB.  It takes courage to switch from
an industry standard to something better.

I'd suggest drawing to a backplane (a backplane is a bitmap in memory
that you can draw on).  Then you respond to paint messages by simply
blitting the bitmap onto the window.  Your current drawing routine only
needs to be invoked when the content changes.

If you do this, you probably won't mind the excess paint messages so much,
since the blit is very fast.

Something like this:

# called when content changes
def draw(self):
    self.cx, self.cy = ... # calculate the size of your map
    self.mbmp = wxEmptyBitmap(self.cx, self.cy)
    mdc = wxMemoryDC()
    mdc.SelectObject(self.mbmp)
    mdc.SetBackground(wxWHITE_BRUSH)
    mdc.Clear()
    # ... draw to mdc
    mdc.SelectObject(None)
    w.Refresh(false) # cause OnPaint to be called
 

# called when screen needs updating
def OnPaint (self, e):
    mdc = wxMemoryDC()
    mdc.SelectObject(self.mbmp)
    pdc = wxPaintDC(self)
    pdc.Blit(0, 0, self.cx, self.cy, mdc, 0, 0)
 

Vic Kelson wrote:

Hi All,

I am a recent convert from Visual Basic to Python/wxPython, and I must
say, Python and wxPython are great!  I'm writing a hydrological modeling
GUI, which is largely geographical in nature.  Here's my problem:

I am trapping the EVT_SIZE event for a wxFrame and forcing a redraw of
the map and the elements of the model.  Trouble is that a single resize
of the window fires many resize events, even if you hit the "maximize"
button.  The code begis a redraw, then another, then...  And on the LAST
event, the window is left blank *sigh*.  How do I check during a resize
event to see if the window is still resizing?  Can this be done?  Or can
I set the frame to only send ONE resize event when Windoze or the WM has
finished the stupid animation?

THANKS!  Keep up the good work!
Vic Kelson

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users