Mathieu
Mathieu

Reputation: 7581

How to tell a panel that it is being resized when using wx.aui

I'm using wx.aui to build my user interface. I'm defining a class that inherits from wx.Panel and I need to change the content of that panel when its window pane is resized.

I'm using code very similar to the code below (which is a modified version of sample code found here).

My question is: is there a wx.Panel method being called behind the scenes by the AuiManager that I can overload? If not, how can my ControlPanel object know that it's being resized?

For instance, if I run this code and drag up the horizontal divider between the upper and lower panes on the right, how is the upper right panel told that its size just changed?

import wx
import wx.aui

class ControlPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.mgr = wx.aui.AuiManager(self)

        leftpanel = ControlPanel(self, -1, size = (200, 150))
        rightpanel = ControlPanel(self, -1, size = (200, 150))
        bottompanel = ControlPanel(self, -1, size = (200, 150))

        self.mgr.AddPane(leftpanel, wx.aui.AuiPaneInfo().Bottom())
        self.mgr.AddPane(rightpanel, wx.aui.AuiPaneInfo().Left().Layer(1))
        self.mgr.AddPane(bottompanel, wx.aui.AuiPaneInfo().Center().Layer(2))

        self.mgr.Update()


class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, '07_wxaui.py')
        frame.Show()
        self.SetTopWindow(frame)
        return 1

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

Upvotes: 2

Views: 999

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 285047

According to the wx.Panel docs, wx.Panel.Layout is called "automatically by the default EVT_SIZE handler when the window is resized."

EDIT: However, the above doesn't work as I would expect, so try manually binding EVT_SIZE:

class ControlPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        self.Bind(wx.EVT_SIZE, self.OnResize)

    def OnResize(self, *args, **kwargs):
        print "Resizing"

Upvotes: 3

Related Questions