On Sat, Mar 20, 2010 at 2:18 AM, Robin Dunn <ro...@alldunn.com> wrote:
> On 3/19/10 9:30 PM, C M wrote:
>> wxPython 2.8.10, Python 2.5, Windows.
>> I'm not sure if I'm misunderstanding something, but the attached
>> sample demonstrates the issue. If I use .SetLabel() on a
>> wxStaticTextCtrl, it works, and, as the docs state, it resizes to fit
>> the new and longer text. But once I resize the frame (or if I were to
>> call Layout(), which I think a manual resize of the frame results in),
>> the size of the staticText reverts to its original width.
>> Am I doing something wrong? This seems like it shouldn't be how it
>> behaves.
> self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
> label='staticText1', name='staticText1', parent=self.panel1,
> pos=wx.Point(0, 64), size=wx.Size(55, 13), style=0)
> By passing the size to the constructor you are setting the widget's min
> size, which overrides the best size when the Layout is done.
Thanks, Robin.
Some comments, for what it's worth...
The docs state this about .SetLabel(): "Sets the static text label
and updates the controls size to exactly fit the label unless the
control has wxST_NO_AUTORESIZE flag." Based on that language, I would
think I would not be the only person to be confused that, when a size
is initially set, the updated size is not persistent. Adding
something like, "Note, this updated size only persists if an initial
size for the widget is not set" would probably be helpful.
I've found, based on your suggestions now and I think one other time,
that the rule in wxPython (which I will try not to forget now) ought
to be: *Don't provide a size unless you have to.* (More generally:
"Don't provide a parameter unless you have to.")
Another point is that I use Boa Constructor, which, in the Designer,
does in fact set initial sizes (and placeholder content) for every
widget. So, this is a potential gotcha for Boa users, something to
keep in mind. I wonder if it could be possible to have Boa provide
size=(-1,-1) or just no size parameter given if one is in sizer-based
layout mode, but that might not be compatible with the idea of a
layout designer.
Che