wxStaticText reverting to original size after Layout()

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.

Thanks,
Che

staticText_issue.py (2.36 KB)

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.

···

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.

--
Robin Dunn
Software Craftsman

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

···

On Sat, Mar 20, 2010 at 2:18 AM, Robin Dunn <robin@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=&#39;staticText1&#39;, name=&#39;staticText1&#39;, 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.

If it's going to pass anything, I would think wx.DefaultSize would
make the most sense since I'm pretty sure that's the default anyway.

···

On Mar 22, 10:20 am, C M <cmpyt...@gmail.com> wrote:

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

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

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.

It does reset the size of the widget to fit the text, but since the min size is also set then the size is changed to the min size again the next time Layout happens.

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.")

Yep.

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.

I agree. I started to write about this in my last reply but deleted it because it sounded too much like a negative rant and I couldn't think of a way to say it nicely. :slight_smile: To be fair, Boa has had designer support for brute-force layout (fixed positions and sizes) for a lot longer than it has understood sizers, so I'm sure that there are at least a few things where the sizer concept doesn't mesh well with the way that that Boa does things.

···

On 3/22/10 8:20 AM, C M wrote:

On Sat, Mar 20, 2010 at 2:18 AM, Robin Dunn<robin@alldunn.com> wrote:

On 3/19/10 9:30 PM, C M wrote:

--
Robin Dunn
Software Craftsman