Hello, I am trying to use the EVT_SIZE tool for resizing items to fit
windows, and am following the example in doodle.py. In the code below,
a small panel containing a dc is created, but when it is maximized only
the background is resized to fit the large window and the painted light
blue lines stay the original size. Am I invoking EVT_SIZE in the wrong
place?
Thanks,
Gabriel
···
############
import wx
class MyPanel(wx.Panel):
def init(self,parent,id):
wx.Panel.init(self,parent,id,size=(250,500))
size = self.GetClientSize()
class MyFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘Global Context’,size=(250,500))
self.panel = MyPanel(self,-1)
self.SetBackgroundColour(“Red”)
self.InitBuffer()
self.panel.Bind(wx.EVT_PAINT, self.OnPaint)
def InitBuffer(self):
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DrawLines(dc)
self.reInitBuffer = False
wx.EVT_SIZE(self, self.OnSize)
def OnSize(self,event):
self.reInitBuffer = True
def DrawLines(self, dc):
dc.BeginDrawing()
y = 1
while y < 250:
self.pen = wx.Pen('Light Blue', 3, wx.SOLID)
dc.SetPen(self.pen)
x = 0
coords = []
while x < 251:
coords.append((x,y,x+1,y+1))
x += 1
for eachcoord in coords:
dc.DrawLine(*eachcoord)
y += 1
dc.EndDrawing()
def OnPaint(self,event):
dc = wx.BufferedPaintDC(self.panel, self.buffer)
app = wx.PySimpleApp(redirect=‘True’)
frm = MyFrame()
frm.SetSize((250,500))
frm.Show()
app.SetTopWindow(frm)
app.MainLoop()