SetSizeHints() on OS X

Hi,

Attached you'll find a small sample showing the problem. I've got a
frame with some controls. These controls are created with a "starting"
size set (and added to a sizer). The frame should then fit to these
sizes. Aside from that the controls get minimum- and
maximum-size-hints. So if the user resizes the frame they should not
grow larger or shrink smaller than specified.

It works fine under GTK and OS X. The maximum-size-hint does not work
on MSW at all, but that is known. The real problem on OS X is the
initial size of the multiline edit in my sample app below. It has the
same size as the first textentry. When I resize the frame for a single
pixle, it snaps back to the smaller size it should have started with. On
wx.GTK the multiline starts with the proper size (smaller than the first
entry).

What am I doing wrong here? Do I need some kind of Refresh() or
Layout() after doing the SetSizeHints() on OS X ?

Thanks for you help,
Johannes

minmax.py (1.4 KB)

···

--
BYTEWISE Software GmbH Tel +43 (5577) 89877-0
i.A. Johannes Vetter Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2 http://www.bytewise.at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Individuelle Datenbanklösungen für GNU/Linux, Windows und
Mac OSX: http://www.bytewise.at/leistungen/gnue-indiv.html

Hi Johannes,

It works fine under GTK and OS X. The maximum-size-hint does
not work on MSW at all, but that is known.

I don't know where you got that info... I am just curious, what is preventing SetMaxSize() to work on Windows?
BTW, quoting the manual:

"
wxWindow::SetSizeHints
Use of this function for windows which are not toplevel windows (such as wxDialog or wxFrame) is discouraged. Please use SetMinSize and SetMaxSize instead

"

I have no idea why it doesn't work correctly on OSX, but you might try with SetMinSize/SetMaxSize (though I doubt it will make any difference). Ah, moreover, is there a particular reason for which you put the widgets directly inside a frame?. I don't know if this is still valid (maybe someone more knowledgeable than me may shed some light about the latest wxPython releases), but it's usually recommended to use a panel inside a frame and attach the widgets to the panel. But things might have changed.

Andrea.

···

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Mobile Tel: +44 (0) 77 487 70534
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Johannes Vetter wrote:

Hi,

Attached you'll find a small sample showing the problem. I've got a
frame with some controls. These controls are created with a "starting"
size set (and added to a sizer). The frame should then fit to these
sizes. Aside from that the controls get minimum- and
maximum-size-hints. So if the user resizes the frame they should not
grow larger or shrink smaller than specified.

It works fine under GTK and OS X. The maximum-size-hint does not work
on MSW at all, but that is known. The real problem on OS X is the
initial size of the multiline edit in my sample app below. It has the
same size as the first textentry. When I resize the frame for a single
pixle, it snaps back to the smaller size it should have started with. On
wx.GTK the multiline starts with the proper size (smaller than the first
entry).

What am I doing wrong here? Do I need some kind of Refresh() or
Layout() after doing the SetSizeHints() on OS X ?

* The sizers don't currently do anything with the max size hint. Where it appears to work currently it is because the widget itself is refusing to change to the size that the sizer tells it to.

* The issue you have on OSX is because you are setting the max size hints after you have fit the frame to the size requested by the sizer with the original min size values (those passed to the widget constructors.) So since there is no additional size event after that point then nothing is being resized and so the max hints don't kick in.

One way to get the size adjusted the way you want is to actually change the size of the frame programatically, something like this:

  self.SetSize(self.GetSize() + (1,1))

···

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

Gavana, Andrea wrote:

I have no idea why it doesn't work correctly on OSX, but you might
try with SetMinSize/SetMaxSize (though I doubt it will make any
difference).

It won't. SetSizeHints for non top-level windows is just a wrapper around SetMinSize and SetMaxSize.

···

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

Hi Andrea,

I don't know where you got that info... I am just curious, what is
preventing SetMaxSize() to work on Windows?

Hm, setting a maximum size has no effect at all on windows, at least
this sample shows it.

wxWindow::SetSizeHints
Use of this function for windows which are not toplevel windows (such
as wxDialog or wxFrame) is discouraged. Please use SetMinSize and
SetMaxSize instead

I didn't know this. I've used SetSizeHints() only because it was one
function call instead of two :slight_smile:

I have no idea why it doesn't work correctly on OSX, but you might try
with SetMinSize/SetMaxSize (though I doubt it will make any
difference). Ah, moreover, is there a particular reason for which you
put the widgets directly inside a frame?. I don't know if this is
still valid (maybe someone more knowledgeable than me may shed some
light about the latest wxPython releases), but it's usually
recommended to use a panel inside a frame and attach the widgets to
the panel. But things might have changed.

I've created the sample app to be as short as possible but as complete
as need to show the effect (or the problem).

Attached is another (more complete version) of the sample which is still
not working on OS X and MSW.

Thanks anyway,

Johannes

minmax.py (1.64 KB)

···

Am Dienstag, den 16.01.2007, 15:43 +0000 schrieb Gavana, Andrea:
--
BYTEWISE Software GmbH Tel +43 (5577) 89877-0
i.A. Johannes Vetter Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2 http://www.bytewise.at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Individuelle Datenbanklösungen für GNU/Linux, Windows und
Mac OSX: BYTEWISE Software GmbH - Unsere Leistungen - Datenbanklösungen

Hi Robin,

Thanks for your answer.

* The issue you have on OSX is because you are setting the max size
hints after you have fit the frame to the size requested by the sizer
with the original min size values (those passed to the widget
constructors.) So since there is no additional size event after that
point then nothing is being resized and so the max hints don't kick
in.

But the problem here is, that on OS X the multiline text edit does not
appear in the size as given in the constructor, which is (120, -1) in
the sample. Instead it has the same size as the single-line text control
which is created with a size of (300, -1).

Setting the SizeHints *after* Fit() is intended as I wanted to have a
'starting' size of the controls being in between their minimum and
maximum size. If I would call the SetSizeHints() *before* the Fit() all
controls would be rendered with their minimal size (which is smaller
than the size given in the constuctors).

Thanks for your help,

Johannes

···

Am Dienstag, den 16.01.2007, 10:45 -0800 schrieb Robin Dunn:

--
BYTEWISE Software GmbH Tel +43 (5577) 89877-0
i.A. Johannes Vetter Fax +43 (5577) 89877-66
A-6890 Lustenau, Enga 2 http://www.bytewise.at
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Individuelle Datenbanklösungen für GNU/Linux, Windows und
Mac OSX: BYTEWISE Software GmbH - Unsere Leistungen - Datenbanklösungen

Johannes Vetter wrote:

Hi Robin,

Thanks for your answer.

* The issue you have on OSX is because you are setting the max size hints after you have fit the frame to the size requested by the sizer with the original min size values (those passed to the widget constructors.) So since there is no additional size event after that point then nothing is being resized and so the max hints don't kick
in.

But the problem here is, that on OS X the multiline text edit does not
appear in the size as given in the constructor, which is (120, -1) in
the sample. Instead it has the same size as the single-line text control
which is created with a size of (300, -1).

Because you used the wx.EXPAND flag when adding it to the sizer.

···

Am Dienstag, den 16.01.2007, 10:45 -0800 schrieb Robin Dunn:

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