My wxPython project has a frame, with multiple nested sizers.
One of the sizers contains a wxStaticImage with a bitmap that is read from a file.
I need the image to resize (grow/shrink) every time the frame is resized, so it will fit it's sizer's boundaries.
(I think that) I know how to resize an image. What I don't know is how to:
- how to get the image's container's width or height?
- maybe i overlooked a property that does it auotmatically?
(for now, I don't mind the proportions)
Edit: Complete solution
i understood wrong about wxStaticBitmapin.Size. it does NOT describe the size of the image (i.e. image resolution), but rather - wxStaticBitmapin.Size gives the sizer's slot dimentions, or in other words: the current widget's size.
so with Mik's code i now how to fit into the slot.
in addition to mike's solution: when using onSize event on a frame, don't forget to add event.skip(). otherwise the sizers will stop re-aligning. Altertanively, just use the image's onSize.
here's the complete event method:
def bitmap1_onSize(self, e=None):
W, H = self.bitmap1.Size
if W > H:
NewW = W
NewH = W * H / W
else:
NewH = H
NewW = H * W / H
img = wx.Image(self.frame_file_picker.Path, wx.BITMAP_TYPE_ANY)
img = img.Scale(NewW,NewH)
self.bitmap1.SetBitmap(wx.BitmapFromImage(img))
e.Skip()