[wxPython] Another sizer problem...

Hi,

I've been scratching together some code for popping up a nice-looking dialog
on interpreter errors [either with or without a stack traceback] recently
(well, I significantly rewrote some earlier code, which used to work rather
well with Python 1.5.2 and wxPython 2.1 or so, but hasn't been working for
almost a year...), using wxDesigner for much of the tedious work... the code
works well, except (and this is the show-stopper) for the sizers...

The code emitted by wxDesigner to "populate" a dialog (/panel) is of the
form in the attached file e_wdr.py (actually I've only included one of the
four "populate_*" functions; they're all similar). I actually have (at
least) 2 distinct (well, I think they're distinct anyway) problems with
this...

Firstly, the box sizers don't seem to automatically adjust to the size of a
changing wxStaticText, like the program name in the example. This is
despite what the documentation says (or rather SEEMS TO ME to be saying--I
could be misinterpreting it...??) about a wxStaticText without the
flag wxST_NO_AUTORESIZE (From the documentation: "By default, the control
will adjust its size to exactly fit to the size of the text when SetLabel is
called. If this style flag is given, the control will not change its size
(this style is especially useful with controls which also have wxALIGN_RIGHT
or CENTER style because otherwise they won't make sense any longer after a
call to SetLabel)"

Secondly (and Iwon't include a code sample here), I'm trying to knock
together a wxPySizer-derived class for sizing a wxTextCtrl (or a wxTextCtrl
within a wxScrolledWindow) which reports the "natural size" of the text text
as it's 'minimal size' unless this is larger than a certain fraction of the
display size, in which case it will report that given fraction [causing the
wxTextCtrl to be "clipped", or made accessible only through scrolling...
eventually...]. I've started from the file lib/grips.py, but am having
problems... has anyone done something similar which they would be able to
share?

Oh, incidentally, all this is planned for (hopefully almost immediate)
contribution to the wxPython library...

Cheerio, Chris

e_wdr.py (6.1 KB)

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com>
or <mailto:Chris.Fama@uq.net.au>
Brisbane, Australia
Phone: (0/+61)(7) 3870 5639 {10am-10pm GMT+10 on both these numbers please}
Mobile: (0/+61)(400) 833 700
-------------------------------------------------------------------------
Business page: <http://whollysnakes.com>
Personal page: <http://uq.net.au/~zzcfama>
-------------------------------------------------------------------------

Sorry, 2 additional points, one of which was a "typo": the flag I mentioned
to the wxStaticText constructor would cause the size to be adjusted
automatically on a call to SetLabel, but that will not cause an automatic
relayout... but the RecalcSizes, Fit, and Layout methods of the sizer class
don't seem to do the job either.

I imagine I'll need to send a code sample--later...

Secondly, That should have been lib/grids.py.

Chris

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com>
         or <mailto:Chris.Fama@uq.net.au>
Brisbane, Australia
Phone: (0/+61)(7) 3870 5639 {10am-10pm GMT+10 on both these numbers please}
Mobile: (0/+61)(400) 833 700
-------------------------------------------------------------------------
Business page: <http://whollysnakes.com>
Personal page: <http://uq.net.au/~zzcfama&gt;
-------------------------------------------------------------------------

----- Original Message -----
From: "Chris Fama" <chris.fama@uq.net.au>
To: <wxpython-users@lists.wxwindows.org>
Sent: Monday, September 10, 2001 11:10 PM
Subject: [wxPython] Another sizer problem...

Hi,

I've been scratching together some code for popping up a nice-looking

dialog

on interpreter errors [either with or without a stack traceback] recently
(well, I significantly rewrote some earlier code, which used to work

rather

well with Python 1.5.2 and wxPython 2.1 or so, but hasn't been working for
almost a year...), using wxDesigner for much of the tedious work... the

code

works well, except (and this is the show-stopper) for the sizers...

The code emitted by wxDesigner to "populate" a dialog (/panel) is of the
form in the attached file e_wdr.py (actually I've only included one of the
four "populate_*" functions; they're all similar). I actually have (at
least) 2 distinct (well, I think they're distinct anyway) problems with
this...

Firstly, the box sizers don't seem to automatically adjust to the size of

a

changing wxStaticText, like the program name in the example. This is
despite what the documentation says (or rather SEEMS TO ME to be saying--I
could be misinterpreting it...??) about a wxStaticText without the
flag wxST_NO_AUTORESIZE (From the documentation: "By default, the control
will adjust its size to exactly fit to the size of the text when SetLabel

is

called. If this style flag is given, the control will not change its size
(this style is especially useful with controls which also have

wxALIGN_RIGHT

or CENTER style because otherwise they won't make sense any longer after a
call to SetLabel)"

Secondly (and Iwon't include a code sample here), I'm trying to knock
together a wxPySizer-derived class for sizing a wxTextCtrl (or a

wxTextCtrl

within a wxScrolledWindow) which reports the "natural size" of the text

text

as it's 'minimal size' unless this is larger than a certain fraction of

the

display size, in which case it will report that given fraction [causing

the

wxTextCtrl to be "clipped", or made accessible only through scrolling...
eventually...]. I've started from the file lib/grips.py, but am having
problems... has anyone done something similar which they would be able to
share?

Oh, incidentally, all this is planned for (hopefully almost immediate)
contribution to the wxPython library...

Cheerio, Chris

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com>
or <mailto:Chris.Fama@uq.net.au>
Brisbane, Australia
Phone: (0/+61)(7) 3870 5639 {10am-10pm GMT+10 on both these numbers

please}

Mobile: (0/+61)(400) 833 700
-------------------------------------------------------------------------
Business page: <http://whollysnakes.com>
Personal page: <http://uq.net.au/~zzcfama&gt;
-------------------------------------------------------------------------

Firstly, the box sizers don't seem to automatically adjust to the size of

a

changing wxStaticText, like the program name in the example. This is
despite what the documentation says (or rather SEEMS TO ME to be saying--I
could be misinterpreting it...??) about a wxStaticText without the
flag wxST_NO_AUTORESIZE (From the documentation: "By default, the control
will adjust its size to exactly fit to the size of the text when SetLabel

is

called. If this style flag is given, the control will not change its size
(this style is especially useful with controls which also have

wxALIGN_RIGHT

or CENTER style because otherwise they won't make sense any longer after a
call to SetLabel)"

The docs say that the control will adjust, but it doesn't say anything about
the sizer. The sizer takes the size the control had when it was added to
the sizer as the minimum size. After that time the sizer manages the size
based on it's layout algorithm, so even if the control changes its own size,
the sizer won't notice and will just change it back to what it wants it to
be the next time Layout() is called. If you want the size to change its
idea of what the minimum size should be then you can do it something like
this:

    text.SetLabel("New Label")
    size = text.GetBestSize()
    sizer.SetItemMinSize(text, size.width, size.height)
    window.Layout()

Secondly (and Iwon't include a code sample here), I'm trying to knock
together a wxPySizer-derived class for sizing a wxTextCtrl (or a

wxTextCtrl

within a wxScrolledWindow) which reports the "natural size" of the text

text

as it's 'minimal size' unless this is larger than a certain fraction of

the

display size, in which case it will report that given fraction [causing

the

wxTextCtrl to be "clipped", or made accessible only through scrolling...
eventually...]. I've started from the file lib/grips.py, but am having
problems... has anyone done something similar which they would be able to
share?

You'll need to get the font used, and then measure the size of the text
using that font on the target window using GetTextExtent. You can then base
your size calculations off of that.

···

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

Robin:

Many, many thanks for that!

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com>
         or <mailto:Chris.Fama@uq.net.au>
Brisbane, Australia
Phone: (0/+61)(7) 3870 5639 {10am-10pm GMT+10 on both these numbers please}
Mobile: (0/+61)(400) 833 700
-------------------------------------------------------------------------
Business page: <http://whollysnakes.com>
Personal page: <http://uq.net.au/~zzcfama&gt;
-------------------------------------------------------------------------

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, September 14, 2001 3:22 PM
Subject: Re: [wxPython] Another sizer problem...

> Firstly, the box sizers don't seem to automatically adjust to the size

of

a
> changing wxStaticText, like the program name in the example. This is
> despite what the documentation says (or rather SEEMS TO ME to be

saying--I

> could be misinterpreting it...??) about a wxStaticText without the
> flag wxST_NO_AUTORESIZE (From the documentation: "By default, the

control

> will adjust its size to exactly fit to the size of the text when

SetLabel

is
> called. If this style flag is given, the control will not change its

size

> (this style is especially useful with controls which also have
wxALIGN_RIGHT
> or CENTER style because otherwise they won't make sense any longer after

a

> call to SetLabel)"

The docs say that the control will adjust, but it doesn't say anything

about

the sizer. The sizer takes the size the control had when it was added to
the sizer as the minimum size. After that time the sizer manages the size
based on it's layout algorithm, so even if the control changes its own

size,

the sizer won't notice and will just change it back to what it wants it to
be the next time Layout() is called. If you want the size to change its
idea of what the minimum size should be then you can do it something like
this:

    text.SetLabel("New Label")
    size = text.GetBestSize()
    sizer.SetItemMinSize(text, size.width, size.height)
    window.Layout()

> Secondly (and Iwon't include a code sample here), I'm trying to knock
> together a wxPySizer-derived class for sizing a wxTextCtrl (or a
wxTextCtrl
> within a wxScrolledWindow) which reports the "natural size" of the text
text
> as it's 'minimal size' unless this is larger than a certain fraction of
the
> display size, in which case it will report that given fraction [causing
the
> wxTextCtrl to be "clipped", or made accessible only through scrolling...
> eventually...]. I've started from the file lib/grips.py, but am having
> problems... has anyone done something similar which they would be able

to

> share?

You'll need to get the font used, and then measure the size of the text
using that font on the target window using GetTextExtent. You can then

base

your size calculations off of that.

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users