The proper way to capture Frame resize?

I recently tried to capture the evt_size event of a Frame but ended up
breaking the display. When I bound a function to the event, the Pane
within the Frame was no longer properly resized to display all of it's
contents.

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,
                          pos=(150, 150), size=(450, 552))

        self.Bind(wx.EVT_SIZE, self.OnFrameResize, self)

    def OnFrameResize(evt):
        print dir(evt)

I tried returning True in OnFrameResize but that didn't help either.

Thanks in advance for any help.
Josh

Hi,

···

On Wed, Jul 21, 2010 at 8:23 AM, Josh Russo <josh.r.russo@gmail.com> wrote:

I recently tried to capture the evt_size event of a Frame but ended up
breaking the display. When I bound a function to the event, the Pane
within the Frame was no longer properly resized to display all of it's
contents.

class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title,
pos=(150, 150), size=(450, 552))

   self\.Bind\(wx\.EVT\_SIZE, self\.OnFrameResize, self\)

def OnFrameResize(evt):
print dir(evt)

I tried returning True in OnFrameResize but that didn't help either.

The Frame has some builtin stuff that depends on the EVT_SIZE event
for sizing its main panel. Your handler is intercepting the event and
blocking the base classes from being called.

If you add a call to 'evt.Skip()' in your handler it should fix it.

Cody

Cool thanks.

I'll take a look at the code too, but what's that do?

···

On Jul 21, 12:29 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Wed, Jul 21, 2010 at 8:23 AM, Josh Russo <josh.r.ru...@gmail.com> wrote:
> I recently tried to capture the evt_size event of a Frame but ended up
> breaking the display. When I bound a function to the event, the Pane
> within the Frame was no longer properly resized to display all of it's
> contents.

> class MyFrame(wx.Frame):
> def __init__(self, parent, title):
> wx.Frame.__init__(self, parent, wx.ID_ANY, title,
> pos=(150, 150), size=(450, 552))

> self.Bind(wx.EVT_SIZE, self.OnFrameResize, self)

> def OnFrameResize(evt):
> print dir(evt)

> I tried returning True in OnFrameResize but that didn't help either.

The Frame has some builtin stuff that depends on the EVT_SIZE event
for sizing its main panel. Your handler is intercepting the event and
blocking the base classes from being called.

If you add a call to 'evt.Skip()' in your handler it should fix it.

Cody

Hi,

Hi,

> I recently tried to capture the evt_size event of a Frame but ended up
> breaking the display. When I bound a function to the event, the Pane
> within the Frame was no longer properly resized to display all of it's
> contents.

> class MyFrame(wx.Frame):
> def __init__(self, parent, title):
> wx.Frame.__init__(self, parent, wx.ID_ANY, title,
> pos=(150, 150), size=(450, 552))

> self.Bind(wx.EVT_SIZE, self.OnFrameResize, self)

> def OnFrameResize(evt):
> print dir(evt)

> I tried returning True in OnFrameResize but that didn't help either.

The Frame has some builtin stuff that depends on the EVT_SIZE event
for sizing its main panel. Your handler is intercepting the event and
blocking the base classes from being called.

If you add a call to 'evt.Skip()' in your handler it should fix it.

Cody

Cool thanks.

I'll take a look at the code too, but what's that do?

If you call an event objects Skip method it tells the framework that
the event should still be allowed to be processed by any other event
handlers that may be on the stack and are registered to handle that
event.

The base Frame class has code that handles EVT_SIZE so when the
Frame.__init__ is called its handler is registered. Then in your
derived class you also Bind to EVT_SIZE so there are now two handlers
for EVT_SIZE for that window. When the event happens yours is on the
top of the pile so it gets called first, not calling Skip will tell
the framework that your handler handled the event and that nothing
further needs to be done. However calling Skip says that the framework
should give any other handlers a chance to receive the event so the
base Frame classes handler then will get called as well.

Cody

···

On Wed, Jul 21, 2010 at 8:35 AM, Josh Russo <josh.r.russo@gmail.com> wrote:

On Jul 21, 12:29 pm, Cody Precord <codyprec...@gmail.com> wrote:

On Wed, Jul 21, 2010 at 8:23 AM, Josh Russo <josh.r.ru...@gmail.com> wrote:

Awesome, thanks again.

···

On Jul 21, 12:47 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

On Wed, Jul 21, 2010 at 8:35 AM, Josh Russo <josh.r.ru...@gmail.com> wrote:
> On Jul 21, 12:29 pm, Cody Precord <codyprec...@gmail.com> wrote:
>> Hi,

>> On Wed, Jul 21, 2010 at 8:23 AM, Josh Russo <josh.r.ru...@gmail.com> wrote:
>> > I recently tried to capture the evt_size event of a Frame but ended up
>> > breaking the display. When I bound a function to the event, the Pane
>> > within the Frame was no longer properly resized to display all of it's
>> > contents.

>> > class MyFrame(wx.Frame):
>> > def __init__(self, parent, title):
>> > wx.Frame.__init__(self, parent, wx.ID_ANY, title,
>> > pos=(150, 150), size=(450, 552))

>> > self.Bind(wx.EVT_SIZE, self.OnFrameResize, self)

>> > def OnFrameResize(evt):
>> > print dir(evt)

>> > I tried returning True in OnFrameResize but that didn't help either.

>> The Frame has some builtin stuff that depends on the EVT_SIZE event
>> for sizing its main panel. Your handler is intercepting the event and
>> blocking the base classes from being called.

>> If you add a call to 'evt.Skip()' in your handler it should fix it.

>> Cody

> Cool thanks.

> I'll take a look at the code too, but what's that do?

If you call an event objects Skip method it tells the framework that
the event should still be allowed to be processed by any other event
handlers that may be on the stack and are registered to handle that
event.

The base Frame class has code that handles EVT_SIZE so when the
Frame.__init__ is called its handler is registered. Then in your
derived class you also Bind to EVT_SIZE so there are now two handlers
for EVT_SIZE for that window. When the event happens yours is on the
top of the pile so it gets called first, not calling Skip will tell
the framework that your handler handled the event and that nothing
further needs to be done. However calling Skip says that the framework
should give any other handlers a chance to receive the event so the
base Frame classes handler then will get called as well.

Cody