import wx
import wx.grid
class Wndw(wx.Frame):
def init(self, parent):
wx.Frame.__init__(self, id=-1, name='', parent=None, pos=wx.Point(400, 100), size=wx.Size(120, 120), style=wx.DEFAULT_FRAME_STYLE, title='Grid/LanguagesCombo')
self.SetClientSize(wx.Size(300,300))
self.VentanaDeslizante = wx.ScrolledWindow(id=-1,name='VentanaDeslizante', parent=self, pos=wx.Point(0, 0), size=wx.Size(10, 10), style=wx.HSCROLL | wx.VSCROLL)
EditorOpciones = wx.grid.GridCellChoiceEditor([])
self.thegrid = wx.grid.Grid(id=-1, name='grid1',parent=self.VentanaDeslizante, pos=wx.Point(0, 0),size=wx.Size(250, 175), style=0)
self.thegrid.CreateGrid(3, 3)
self.thegrid.SetCellEditor(0, 0, EditorOpciones)
self.thegrid.list = [ ('Chinese'), ('Japanese'), ('Norway') ]
self.thegrid.SetCellValue(0, 0, self.thegrid.list[0])
self.thegrid.Bind(wx.grid.EVT_GRID_CELL_CHANGED , self.CellChange) # I need to move to next cell, method does work
self.thegrid.Bind(wx.grid.EVT_GRID_EDITOR_CREATED , self.OnEditorCreation)
self.thegrid.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN , self.OnEditorHidden) # I need to move to next cell, method does not work
#*********************************************
def CellChange(self, event):
line = event.GetRow()
column = event.GetCol()
# When changing cell value, method MoveCursorRight works well
# when pressing key tab ¡¡¡
self.thegrid.MoveCursorRight(False)
event.Skip()
#*********************************************
def OnEditorHidden(self, event):
line = event.GetRow()
column = event.GetCol()
# Method GoToCell invocation below try to change focus to next right cell
# with tab key , but does an infinite loop instead ?
# Note: Cell value not changed
#self.thegrid.GoToCell(line, column + 1) # Please uncomment here to see the error
event.Skip()
#*********************************************
def OnEditorCreation(self, event): # Creation of the editor and loading its data, it's Ok.
self.thecombo = event.GetControl() # Get the ComboBox belonging to GridCellChoiceEditor
for language in self.thegrid.list:
self.thecombo.Append(language)
event.Skip()
#*********************************************
if name == ‘main’:
app=wx.App()
frame = Wndw(None)
frame.Show()
app.MainLoop()