1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| # -*- coding: iso-8859-1 -*-
import wx
import wx.grid as gridlib
class MyGrid(gridlib.Grid):
def __init__(self, parentUI):
gridlib.Grid.__init__(self, parentUI, -1)
gridlib.EVT_GRID_CELL_CHANGE(self, self.OnChange)
self.CreateGrid(0, 2)
self.SetColSize(0,150)
self.SetColSize(1,300)
self.DrawGrid()
def DrawGrid(self,numrows = 2):
self.BeginBatch()
while self.GetNumberRows():
editor=self.GetDefaultEditorForCell(0,1)
if (editor.IsCreated):
editor.Destroy()
self.DeleteRows(0)
self.ClearGrid()
self.AppendRows(int(numrows))
self.SetCellEditor(0,1,gridlib.GridCellNumberEditor(1,65535))
self.SetCellValue(0,0,"NumRows")
self.SetCellValue(0,1,str(numrows))
self.SetCellEditor(1,1,gridlib.GridCellChoiceEditor(["Choix1","Choix2"]))
self.SetCellValue(1,0,"Param2")
self.SetCellValue(1,1,"Choix1")
self.EndBatch()
def OnChange(self,evt):
gridlib.EVT_GRID_CELL_CHANGE(self, None)
evt.Skip()
self.DrawGrid(self.GetCellValue(0,1))
gridlib.EVT_GRID_CELL_CHANGE(self, self.OnChange)
class MyFrame(wx.Frame):
def __init__(self, parent):
self.parent=parent
wx.Frame.__init__(self, parent, -1, "Grid Bug",wx.DefaultPosition, wx.Size(800, 600))
self.panel = wx.Panel(self, -1)
self.grid = MyGrid(self.panel)
self.box = wx.BoxSizer(wx.VERTICAL)
self.box.Add(self.grid, 1, wx.EXPAND)
self.panel.SetSizer(self.box)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None)
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == '__main__':
app = MyApp(0)
app.MainLoop() |
Partager