views:

29

answers:

2

I have a fucntion that calculates the number of images that can be displayed on the screen, if there are more images than the ones that can be put on screen, I resize the images till they all can happear.

Then, I want to display them with one vertical box sizer and several horizontal box sizers!

The horizontal number of box sizers are dynamic, it can be only one or more depending on the number of images.

How can I define several box sizers and add them to the vertical box sizer?

Thanks in advance!

+2  A: 

Why not simply make the horizontal sizers in a loop, .Adding them to the same vertical sizer? E.g.

def HorzInVert(n):
  vert = wx.BoxSizer(wx.VERTICAL)
  horizontals = []
  for i in range(n):
    horz = wx.BoxSizer(wx.HORIZONTAL)
    vert.Add(horz,1, wx.ALL, 0)
    horizontals.append(horz)
  return vert, horizontals

You can call this simple function from anywhere, it returns the vertical sizer and the list of n horizontal sizers in it -- then the caller adds stuff suitably to the horizontal sliders, an appropriate SetSizerwith the vertical sizer as the argument, and the vertical sizer's .Fit. Of course you can make it as much fancier as you want, with all sort of arguments to control exactly how the Adds are performed.

Alex Martelli
that might work but does'nt that gives something like: trying to insert the same thing again (because we insert horz several times?)..
aF
@aF, no, because the name horz refers to a different, freshly instantiated BoxSizer even time 'round the loop.
Alex Martelli
A: 

wx.GridSizer is the answer!

aF
Was your choice of formatting intentional? Your answer is a bit hard to read.
Bryan Oakley
is it better now? :P
aF