Questions about wx.Grid

I'm trying to implement a GUI using several grid objects in a panel
such that the first grid will not be sized when the window expands and
somehow (what I'm trying to figure out how to do) will not scroll when
the window is scrolled right in order to view other grids on the
panel. I have 1 grid which shouldn't move and 9 grids that will
participate in horizontal scrolling. All grids will participate in
vertical scrolling. My thought was to use a SetTargetWindow (or
something else?) to notify the scrolledwindow that only grids 2-10
should scroll. I don't know if this is possible nor can I figure out
how to do it. If my approach is doable, perhaps there's a way I can
determine the upper left coordinates of grid 2 and the lower right
coordinates of grid 10 and with those coordinates passed to the
SetTargetWindow (or?) magic will happen...

The first grid is a 1 column 40 row grid which contains information
common to each of the other grids. I don't want to repeat it in each
grid as it would look tacky. So, if I can leave it on-screen after
the gui is built, the user can scroll everything vertically and when
he/she scrolls horizontally only the grids other than the leftmost
will participate in the scrolling (each of these grids is a 6 column
40 row grid.

Can anyone help me?

I'm trying to implement a GUI using several grid objects in a panel
such that the first grid will not be sized when the window expands and
somehow (what I'm trying to figure out how to do) will not scroll when
the window is scrolled right in order to view other grids on the
panel. I have 1 grid which shouldn't move and 9 grids that will
participate in horizontal scrolling. All grids will participate in
vertical scrolling. My thought was to use a SetTargetWindow (or
something else?) to notify the scrolledwindow that only grids 2-10
should scroll. I don't know if this is possible nor can I figure out
how to do it. If my approach is doable, perhaps there's a way I can
determine the upper left coordinates of grid 2 and the lower right
coordinates of grid 10 and with those coordinates passed to the
SetTargetWindow (or?) magic will happen...

The SetTargetWindow works differently than you seem to think it does. In fact the Grid is already using it so it makes a good example to use for the explanation. The Grid is actually composed of 4 windows that are children of the Grid (the scrolled window,) one for the row labels, one for the col labels, one for the corner between the labels and one for the actual grid area, called the GridWindow. The Grid passes the GridWindow to SetTargetWindow so any scrolling events that happen to the Grid are actually handled by that child window instead. So instead of scrolling all of the content of the Grid (including the label windows) only the GridWindow content is scrolled.

The first grid is a 1 column 40 row grid which contains information
common to each of the other grids. I don't want to repeat it in each
grid as it would look tacky. So, if I can leave it on-screen after
the gui is built, the user can scroll everything vertically and when
he/she scrolls horizontally only the grids other than the leftmost
will participate in the scrolling (each of these grids is a 6 column
40 row grid.

Can anyone help me?

If I understand you correctly you could probably do what you want with two panels instead of just one. Or actually one panel and one wx.ScrolledWindow. Put the first grid (the one that is to stay always visible) on the panel and put the others on the scrolled window in a horizontal box sizer and use FitInside so the sizer will set the virtual size of the scrolled window. The grid's best size may not be calculated in a way that fits with what you want to do here, so you should probably explicitly set their min size so that value will be used instead.

If this is not what you are wanting to do then please explain it some more and/or draw a picture or create a small runnable sample that shows what you've tried so far.

···

On 11/17/11 7:51 PM, johncblacker wrote:

--
Robin Dunn
Software Craftsman

Thanks Robin…in your first response paragraph you indicate that Grid is already using 4 separate panels and that the labels are always visible but only the gridwindow area scrolls…I’m not experiencing it that way. When I put grids in a scrollablewindow with a horizontal boxsizer I’m finding that the grids scroll completely - labels and all. I’ve circumvented the problem somewhat by doing the following:

master panel

vertical boxsizer—>topscrollablepanel

horizontal boxsizer

topleftscrollablepanel

left grid (proportion = 1)

toprightscrollablepanel

right grids 2-10 (proportion = 10)

—>botscrollablepanel

horizontal boxsizer

botleftscrollablepanel

left grid (proportion =1 )

botrightscrollablepanel

right grids 2-10) proportion = 10)

This isn’t bad, but imperfect. The left grid(s) don’t expand very much, the right grids scroll both horizontally and vertically. The labels also participate in the scroll and the top labels scroll off the screen if I scroll down. Since each of the grids 2-10 have the same layout and labels at the top, having the labels scroll off horizontally is OK, but it wouldn’t make sense for them to remain on the screen if it were scrolled down AND right…

Guess I need to do some experimenting with grid and better understand how it works.

Thanks for your reply Robin.

So…did some experimenting and arrived at the following conclusion. You can’t put a grid inside a sizer as that messes things up…like the ability to scroll while keeping the labels in view. I took the simple grid app from the wxPython in Action book and modified it slightly like so:

import wx
import wx.grid

class TestFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, title=“simple grid”,
size=(640, 480))
gsizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(gsizer)
grid = wx.grid.Grid(self)
grid.CreateGrid(50,50)
for row in range(20):
for col in range(6):
grid.SetCellValue(row, col,
“cell (%d,%d)” % (row, col))
gsizer.Add(grid)
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()

So just added a sizer and added the grid to it and when it runs…there are no scroll bars! Now if one were to use a wx.PyScrolledWindow, one would have scroll bars, but would lose the functionality associated with the grid to keep it’s labels in view when scrolled.

Because you are putting a wx.ScrolledWindow (the Grid) in another wx.ScrolledWindow. So when you scroll the outer scrolled window all of its contents, including the whole Grid widget(s), will be scrolled.

···

On 11/24/11 5:51 PM, johncblacker wrote:

Thanks Robin...in your first response paragraph you indicate that Grid
is already using 4 separate panels and that the labels are always
visible but only the gridwindow area scrolls...I'm not experiencing it
that way. When I put grids in a scrollablewindow with a horizontal
boxsizer I'm finding that the grids scroll completely - labels and all.

--
Robin Dunn
Software Craftsman

It works as expected in 2.9. In 2.8 more precedence is being given to the item's best size, which for a grid is the size needed to show all the cells. Obviously that is not going to work in this case, so you can override the best size by setting the min size, and then tell the sizer to expand the item.

BTW, using the WIT makes it lots easier to diagnose issues like this. http://wiki.wxpython.org/Widget_Inspection_Tool

g1.py (702 Bytes)

···

On 11/25/11 12:32 PM, johncblacker wrote:

So...did some experimenting and arrived at the following conclusion. You
can't put a grid inside a sizer as that messes things up...like the
ability to scroll while keeping the labels in view. I took the simple
grid app from the wxPython in Action book and modified it slightly like so:

So just added a sizer and added the grid to it and when it runs...there
are no scroll bars! Now if one were to use a wx.PyScrolledWindow, one
would have scroll bars, but would lose the functionality associated with
the grid to keep it's labels in view when scrolled.

--
Robin Dunn
Software Craftsman