Hi all,
I'm new to this forum and to wxPython generally so im sorry if my
question seems a little noobish.
I've tried to create a simple panel that will show a static bitmap and
when it's resized the bitmap will be resized too.
here's the code:
import wx
class ResizableImage(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, size = parent.GetSize())
self.StaticBitmap = wx.StaticBitmap(self, wx.ID_ANY)
#I dont have a reason to give a specific ID, plz comment if
you think otherwise
# Initializing the starting Image and quality of the strech
self.Image = wx.EmptyImage(1, 1)
self.StrechQuality = wx.IMAGE_QUALITY_NORMAL
# binding the size event for refreshing the Image scale
self.Parent.Bind(wx.EVT_SIZE, self.Refresh)
def SetStrechQuality(self, qual):
self.StrechQuality = qual
def SetImage(self, image):
self.Image = image
self.Refresh('')
def SetBitmap(self, bitmap):
self.Image = bitmap.ConvertToImage()
self.Refresh('')
def Refresh(self, event):
self.Parent.Layout()
SizeX, SizeY = self.GetSize()
self.RatioX = 1.0 * SizeX / self.Image.GetWidth()
self.RatioY = 1.0 * SizeY / self.Image.GetHeight()
bmp = self.Image.Scale(width = SizeX, height =
SizeY).ConvertToBitmap()
self.StaticBitmap.SetSize(self.GetSize())
self.StaticBitmap.SetBitmap(bmp)
pass
if __name__ == "__main__":
#test code
print ' Welcome '
app = wx.PySimpleApp(0)
Yosi = wx.Frame(None, title = 'Test', size = (500, 500))
Yosi.panel = ResizableImage(Yosi)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(Yosi.panel, 1, wx.EXPAND, 0)
Yosi.SetSizer(sizer)
sizer.Fit(Yosi)
Yosi.Layout()
app.SetTopWindow(Yosi)
Yosi.Show()
ImageLocation ='c:/test/1.jpg'
#replace with Image Path
im = wx.Image(ImageLocation)
Yosi.panel.SetImage(im)
app.MainLoop()
my problem is that when I have more then one ResizableImage classes in
a window I call the
parent.Layout() function more than once
and If I wont call it the sizer holding the panel wont resize the
Panel.
any advises?