views:

255

answers:

1

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()
+3  A: 

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"
Matthew Flaschen
Yup. I hadn't thought of binding the event myself... thanks!
Matt