wx.PySizer

Inheritance diagram for wx.PySizer:



Description

wx.PySizer is a special version of wx.Sizer that has been instrumented to allow the C++ virtual methods to be overloaded in Python derived classes. You would derive from this class if you are wanting to implement a custom sizer in Python code. Simply implement CalcMin and RecalcSizes in the derived class and you’re all set.

For example:

class MySizer(wx.PySizer):
    """ A simple wx.PySizer derived class. """

    def __init__(self):
        """ Default class constructor. """

        wx.PySizer.__init__(self)


    def CalcMin(self):
        "Re-implemented from wx.Sizer.CalcMin. """

        for item in self.GetChildren():
            # Calculate the total minimum width and height needed
            # by all items in the sizer according to this sizer's
            # layout algorithm.

            DoSizeCalculation(item)

        return wx.Size(width, height)


    def RecalcSizes(self):
        "Re-implemented from wx.Sizer.RecalcSizes. """

        # Find the space allotted to this sizer
        pos = self.GetPosition()
        size = self.GetSize()

        for item in self.GetChildren():
            # Recalculate (if necessary) the position and size of
            # each item and then call item.SetDimension to do the
            # actual positioning and sizing of the items within the
            # space alloted to this sizer.

            item.SetDimension(itemPos, itemSize)

When Layout is called it first calls CalcMin followed by RecalcSizes so you can optimize a bit by saving the results of CalcMin and reusing them in RecalcSizes.

Derived From

Methods Summary

Class API

Methods

__init__()

Creates a wx.PySizer. Must be called from the __init__ in the derived class.


Returns:

wx.PySizer