Grid size/display

This is of those sizer-related questions
that always drives me mad.

Suppose I have a grid in a panel inside a
sizer in a window and when the window is created I want it to display the
entire grid. That is, the window should come up sized to exactly display
the grid, for example. How to do this?

In the more general case, I would want to
figure out the size of the grid (i.e., the size of it’s displayed image)
and perhaps then have the window come up to display some portion of that
– but I’ll settle for the simpler goal to begin with.

I notice that none of the demos do anything
like this – which makes me think that maybe it’s not so easy to do. But
in general, if the purpose of my window is primarily to display my grid,
and my grid is a “reasonable” size, then I’d like the window
to display the whole grid with no ugly extra space to its right or below.
Every one of the demos either displays only part of the grid or else
displays the entire grid with a bunch of extra space. Is it really
that tricky?

···

Gary H. Merrill

Director and Principal Scientist, New Applications

Data Exploration Sciences

GlaxoSmithKline Inc.

(919) 483-8456

well is not that tricky, you'll have to remember that *sizers* do the layout.
so... back to your problem:
- make sure the grid is in a sizer and set the sizer to be panel's sizer.
- make sure you're using proportion=1 and flag=wx.EXPAND where they need to be used.
- use SetSizeHints and Fit to achieve a certain size of the window on first show.

···

On Thu, 19 Aug 2004 10:58:57 -0400, <gary.h.merrill@gsk.com> wrote:

This is of those sizer-related questions that always drives me mad.

Suppose I have a grid in a panel inside a sizer in a window and when the
window is created I want it to display the entire grid. That is, the
window should come up sized to exactly display the grid, for example. How
to do this?

In the more general case, I would want to figure out the size of the grid
(i.e., the size of it's displayed image) and perhaps then have the window
come up to display some portion of that -- but I'll settle for the simpler
goal to begin with.

I notice that none of the demos do anything like this -- which makes me
think that maybe it's not so easy to do. But in general, if the purpose
of my window is primarily to display my grid, and my grid is a
"reasonable" size, then I'd like the window to display the whole grid with
no ugly extra space to its right or below. Every one of the demos either
displays only part of the grid or else displays the entire grid with a
bunch of extra space. Is it really that tricky?

--
Peter Damoc
Hacker Wannabe

Okay. Suppose I remember all that (which
is what the code now does and has been doing all along). What I was
really asking for was how to set it to the “certain size”. So
far as I can see, you can set these sizer options all you like, and the
outer window still won’t size to the size of the internal grid.

For example, the GridCustTable.py code for
the custom grid table demo is a very simple implementation of just this
sort. It appears to conform to all of the the requirements you list
except for calls to SetSizeHints() and Fit(). In order to make use
of SetSizeHints() I of course need to know the size for the hints (the
“certain size” referred to). But I don’t.

So exactly what needs to be added to this
code to get the window to come up sized exactly for the grid displayed
in it? How do I find out what that “certain size” is?

···

Gary H. Merrill

Director and Principal Scientist, New Applications

Data Exploration Sciences

GlaxoSmithKline Inc.

(919) 483-8456

“Peter Damoc”
pdamoc@gmx.net

19-Aug-2004 11:44

Please respond to wxPython-users@lists.wxwidgets.org

To

wxPython-users@lists.wxwidgets.org
cc

Subject

Re: [wxPython-users] Grid
size/display

`On Thu, 19 Aug 2004 10:58:57 -0400, gary.h.merrill@gsk.com
wrote:

This is of those sizer-related questions that always drives me mad.

Suppose I have a grid in a panel inside a sizer in a window and when
the

window is created I want it to display the entire grid. That is, the

window should come up sized to exactly display the grid, for example.

How

to do this?

In the more general case, I would want to figure out the size of the
grid

(i.e., the size of it’s displayed image) and perhaps then have the
window

come up to display some portion of that – but I’ll settle for the

simpler

goal to begin with.

I notice that none of the demos do anything like this – which makes
me

think that maybe it’s not so easy to do. But in general, if
the purpose

of my window is primarily to display my grid, and my grid is a

“reasonable” size, then I’d like the window to display the
whole grid

with

no ugly extra space to its right or below. Every one of the
demos either

displays only part of the grid or else displays the entire grid with
a

bunch of extra space. Is it really that tricky?

well is not that tricky, you’ll have to remember that sizers do the

layout.

so… back to your problem:

  • make sure the grid is in a sizer and set the sizer to be panel’s sizer.

  • make sure you’re using proportion=1 and flag=wx.EXPAND where they need

to be used.

  • use SetSizeHints and Fit to achieve a certain size of the window on

first show.

Peter Damoc

Hacker Wannabe


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

`

This is really a wx.Grid issue, not a sizer issue, and I haven't worked with wx.Grid much.

wx.Grid.GetBestSize() method might return what you want. In practice it may not. I've had trouble with some other widgets whose Best Size changes depending on what you put in them.

This is all tricky with windows that have scrollbars..it's hard to define what a "minimum acceptable" size is. What you really want is a wx.Grid method that returns the unscrolled size. You may be able to write your own, using GetRowHeight and GetColWidth.

Also, give wx.Grid.Fit() a try.

-Chris

···

gary.h.merrill@gsk.com wrote:

  In order to make use of SetSizeHints() I of course need to
know the size for the hints (the "certain size" referred to). But I don't.

So exactly what needs to be added to this code to get the window to come up sized exactly for the grid displayed in it? How do I find out what that "certain size" is?

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Sorry for sounding so condescend :slight_smile: is one of my worst character flaws :wink:
As Chris Barker mentioned, there are a lot of tricky things when scrolls are involved.
The attached file shows what I understood you wanted. As it can be seen the scrolls appear even if in theory the shouldn't have.

Here is what Robin suggested as a solution for the scrollbars problem
http://thread.gmane.org/gmane.comp.python.wxpython.devel/616

grid.py (589 Bytes)

···

On Thu, 19 Aug 2004 15:36:23 -0400, <gary.h.merrill@gsk.com> wrote:

Okay. Suppose I remember all that (which is what the code now does and
has been doing all along). What I was really asking for was how to set it to the "certain size". So far as I can see, you can set these sizer
options all you like, and the outer window still won't size to the size of the internal grid.

--
Peter Damoc
Hacker Wannabe

Actually, your grid.py file doesn’t even
compile for me. When I fix it so that it does compile, it pops up
a window displaying only the title bar and none of the grid (like it thinks
the initial size of the grid panel is 0 – which in fact probably is the
minimum size of that panel). Are you saying that you can actually
run the code you posted and that it works?

grid.py (591 Bytes)

···

Gary H. Merrill

Director and Principal Scientist, New Applications

Data Exploration Sciences

GlaxoSmithKline Inc.

(919) 483-8456

“Peter Damoc”
pdamoc@gmx.net

20-Aug-2004 02:27

Please respond to wxPython-users@lists.wxwidgets.org

To

wxPython-users@lists.wxwidgets.org
cc

Subject

Re: [wxPython-users] Grid
size/display

`On Thu, 19 Aug 2004 15:36:23 -0400, gary.h.merrill@gsk.com
wrote:

Okay. Suppose I remember all that (which is what the code now
does and

has been doing all along). What I was really asking for was
how to set

it to the “certain size”. So far as I can see, you
can set these sizer

options all you like, and the outer window still won’t size to the
size

of the internal grid.

Sorry for sounding so condescend :slight_smile: is one of my worst character flaws
:wink:

As Chris Barker mentioned, there are a lot of tricky things when scrolls

are involved.

The attached file shows what I understood you wanted. As it can be seen

the scrolls appear even if in theory the shouldn’t have.

Here is what Robin suggested as a solution for the scrollbars problem

http://thread.gmane.org/gmane.comp.python.wxpython.devel/616

Peter Damoc

Hacker Wannabe

http://www.sigmacore.net/---------------------------------------------------------------------

To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org`

Oops... forgot to say:
2.5.2.7u on python 2.3.4 on WinXP SP1 :smiley:
it works here :slight_smile:
attached is a screenshot :o)

