From the migration guide, it sounded like as long as I specified a window
size as part of the constructor that it would be taken as the minimum size
for the window with respect to the new sizer changes.
However, I have a case in some existing code (currently being run
under wxPython 2.4.2.4) where that doesn't seem to be true - namely my
own subclass of wx.wxWindow (using the older naming scheme). I'm not
sure if the reference in the migration guide to the fact that all
controls were adjusted to use the constructor information also applies
to base wxWindows or not.
For example, my constructor code looks like (for my test I'm not using
the fullscreen path, so it's size is based on the image size):
- - - - - - - - - - - - - - - - - - - - - - - - -
class TPView(wx.wxWindow):
def __init__(self, tpctrl, monitor=False, options={}, parent=None):
self.tpimg = load_bitmap('TP.jpg')
self.options = options
if options.get('fullscreen',False):
size = parent.GetSize()
self.off_x = (size[0] - self.tpimg.GetWidth()) // 2
self.off_y = (size[1] - self.tpimg.GetHeight()) // 2
else:
size = (self.tpimg.GetWidth(), self.tpimg.GetHeight())
self.off_x = self.off_y = 0
wx.wxWindow.__init__(self, parent, -1, size=size)
(...)
- - - - - - - - - - - - - - - - - - - - - - - - -
And is installed into a sizer as by a parent window (of which it is part):
- - - - - - - - - - - - - - - - - - - - - - - - -
self.tpview = tpview.TPView(None,options=tpview_options,
parent=self)
self.vsizer = wx.wxBoxSizer(wx.wxVERTICAL)
(...)
self.vsizer.AddMany([(self.exer_title,0,wx.wxEXPAND),
(self.tpview,0,wx.wxALIGN_CENTER)])
- - - - - - - - - - - - - - - - - - - - - - - - -
But it ends up smaller than proper (and smaller than 2.4.2.4). If I
either add a call to self.SetMinSize(size) in the above constructor,
or add the wx.wxFIXED_MINSIZE flag to the AddMany call for the
self.tpview element, it works fine again. Of course, neither of those
approaches are backwards compatible with 2.4.2.4.
Should I expect this to work without those explicit changes? If not,
is there a better recommended way to tweak the code while remaining
compatible with 2.4.2.4?
Note that I do definitely like the sizer changes, as I think they
represent a better way to do things going forward, but am just looking
to try to remain source compatible (preferably without conditional
checks based on wx version, although I'll do that if I have to).
Thanks.
-- David