Hi Stef,
hello,
I've an image on a panel,
and the panel fills the complete frame.
(This is just a test, the idea is to put the image in a pane of wx.AUI)
Now when the frame is resized, the image should be redrawn with the
correct aspect ratio.
For the image part that works,
but if the image shrinks in one direction,
it leaves garbage in the background of the panel.
At the end of resize, I already call these methods,
self.panel.ClearBackground()
self.panel.Refresh(True)
but doesn't seem to help.
How should I clear the panel background after a resize ?
Can you try the attached modified version of your file and see if it
does what you need?
HTH.
import wx
# ***********************************************************************
# ***********************************************************************
class Test_Form(wx.MiniFrame):
def __init__(self):
wx.MiniFrame.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE)
self.panel = wx.Panel(self)
self.image = wx.Image('Vippi_Bricks.png', wx.BITMAP_TYPE_PNG)
self.bmp = None
self.panel.Bind(wx.EVT_SIZE, self.OnSize)
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
self.panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
self.Show()
def OnPaint(self, event):
if self.bmp is None:
self.Resize()
dc = wx.BufferedPaintDC(self.panel)
dc.Clear()
dc.DrawBitmap(self.bmp, 0, 0)
def OnErase(self, event):
pass
def OnSize(self, event):
self.Resize()
self.Refresh()
event.Skip()
def Resize(self):
w, h = self.image.GetWidth(), self.image.GetHeight()
a1, a2 = self.panel.GetClientSize()
a1 = 1.0*a1/w
a2 = 1.0*a2/h
a = min(a1, a2)
self.bmp = self.image.Scale(int(a*w), int(a*h)).ConvertToBitmap()
# ***********************************************************************
# ***********************************************************************
class Test_App (wx.App):
def OnInit (self):
My_Form = Test_Form()
return True
# ***********************************************************************
# ***********************************************************************
# ***********************************************************************
if __name__ == "__main__":
My_App = Test_App(False)
My_App.MainLoop()
# ***********************************************************************
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
···
On Nov 23, 2007 12:37 PM, Stef Mientki wrote: