0

Python 2.7

We are attempting to upgrade from Wx 2.8 to 2.9. We've run into an issue where old code no longer behaves the same in the new version. I have prepared a small example to demonstrate the issue. I believe the problem is stemming from a few lines of code in one of our panels:

self.SetSize((-1, 55))
self.SetMinSize(self.GetSize())
self.SetMaxSize(self.GetSize())

Perhaps someone has run into this issue and found a different way of achieving the above results? When calling GetSize, the width returns as 20 pixels on the new version of Wx.

WxPython 2.8.12.1

enter image description here

WxPython 2.9.5.0

enter image description here .

Here is a sample program that behaves as I've described:

import wx

class OperatorPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.__operatorCombo = OperatorCombo(self)

        borderBox = wx.StaticBox(self, -1, "Operator")
        hbox = wx.StaticBoxSizer(borderBox, wx.VERTICAL)
        hbox.Add(self.__operatorCombo, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        self.SetSizer(hbox)
        self.SetSize((-1, 55))
        self.SetMinSize(self.GetSize())
        self.SetMaxSize(self.GetSize())

class OperatorCombo(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.__comboBox = wx.ComboBox(self, style=wx.CB_READONLY)
        self.__btnAdd = wx.Button(self, label='...', size=(20, -1))
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.__comboBox, 5, flag=wx.EXPAND)
        hsizer.Add(self.__btnAdd, 1)
        self.SetSizer(hsizer)

class TestApp(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)

        self.SetSize((350, 300))

        self.__panTop = wx.Panel(self)
        self.__panBottom = wx.Panel(self)

        self.__panOperator1 = OperatorPanel(self.__panTop)
        self.__panOperator2 = OperatorPanel(self.__panTop)

        self.__btnTest = wx.Button(self.__panBottom, -1, "Test", wx.DefaultPosition, wx.DefaultSize, 0)
        testSizer = wx.BoxSizer(wx.HORIZONTAL)
        testSizer.Add(self.__btnTest, 0, flag=wx.EXPAND)
        self.__panBottom.SetSizer(testSizer)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        hbox.Add(self.__panOperator1, 1, flag=wx.EXPAND)
        hbox.AddSpacer(5)
        hbox.Add(self.__panOperator2, 1, flag=wx.EXPAND)
        vbox.Add(hbox, flag=wx.EXPAND)

        self.__panTop.SetSizer(vbox)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        vsizer.Add(self.__panTop, 1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=3)
        vsizer.AddSpacer(5)
        vsizer.Add(self.__panBottom, 1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=3)
        # Add more stuff here

        self.SetSizer(vsizer)

app = wx.App()
dlg = TestApp(None)
dlg.ShowModal()
dlg.Destroy()

If those three lines are removed, it behaves normally, though the controls are too big vertically.

Thanks.

1 Answer 1

0

It has to do with the StaticBoxSizer, for some reason it doesn't have/get the correct size.

A workaround I found is replacing the three lines with the following:

    self.SetSize((-1, 55))
    self.Layout()

    wx.CallAfter(self.mySetSize)

def myPrint(self):
    print('myPrint')
    print(self.GetSize())

def mySetSize(self):
    print('myGetSize')
    self.myPrint()
    self.SetMinSize(self.GetSize())
    self.SetMaxSize(self.GetSize())

The print stuff is obviously just for debugging.

BTW, why are you not going up to 3.0.2, or maybe even to wxPython-Phoenix?

2.9.5 will not get any fixes and 3.0.2 has a few corrections which never made it into 2.9.5.

1
  • Hmm, well for our purposes, setting a variable for max / min size and calling that instead of GetSize will work fine. We only updated to fix a blocker-bug fixed in 2.9.5. Going further would require too much migration time. The plan is to phase out python. Jul 27, 2015 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.