I have the following wx.Window:
class SketchWindow(wx.Window):
def __init__(self, parent):
wx.Window.__init__(self, parent, -1)
self.SetBackgroundColour('White')
# Window event binding
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_IDLE, self.OnIdle)
# run
self.Run()
def OnPaint(self, evt):
self.DrawEntities(wx.PaintDC(self))
def DrawEntities(self, dc):
dc.SetPen(wx.Pen('Black', 1, wx.SOLID))
dc.SetBrush(wx.Brush('Green', wx.SOLID))
# draw all
for e in self.entities:
x, y = e.location
dc.DrawCircle(x, y, 4)
def OnIdle(self, event):
self.Refresh(False)
def Run(self):
# update self.entities ...
# call this method again later
wx.CallLater(50, self.Run)
I need to draw on my window a number of circles [0, 2000] every N milliseconds (50 in my example), where at each step these circles may update their location.
The method I wrote works (the circles are anti-aliased too) but it's quite slow. Is there a way to improve my solution?
I think the basic idea for better performance is to draw to memory offscreen, then blit the result to the screen. You could use the BufferedCanvas to accomplish this (example given at bottom of link page).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With