ScrolledPanel and Growing Images

Soooo, I was playing around just to get a used to certain parts of wxPython that I’ve never used before: namely painting, scrolling, and all that jazz.

The goal was to create a frame that would display images down on the left side, and have stuff about the image on the right. Since images can be any ol’ size, I’d dynamically resize them as the frame changed size, so that they were never wider then half the width of the frame, while keeping proportions right.

The basic layout of the windows is a vertical box sizer, with horizontal box sizers piled down it; the horizontals hold an ImagePanel, and a TextCtrl. The ImagePanel is the image and re-paints/re-sizes the image as appropriate, the TextCtrl is just to demonstrate something is there :slight_smile:

After tons of iterations of sizers and scrolling widgets, I have it mostly right-- except when the window expands, the horizontal sizers never get taller as I’d want them to.

I think I know why: what I think I want is for the “virtual” depth in the scrolled area to get bigger as I make the window bigger, proportionally. But the “virtual” size isn’t changing, so as I make the window wider, the virtual depth is actually no different. But I have no idea how to change that behavior :slight_smile: This is my first time ever getting near scrolled windows or painting or any of this jazz :slight_smile:

I attached a trimmed down test-case to demonstrate: it should just run and work. (My sample image directory is represented as big black boxes of varying sizes in the test-case, so you can see exactly what I’m looking at without having all the pictures of flowers and deer :P)

(This is wxPython 2.8 + Python 2.4 on OSX, but I tested it out on Windows and its about the same)

Any idea what I’m doing wrong? I think my understanding of the scrolled-fu may be off. :slight_smile:

Thanks in advance.

testcase.py (5.75 KB)

Stephen Hansen wrote:

Soooo, I was playing around just to get a used to certain parts of wxPython that I've never used before: namely painting, scrolling, and all that jazz.

The goal was to create a frame that would display images down on the left side, and have stuff about the image on the right. Since images can be any ol' size, I'd dynamically resize them as the frame changed size, so that they were never wider then half the width of the frame, while keeping proportions right.

The basic layout of the windows is a vertical box sizer, with horizontal box sizers piled down it; the horizontals hold an ImagePanel, and a TextCtrl. The ImagePanel is the image and re-paints/re-sizes the image as appropriate, the TextCtrl is just to demonstrate something is there :slight_smile:

After tons of iterations of sizers and scrolling widgets, I have it mostly right-- except when the window expands, the horizontal sizers never get taller as I'd want them to.

I think I know why: what I think I want is for the "virtual" depth in the scrolled area to get bigger as I make the window bigger, proportionally. But the "virtual" size isn't changing, so as I make the window wider, the virtual depth is actually no different. But I have no idea how to change that behavior :slight_smile:

You're actually very close. I noticed that you are trying to override the GetBestSize method in ImagePanel, but you may have noticed that it is not being called by the sizers. There are two reasons for this. First, the name of the C++ virtual method to be overridden is DoGetBestSize. Second, in order to override C++ virtuals you have to use a special base class that is aware that the Python class exists and knows how to reflect the C++ virtual calls to the Python methods. In this case that class is wx.PyPanel. Once I made those changes then the height of each item is adjusting the way I think you intended (if I understand your description correctly.)

I didn't look at your painting code.

scrolling.py (5.6 KB)

···

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