In the following sample app, I create a main frame in MainGUI ans set
two panels within it. ButtonPanel() has a single blank button, and
PlotPanel()
is supposed to redraw a rectangle on each pass through the given
range. Using glcanvas in PlotPanel draws each one, but won't
Refresh(), or Update(). If I replace the glcanvas with a panel
instead, it looks like it does what I want, which is to redraw each
pass through, but it shows some, and not all of the redraws, no matter
how much I slow it down.
Is there a way to get a steady redraw rate, and if so how?
import wx
import random
import time
import wx.glcanvas
class MainGUI(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(600, 600))
self.ppanel = PlotPanel(self, -1)
self.bpanel = ButtonPanel(self, -1)
self.hbox = wx.BoxSizer()
self.hbox.Add(self.ppanel)
self.hbox.Add(self.bpanel)
self.SetSizer(self.hbox)
class ButtonPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, style = wx.BORDER_SUNKEN)
self.changeb = wx.Button(self, -1)
self.Bind(wx.EVT_BUTTON, self.GetParent().ppanel.OnClick, id =
self.changeb.GetId())
class PlotPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id, style = wx.BORDER_SUNKEN)
self.canvas = wx.glcanvas.GLCanvas(self, -1, size = (250,250))
def OnClick(self, event):
self.dc = wx.PaintDC(self.canvas)
self.dc.SetPen(wx.Pen('#d4d4d4'))
for i in range(1,20):
self.random = random.randint(10,99)
self.dc.SetBrush(wx.Brush('#c%ic%i' % (self.random,self.random)))
self.dc.DrawRectangle(self.random, self.random, self.random, self.random)
time.sleep(.175)
self.Update()
self.Refresh()
self.canvas.GetGrandParent().UpdateWindowUI()
class MainApp(wx.App):
'''Class Main App.'''
def __init__(self, redirect = False):
wx.App.__init__(self)
def OnInit(self):
'''Init Main App.'''
#MainFrame Instance For MainGui
self.frame = MainGUI(None, -1, 'Primary')
self.frame.Show(True)
self.SetTopWindow(self.frame)
return True
#Main app instance
app = MainApp()
app.MainLoop()
Thanks,
David