Thank you for reading this.
I'm attempting to convert some code that I wrote some time ago to wxPython and what follows is just the bare bones, mostly lifted from a demo example.
My Display() procedure will be called from a timer event (haven't sorted that out yet) periodically. How do I link the OnPaint event with Display()? Is there an Update() procedure?
import wx
import numpy
board_size = 20
class Mywin(wx.Frame):
def \_\_init\_\_\(self, parent, title\):
super\(Mywin, self\)\.\_\_init\_\_\(parent, title = title,size = \(500,300\)\)
self\.InitUI\(\)
def InitUI\(self\):
self\.Bind\(wx\.EVT\_PAINT, self\.OnPaint\)
self\.Centre\(\)
self\.Show\(True\)
def OnPaint\(self, e\):
dc = wx\.PaintDC\(self\)
brush = wx\.Brush\("white"\)
dc\.SetBackground\(brush\)
dc\.Clear\(\)
board = numpy.zeros(board_size * board_size, dtype='i').reshape(board_size, board_size)
board [1][1] = 1
board [1][3] = 1
def Display():
for x in range(board_size):
for y in range(board_size):
if \(board\[y\]\[x\]\) == 0:
\#draw a green box
wx\.pen = wx\.Pen\(wx\.Colour\(0,0,0\)\)
wx\.dc\.SetPen\(pen\)
wx\.dc\.SetBrush\(wx\.Brush\(wx\.Colour\(0,255,0\), wx\.SOLID\)\)
wx\.dc\.DrawRectangle\(10, 10, 10, 10\)
else:
\#draw a white box
wx\.pen = wx\.Pen\(wx\.Colour\(0,0,0\)\)
wx\.dc\.SetPen\(pen\)
wx\.dc\.SetBrush\(wx\.Brush\(wx\.Colour\(0,0,0\), wx\.SOLID\)\)
wx\.dc\.DrawRectangle\(10, 10, 10, 10\)
ex = wx.App()
Mywin(None,'Drawing demo')
ex.MainLoop()
Display()
···
--
Regards,
Phil