···

On Fri, 20 Aug 2004 12:59:50 -0400, <gary.h.merrill@gsk.com> wrote:

Actually, your grid.py file doesn't even compile for me. When I fix it so
that it does compile, it pops up a window displaying only the title bar
and none of the grid (like it thinks the initial size of the grid panel is
0 -- which in fact probably is the *minimum* size of that panel). Are you
saying that you can actually run the code you posted and that it works?

--
Peter Damoc
Hacker Wannabe

Well, it’s a bit distressing that the code
seems to work so differently between 2.4 and 2.5. I don’t think I’ll
convert to 2.5 right at the moment. But I suppose it’s good to know
that this will work okay in the future (of course there are some assumptions
behind this belief).

···

Gary H. Merrill

Director and Principal Scientist, New Applications

Data Exploration Sciences

GlaxoSmithKline Inc.

(919) 483-8456

As it happens, one the improvements in 2.5 has to do with the handling of initial sizer of Windows when placed in Sizers, so I'm not surprised that this works better. A search of this list and/or wx-users should turn up the discussion, but I'm not sure you'll get much from it except that this might well work better under 2.5, which you already know.

-Chris

···

gary.h.merrill@gsk.com wrote:

Well, it's a bit distressing that the code seems to work so differently between 2.4 and 2.5.

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Ok... I owe you an apologize... :slight_smile: The code I sent you doesn't work... it was not intentional, I was high... :slight_smile:
It's due to the fact that I'm one of those update junkies.
Looking again at the code I realise that it uses features so new that even older versions of 2.5 won't be able to compile it :slight_smile: Like the lack of IDs :slight_smile: one feature I LOVE in the new 2.5 series :slight_smile:

Attached is a version that should work in 2.4. It is the best that I could do :slight_smile:

grid.py (857 Bytes)

···

On Fri, 20 Aug 2004 13:50:51 -0400, <gary.h.merrill@gsk.com> wrote:

Well, it's a bit distressing that the code seems to work so differently
between 2.4 and 2.5. I don't think I'll convert to 2.5 right at the
moment. But I suppose it's good to know that this will work okay in the
future (of course there are some assumptions behind this belief).

--
Peter Damoc
Hacker Wannabe