wxScrolledWindow + WrapSizer problem

I have started to explore wxPython.
Currently I have problems with this code:

Platform linux/wxGTK (wxPython 4.01)

  • Add Elements with the ‘+ Add’ Button

Expected behavior:

  • Wrap around horizontally if necessary
  • Show Vertical Scrollbar if necessary
  • Render each Element inside the visible/scrollable Area

Current behavior:

  • if the window is very wide, elements are rendered off-screen
  • no scrollbars are shown

the code is generated with wxGlade.
I tried to workaround the problem by Setting the virtualsize in the OnSize and AddCard functions.
The debug print agree that size and virtualsize are the same, but the Panels are not rendered properly.

Any Ideas?

I have just tried this and this seems to work:

    def on_size(self, event):  # wxGlade: MyFrame.<event_handler>
        sizer = self.panel_1.GetSizer()
        s = self.panel_1.GetSize()
        vs = self.panel_1.GetVirtualSize()
        self.panel_1.SetVirtualSize( (s[0], vs[1]) )

I did not modify your code, though, but tested with a simpler sample. Please always post minimal samples.

I’ve tried the WrapSizer on a SrolledWindow with thumbnails trying to imitate the MS explorer on an image folder: when one narrows the frame the thumbnails are wrapped around (though not as smoothly as Windows does), but when one widens the frame again there is no unwrapping, i.e. in Windows as soon as there is enough room for a single thumbnail the whole rearranges. Once one has actually seen it one can imagine the quality of that explorer!
But all the other sizers seem to be nice & robust (and certainly not only them !!!) :face_with_raised_eyebrow:

My on_size handler above does exactly this. It will unwrap when you increase the width. I have tested only on Windows, but I don’t see why it should not work on other platforms as well.

Scrolled_WrapSizer.py (4.2 KB)

It’s just important to handle the EVT_SIZE of the surrounding frame, not the panel.

That’s true, it just deviates from the behaviour of a sizer. But maybe that’s intended on performance reasons because when one saves the frame size and starts it again with that size then it sizes properly to that new size. For my application that’s dynamical enough

just one remark: with the explorer on Windows one never sees the horizontal scrollbar which is actually not needed; on your example it’s flickering and if one stops at the right time it becomes visible; style=wx.VSCROLL on the ScrolledWindow won’t work but ShowScrollbars does;
what I now would like is this vanishing narrow bar what even the explorer hasn’t grown up to yet :sunglasses:

If that’s a problem, handle both EVT_SIZE:

        self.Bind(wx.EVT_SIZE, self.on_size, self)
        self.main_panel.Bind(wx.EVT_SIZE, self.on_size, self.main_panel)

then the horizontal scroll bar still pops up at the last two columns (at least on my Windows)
here is what MS thinks of a scrolled wrapper

Scrolled_WrapSizer_nhsb.py (4.2 KB)

Not here on Win 10, Python 3.8/64 and wxPython 4.1
Also, your event handler is quite different. Did not test this.

On what platform do you see problems?

I’m on the same platform
the different event handler doesn’t matter on my Windows, but I forgot to take your second binding out again, it’s not needed…
in your coding the horizontal scroll bar comes up when the frame is horizontally narrowed up to the last two columns

and this is a version for Python lovers: no goodies without loopies

wrap_sizer.py (1.5 KB)

OK, better use GetClientSize to get the size without the displayed vertical scroll bar:

    def on_size(self, event):  # wxGlade: MyFrame.<event_handler>
        cs = self.main_panel.GetClientSize()
        vs = self.main_panel.GetVirtualSize()
        self.main_panel.SetVirtualSize( (cs[0], vs[1]) )

Scrolled_WrapSizer_update.py (4.3 KB)

in my example (just one post up) there is no ‘EVT_SIZE’ at all: there is just a ‘ScrolledWindow’ and in it a ‘WrapSizer’! the mechanics are all done by the magic of wx (I hope)

You wrote:

And the post was a solution to that.

I don’t read poems or obscure messages.
If you want to contribute, describe what was the required step to solve the problem.