Scrolling grids simultaneously?

Hi NG,

    I am working on a small software based on a wx.aui.AuiNotebook.
Every page of the notebook contains a wx.grid. Using wx.aui is very
useful as I can split the notebook pages and compare 2 or more grids
side by side.
I was wondering, however: is there a way to scroll simultaneously 2 or
more grid (as Excel does)? I mean, if the user drags the scrollbar for
one grid, the other grid should scroll in such a way that the 2 (or
more) grids display the same row/column interval. I hope it is clear
enough...
Thank you for every suggestion.

···

--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Andrea Gavana wrote:

Hi NG,

    I am working on a small software based on a wx.aui.AuiNotebook.
Every page of the notebook contains a wx.grid. Using wx.aui is very
useful as I can split the notebook pages and compare 2 or more grids
side by side.
I was wondering, however: is there a way to scroll simultaneously 2 or
more grid (as Excel does)? I mean, if the user drags the scrollbar for
one grid, the other grid should scroll in such a way that the 2 (or
more) grids display the same row/column interval. I hope it is clear
enough...

I have done this for different widgets in the same frame. I guess you could do it across notebooks if you are able to send somehow messages/events between them.

See the attached test case I made. Does it help? Basically I hook on the scroll event and *replicate* it to another widget. Only tested under MSW.

bound widgets.py (6.56 KB)

···

--
Grzegorz Adam Hankiewicz, Jefe de producto de TeraVial
Rastertech España S.A. Tel: +34 918 467 390, ext 18.
http://www.rastertech.es/ ghankiewicz@rastertech.es

Hi Gregorz,

···

On 1/22/07, Grzegorz Adam Hankiewicz wrote:

Andrea Gavana wrote:
> Hi NG,
>
> I am working on a small software based on a wx.aui.AuiNotebook.
> Every page of the notebook contains a wx.grid. Using wx.aui is very
> useful as I can split the notebook pages and compare 2 or more grids
> side by side.
> I was wondering, however: is there a way to scroll simultaneously 2 or
> more grid (as Excel does)? I mean, if the user drags the scrollbar for
> one grid, the other grid should scroll in such a way that the 2 (or
> more) grids display the same row/column interval. I hope it is clear
> enough...

I have done this for different widgets in the same frame. I guess you
could do it across notebooks if you are able to send somehow
messages/events between them.

See the attached test case I made. Does it help? Basically I hook on the
scroll event and *replicate* it to another widget. Only tested under MSW.

Thank you for the sample! I'll try to adapt it to my needs, but it
seems to work very well :smiley:

Thanks again.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Andrea Gavana wrote:

See the attached test case I made. Does it help? Basically I hook on the
scroll event and *replicate* it to another widget. Only tested under MSW.

Thank you for the sample! I'll try to adapt it to my needs, but it
seems to work very well :smiley:

Actually that example is incomplete. Both widgets bind only to EVT_SCROLLWIN. Not only this is incomplete but inaccurate: if you press the arrows instead of dragging event.GetPosition() will always return a zero. Whether this is a bug or feature I don't know.

However, you can add handlers for EVT_MOUSEWHEEL, EVT_SCROLLWIN_LINEUP, EVT_SCROLL_LINEDOWN, EVT_SCROLLWIN_PAGEUP, EVT_SCROLLWIN_PAGEDOWN, EVT_SCROLLWIN_TOP, EVT_SCROLLWIN_BOTTOM. Something I found a mistery is why these don't get generated when you select an entry in the list and use the keys to navigate. Apparently to trigger some of this you can right click on the scrollbar and select one option of the menu. Bizarre.

Since you can't catch these events through key interaction you would have to process all EVT_KEY_DOWN events and detect movement there, checking the current position and so forth. For my needs this is not needed, so I just put a dummy EVT_KEY_DOWN to disable keyboard navigation, but maybe you have to take care of that.

Given the number increase in events to process and the complexity of the key down events processing, I think the best would be to create a base class and use it as a mixin to avoid polluting the code of individual controls.

Might be nice for a wxpython demo to show off if the mixin can be improved to allow multiple bound widgets and each of them being able to scroll to the same line, or a line relative to the total amount of elements in that widget.

···

--
Grzegorz Adam Hankiewicz, Jefe de producto de TeraVial
Rastertech España S.A. Tel: +34 918 467 390, ext 18.
http://www.rastertech.es/ ghankiewicz@rastertech.es

Grzegorz Adam Hankiewicz wrote:

Andrea Gavana wrote:

Thank you for the sample! I'll try to adapt it to my needs, but it
seems to work very well :smiley:

Actually that example is incomplete [...]

Here's an improved version using the mixin I thought of. Still doesn't handle keyboard data, and is vertical scrollbar specific. I don't think I'll improve it more, though.

bound widgets.py (9.05 KB)

···

--
Grzegorz Adam Hankiewicz, Jefe de producto de TeraVial
Rastertech España S.A. Tel: +34 918 467 390, ext 18.
http://www.rastertech.es/ ghankiewicz@rastertech.es