Flavio Coelho <fccoelho <at> gmail.com> writes:
Hi,Is there a way to fill a grid from a numpy array without having to iterate
through it and issuing SetCellValue for each cell?same for reading?thanks,--
Flávio Codeço Coelho
here's a minimal example:
import wx
import wx.grid
import numpy as N
class TableBase(wx.grid.PyGridTableBase):
def __init__(self, data):
wx.grid.PyGridTableBase.__init__(self)
self.data = data
def GetNumberRows(self):
return self.data.shape[0]
def GetNumberCols(self):
return self.data.shape[1]
def GetValue(self, row, col):
return self.data[row][col]
class Grid(wx.grid.Grid):
def __init__(self, parent, data):
wx.grid.Grid.__init__(self, parent, -1)
table = TableBase(data)
self.SetTable(table, True)
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
pan = wx.Panel(self, -1)
grid = Grid(pan, N.random.rand(30,40))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(grid, 1, wx.EXPAND)
pan.SetSizer(sizer)
pan.Layout()
class App(wx.App):
def OnInit(self):
frame = Frame()
frame.Show()
return True
app = App()
app.MainLoop()
Christian