sizer problem with wxSTC on Windows

The following code is adapted from a problem I've been having with the PythonCard webserver sample and simply forgot to report previously. The issue is that the size passed in at init (800, 327) seems to be ignored on Windows, but works as expected on the Mac. The behavior changed a while ago, but I don't remember which 2.5.2.x release it was. The initSizers code is my standard way of dealing with layouts where there is only one item on a panel and the window is supposed to be growable. I haven't noticed the issue with other controls like TextCtrl so this may simply be a bug where the min size is not set properly at init on Windows with a wxSTC?!

import wx
from wx import stc

print "wx.VERSION", wx.VERSION

class MyApp(wx.App):

     def OnInit(self):
         self.frame = wx.Frame(None, -1, "sizer problem", size=(800, 482))
         self.panel = wx.Panel(self.frame, -1)

         # on Windows the window will be small
         # but on the Mac the window will be the size specified below
         self.text = stc.StyledTextCtrl(self.panel, -1, (0, 0), (800, 327))

         self.frame.Show(True)
         self.SetTopWindow(self.frame)
         self.initSizers()

         return True

     def initSizers(self):
         sizer1 = wx.BoxSizer(wx.VERTICAL)
         sizer1.Add(self.text, 1, wx.EXPAND)

         sizer1.Fit(self.frame)
         sizer1.SetSizeHints(self.frame)
         self.panel.SetSizer(sizer1)
         self.panel.SetAutoLayout(1)
         self.panel.Layout()

app = MyApp(0)
app.MainLoop()

ka

Kevin Altis wrote:

The following code is adapted from a problem I've been having with the PythonCard webserver sample and simply forgot to report previously. The issue is that the size passed in at init (800, 327) seems to be ignored on Windows, but works as expected on the Mac. The behavior changed a while ago, but I don't remember which 2.5.2.x release it was. The initSizers code is my standard way of dealing with layouts where there is only one item on a panel and the window is supposed to be growable. I haven't noticed the issue with other controls like TextCtrl so this may simply be a bug where the min size is not set properly at init on Windows with a wxSTC?!

Correct, wxSTC is not setting the min size. The reason it appears to work on the Mac is probably due to a different order of initial size events and also the fact that wxSTC also does not have a DoGetBestSize. By the time the sizer does a CalcMin and Layout the wxSTC has already been sized and so the default DoGetBestSize is falling back to "best size is current size" since there are no sizers or child windows.

I'll fix wxSTC but I'm not sure I want it to hold up the release if there are no show-stoppers as there is a very easy work-around for this, just call self.text.SetMinSize.

···

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