Sizer and wxStaticBitmap corruption

Hi

I am using sizers to layout a simple UI. The UI elements consist of graphics files that are loaded into wx.StaticBitmaps. Sizers control the layout of this so that there is 3 rows. The top and bottom rows are fixed in height, but may expand horizontally through an expanding "repeater" bitmap. The centre row has a panel that stretches both ways.

Problem is that when the frame is resized to a smaller size I am getting corruption of the wx.StaticBitmaps on the bottom row of the layout. In the code below, the top and bottom rows are set up in exactly the same manner, so there seems to be some kind of interaction with the vertical resize, or maybe its just a bug.

Anyone know what's going on?

Thanks.

Code is:

···

-----------------------
import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        myStyle = wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE
        wx.Frame.__init__(self, parent, id, title, style=myStyle)

        bmp1 = wx.StaticBitmap(self,-1, bitmap=wx.Image('left.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        bmp2 = wx.StaticBitmap(self,-1, bitmap=wx.Image('repeater.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        bmp3 = wx.StaticBitmap(self,-1, bitmap=wx.Image('right.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())

        bmp4 = wx.StaticBitmap(self,-1, bitmap=wx.Image('left.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        bmp5 = wx.StaticBitmap(self,-1, bitmap=wx.Image('repeater.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        bmp6 = wx.StaticBitmap(self,-1, bitmap=wx.Image('right.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())

        p = wx.Panel(self,-1, size=wx.Size(400,300), style=wx.SUNKEN_BORDER)
        p.SetBackgroundColour("BLACK")

        box1 = wx.BoxSizer(wx.HORIZONTAL)
        box1.Add(bmp1, 0, 0)
        box1.Add(bmp2, 1, wx.EXPAND)
        box1.Add(bmp3, 0, 0)

        box2 = wx.BoxSizer(wx.HORIZONTAL)
        box2.Add(10, 10, 0, 0) #spacer
        box2.Add(p, 1, wx.EXPAND)
        box2.Add(10, 10, 0, 0) #spacer

        box3 = wx.BoxSizer(wx.HORIZONTAL)
        box3.Add(bmp4, 0, 0)
        box3.Add(bmp5, 1, 0)
        box3.Add(bmp6, 0, 0)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(box1, 0, wx.EXPAND)
        mainSizer.Add(box2, 1, wx.EXPAND)
        mainSizer.Add(box3, 0, wx.EXPAND)
# mainSizer.SetSizeHints(self)

        self.SetAutoLayout(1)
        self.SetSizer(mainSizer)
        self.Fit()
        self.Layout()

app = wx.PySimpleApp()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show(1)
app.MainLoop()

Malcolm Hawke wrote:

Hi

I am using sizers to layout a simple UI. The UI elements consist of graphics files that are loaded into wx.StaticBitmaps. Sizers control the layout of this so that there is 3 rows. The top and bottom rows are fixed in height, but may expand horizontally through an expanding "repeater" bitmap. The centre row has a panel that stretches both ways.

Problem is that when the frame is resized to a smaller size I am getting corruption of the wx.StaticBitmaps on the bottom row of the layout. In the code below, the top and bottom rows are set up in exactly the same manner, so there seems to be some kind of interaction with the vertical resize, or maybe its just a bug.

You don't mention your platform, but I'll guess that it is Windows. IIRC, this is a combination of the wx.NO_FULL_REPAINT_ON_RESIZE style on the frame and the wxStaticBitmap not refreshing itself properly when it is resized. You can experiment with style flags (try wxCLIP_CHILDREN and wxCLIP_SIBLINGS too) and refreshing the static bitmaps and maybe you'll be able to come up with something that works.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi and thanks Robin.

You guessed right - I'm using Win2000.

Setting wx.CLIP_SIBLINGS on the wx.StaticBitmaps seems to have done the trick. I haven't seen wx.CLIP_SIBLINGS mentioned in the documentation before so this is new to me.

The next thing that I am struggling with is how to constrain the resize so that the wx.StaticBitmaps can not be resized smaller than their minimum sizes. I can do this by calling the main sizer's SetSizeHints() on the frame, but this prevents the frame from being resized any smaller than its contents. I'd like the contents to be clipped should the frame be resized any further, rather than have the layout changed.

Is this possible?

Malcolm Hawke wrote:

The next thing that I am struggling with is how to constrain the resize so that the wx.StaticBitmaps can not be resized smaller than their minimum sizes. I can do this by calling the main sizer's SetSizeHints() on the frame, but this prevents the frame from being resized any smaller than its contents. I'd like the contents to be clipped should the frame be resized any further, rather than have the layout changed.

Is this possible?

If a sizer item is expandable then it usually can be sized smaller than its minimum too. I expect that there is a way aroudn this, but I don't have time to experiment with it today to figure it out. Perhaps if you put each row of the wx.StaticBitmaps on their own panel with its own sizee, and put the panels in the Frame's sizer, then you could do something with it that way.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!